Board index FlightGear Development Nasal

How do I dynamically change audio files to play?

Nasal is the scripting language of FlightGear.

How do I dynamically change audio files to play?

Postby sidi762 » Sun Nov 10, 2019 2:15 pm

Hi all,

I'm trying to make a music player using nasal. As there is no docs for the sound playing fgcommand at all, I used the sound configuration xml for playing sounds. However, I found that it's impossible to change which file to play in runtime using nasal as it seems that only path are accepted in sound configuration xml instead of property, and I don't have write access to the sound configuration xml file. I even tried to find a way to make the aircraft use a xml file located in FGHOME but ended up in total failure.

By the way, the method to reset sound system in runtime described in wiki doesn't seems to work, at least in 2019.3.2.
Code: Select all
fgcommand("reinit", props.Node.new({ subsystem: "fx" }))


Am I doing anything wrong here?

Thanks in advance!

Kind regards,
Sidi
sidi762
 
Posts: 226
Joined: Sat Jun 18, 2016 9:15 am
Location: Beijing, China
Callsign: DAG0762
Version: 2020.3.18
OS: macOS Catalina

Re: How do I dynamically change audio files to play?

Postby Necolatis » Mon Nov 11, 2019 6:04 pm

the reinit code is not needed anymore, just reload model from debug menu. It does the same.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2238
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: How do I dynamically change audio files to play?

Postby Necolatis » Mon Nov 11, 2019 6:10 pm

fgcommand("play-audio-sample", propertyNode );

for example:


var tmpl = { path : "C:/sound-dir", file : "blabla.wav" , volume : "0.6"};
fgcommand("play-audio-sample", props.Node.new(tmpl) );
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2238
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: How do I dynamically change audio files to play?

Postby wkitty42 » Mon Nov 11, 2019 8:53 pm

sidi, did you see my response on the dev mailing list? i pointed to the ATCChatter addon in FGAddon/Addons that might be helpful... the only thing i've seen so far is that everything handled by that addon is played in string sort order... briefly looking at the way it loads everything into an array, it should be possible to randomly select the next file to play based on the array index...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9161
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 22.04

Re: How do I dynamically change audio files to play?

Postby sidi762 » Wed Nov 13, 2019 3:07 pm

Necolatis wrote in Mon Nov 11, 2019 6:04 pm:the reinit code is not needed anymore, just reload model from debug menu. It does the same.

That should help a lot. Thanks!

Necolatis wrote in Mon Nov 11, 2019 6:10 pm:fgcommand("play-audio-sample", propertyNode );

for example:


var tmpl = { path : "C:/sound-dir", file : "blabla.wav" , volume : "0.6"};
fgcommand("play-audio-sample", props.Node.new(tmpl) );

Yes I've discovered this in the wiki already, but I didn't found any documents for it, as I was hopping to have more control over it such as to stop it whenever I want. Thanks anyway!

wkitty42 wrote in Mon Nov 11, 2019 8:53 pm:sidi, did you see my response on the dev mailing list? i pointed to the ATCChatter addon in FGAddon/Addons that might be helpful... the only thing i've seen so far is that everything handled by that addon is played in string sort order... briefly looking at the way it loads everything into an array, it should be possible to randomly select the next file to play based on the array index...

Will have a look at it. Thanks for the pointer!
sidi762
 
Posts: 226
Joined: Sat Jun 18, 2016 9:15 am
Location: Beijing, China
Callsign: DAG0762
Version: 2020.3.18
OS: macOS Catalina

Re: How do I dynamically change audio files to play?

Postby Hooray » Fri Nov 15, 2019 5:00 pm

If you need more control/additional features, it would make sense to raise this on the devel list, it would be relatively easy to support additional parameters/modes by handing a props.Node hash to the fgcommand, introducing additional fgcommands, a cppbind based API or by using a property-listener based system. I believe a number of folks have asked for ways to do more sophisticated audio handling in fgdata space than we currently support
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Nasal

Who is online

Users browsing this forum: No registered users and 4 guests