Achoriham Posted September 25, 2010 Report Posted September 25, 2010 Hi Folks, Can someone show or upload any sample/example of how I could play some sounds via the new Lua-FSUIPC module? I was a long time user of Esound, but have no Lua skills whatsoever. Can anyone help to find the easiest and simplest way? I just want to play some sounds under certain conditions. thanks Potroh
prokopiu Posted September 25, 2010 Report Posted September 25, 2010 Hi Folks,Can someone show or upload any sample/example of how I could play some sounds via the new Lua-FSUIPC module? I was a long time user of Esound, but have no Lua skills whatsoever. Can anyone help to find the easiest and simplest way? I just want to play some sounds under certain conditions. thanks Potroh try function playSound (path) status = ipc.readSB(0x4200) ipc.writeSTR(0x4208, path, 250) ipc.writeUW(0x4204, 0x1001) ipc.writeSB(0x4200, 1) while ipc.readUW(0x4202) == 1 do ipc.writeSB(0x4200, 4) ipc.sleep(1000) end works fine here, sound in FSX\sound folder, give relative path and filename as parameter. Kosta
Pete Dowson Posted September 26, 2010 Report Posted September 26, 2010 try ... Hi Kosta, Why not use the Lua sound library functions? Surely easier and more readable, and include sound device selection as well as volume, placement, looping, and stopping? Regards Pete
Achoriham Posted September 26, 2010 Author Report Posted September 26, 2010 Why not use the Lua sound library functions? Surely easier and more readable, and include sound device selection as well as volume, placement, looping, and stopping? Pete Hi Pete, Would it be possible to obtain a very small example of how to use the sound-library functions? regards Potroh
Pete Dowson Posted September 26, 2010 Report Posted September 26, 2010 Would it be possible to obtain a very small example of how to use the sound-library functions?[ Like to play a sound called "xyz.wav" located in your FS sound folder: sound.play("xyz") That's about the smallest example I can think of. Please explain what the problem is you are having. Isn't the explanation of the sound library functions in the documentation sufficient? If not, why not? What exactly do you find difficult to understand? The document has the format of the commands on the left and the explanations on the right. Is that not a good format for you? Pete
prokopiu Posted September 26, 2010 Report Posted September 26, 2010 try ... Hi Kosta, Why not use the Lua sound library functions? Surely easier and more readable, and include sound device selection as well as volume, placement, looping, and stopping? Regards Pete Hi Pete, interesting, I seem to have old documentation because that is the first time I see this - I will look for it! I am writing on some virtual copilot lua scripts where I play checklists sounds etc. Where exactly can I find the doc for the sound lua library? Kosta
Achoriham Posted September 26, 2010 Author Report Posted September 26, 2010 Please explain what the problem is you are having. Isn't the explanation of the sound library functions in the documentation sufficient? If not, why not? What exactly do you find difficult to understand? The document has the format of the commands on the left and the explanations on the right. Is that not a good format for you? Pete Hi Pete, Well, I'm not a programmer, nevertheless I can find my way in these files I guess, but I need an example file, which we do not have for the Lua sound library here. The only thing I'd cry for is an example file with the following simple things: 1. How to automatically start a Lua file without any key or button, because I want these sounds to be always there. 2. A sample to play the sound via xy device 3. A sample to loop the sound via xy device 4. A sample if-endif structure to play a sounds if a FSUIPC variable changes. A single file with these would truly make my life easy. best regards Potroh
Pete Dowson Posted September 26, 2010 Report Posted September 26, 2010 1. How to automatically start a Lua file without any key or button, because I want these sounds to be always there. As the documentation clearly tells you, you only have to name the file "ipcReady.lua" and place it in the FS Modules folder, and it will start when FS is ready to fly. How can an example show more than such a statement? 2. A sample to play the sound via xy device Surely you can this out so easily yourself from what is documented? I am really astonished that you won't even make the slightest effort to help yourself! :-(. You need to look up the number of the sound device 'xy' in the FSUIPC.INI file, as stated in the documentation for the function "sound.device()". Then just sound.play("name of sound", devicenumber) If you were really ambitious, and know the correct name of the device, you could write a loop to check the name of each available device and thus get the number automatically, but that is an unlikely thing to want to do. 3. A sample to loop the sound via xy device Oh dear. Have you not bothered to look up anything at all? sound.playloop("name of sound", devicenumber) 4. A sample if-endif structure to play a sounds if a FSUIPC variable changes. You really want an event-driven function, exactly as shown in several of the examples supplied with FSUIPC. Read about the event library functions. A single file with these would truly make my life easy. I think you want to not do anything at all yourself? Why not at least make some effort? I am not here to do things for everyone individually. I supply documentation and examples. For the Lua language itself I give references to where you can find the full details as well as how to buy the books needed to learn more. However, it is so easy to simply apply yourself from all the examples already supplied. If this is really too much effort for you to apply I suggest you find a programmer willing to do things on commission. If you, on the other hand, want to try things yourself, I can help correct or extend your own examples -- but I really do ask you to make the initial effort. That is the best way to longer term understanding and therefore self-support rather than having to be spoon fed. Regards Pete
Achoriham Posted September 26, 2010 Author Report Posted September 26, 2010 Have you not bothered to look up anything at all? Hi Pete, You are right of course, I did not try to look up the sound part of the Lua examples, mainly because I did not find any. Frankly, that's why I named this thread "Lua sound example" because I hoped someone has done some sound related Lua file and would be willing to share, so I wouldn't have to start from scratch. I have some visual basic experience, but that wouldn't be of too much help here, so was simply hoping that someone could help with some EXAMPLES, so I do not have to learn Lua from scratch. But you are right and it wouldn't hurt if I get deeper into the docs, although a tiny sample would have been truly useful. many thanks for your help regards Potroh
Pete Dowson Posted September 26, 2010 Report Posted September 26, 2010 I did not try to look up the sound part of the Lua examples There aren't currently any specific examples for the sound functions, but as you have seen they are simple one-liners' following the format defined. The examples provided do, however, show ways opf putting together Lua plug-ins to do all sorts of things, including events based on FSUIPC offsets. I have some visual basic experience, but that wouldn't be of too much help here That is not true. Lua is at least as simple, for most things, as Basic, if not simpler, and in the case of the plug-ins using FSUIPC it is mainly a matter of calling functions as documented in any case. Please, just peruse some of the examples which are actually supplied. I'm sure you won't really find it so terribly difficult! Regards Pete
prokopiu Posted September 26, 2010 Report Posted September 26, 2010 Hi, I finally found the new documentation here http://forums.simflight.com/viewtopic.php?f=54&t=81475 look at Lua Plug-In documents and examples and download the ZIP. There you get the new sound library explained in the documentation. my little playSound() function now: function playSound (path) ref = sound.play(path) while sound.query(ref) do ipc.sleep(1000) end end The loop is to wait that the sound has finished so that sequential sounds do not play simultaneously. Much nicer compared to all the offset writing :) Pete, thanks for the lua functionality - great stuff. Kosta
Achoriham Posted September 27, 2010 Author Report Posted September 27, 2010 my little playSound() function now: Hi Kosta, Thanks much. I will experiment. regards Potroh
Alhard Horstmann Posted October 14, 2010 Report Posted October 14, 2010 ....my little playSound() function now: Hi all, I read all the FSUIPC-LUA documentation and this thread. I wrote a LUA script for playing a sound, but nothing to hear ! :-( ! Please help. Here is my code started by key press in FS9 running: -- "PlaySound" example LUA plug-in, by AH, 10-10-13 -- -- require("sound") necessary ??? -- require("fsuipc")not necessary -- --set message window to left side ipc.setdisplay(10,500,200,200) -- --show message for tracing ipc.lineDisplay("sound starts",1) -- -- now sound to be played -- --test command line frozen --ValRet=sound.play("barn_fx.wav",0,90,-1) sound.playloop("Y:\FS9\Sound\barn_fx.wav") -- --show message for tracing ipc.lineDisplay("sound ends",5) and here is the debug logfile: ********* LUA: "ahPlaySound" Log [from FSUIPC version 3.989c] ********* 3660359 System time = 14/10/2010 21:35:03, FS2004 time = 16:09:03 (14:09Z) 3660359 LUA: 0 3660359 LUA: Y:\FS9\MODULES\ipcDebug.lua 3660375 LUA: return 3660375 LUA: 3660375 LUA: 0 3660375 LUA: Y:\FS9\MODULES\ipcDebug.lua 3660375 LUA: call 3660375 LUA: 3660375 LUA: Y:\FS9\MODULES\ipcDebug.lua:38 3660375 LUA: beginning "Y:\FS9\MODULES\ahPlaySound.lua" 3660375 LUA: Y:\FS9\MODULES\ahPlaySound.lua:7 3660390 LUA: Y:\FS9\MODULES\ahPlaySound.lua:10 3660390 LUA: Y:\FS9\MODULES\ahPlaySound.lua:16 3660390 LUA: Y:\FS9\MODULES\ahPlaySound.lua:19 3660406 LUA: ended "Y:\FS9\MODULES\ahPlaySound.lua" 3660406 System time = 14/10/2010 21:35:03, FS2004 time = 16:09:03 (14:09Z) ********* LUA execution terminated: Log Closed ********* All messages are shown but NO SOUND!! What is wrong?? What should I test? BTW the sound from FS9 is played properly in parallel to the script. Thanks and regards Alhard
Pete Dowson Posted October 18, 2010 Report Posted October 18, 2010 I wrote a LUA script for playing a sound, but nothing to hear ! Here is my code started by key press in FS9 running: Okay. Let's see: -- require("sound") necessary ??? -- require("fsuipc")not necessary Neither are needed. All FSUIPC built-in libraries are built in and always available. sound.playloop("Y:\FS9\Sound\barn_fx.wav") ipc.lineDisplay("sound ends",5) The problem there is that in Lua strings, same as in many languages, the "\" character is used as an escape -- i.e. it modifies the next character. So your sound path becomes: Y: ?S9?ound?arn_fx.wav where the ? characters are probably non-printables. To get a \ in a Lua string you use \\, so "Y:\\FS9\\Sound\\barn_fx.wav However, if Y:\FS9 is the FS installation being run then you could shorten that to just "barn_fx" And please note that "sound ends" is not true as PlayLoop will loop the sound forever or until you issue a sound.stop call for it, quoting its reference. I've tried your Lua on FS9 here, and with that corrected it works on my Windows 7 PC. However, it only plays a short snippet on my XP PC. What version of Windows are you using? I'm wondering now whether there's something different in the sound calls for XP versus Win7 ... checking. [LATER] Okay ... I've found out what is happening. On Win7 (and, I assume, Vista), the sound continues playing even if the Lua program terminates. On XP it doesn't -- so since there's nothing else being done in that Lua program, you don't hear the sound, or only a short sharp snippet. If I add ipc.sleep(10000) after the sound.playloop call, I get the "narn_fx" sound playing for 10 seconds then ending, abruptly. This is rather unexpected. I'll see what I can do about it ... Regards Pete
Pete Dowson Posted October 18, 2010 Report Posted October 18, 2010 This is rather unexpected. I'll see what I can do about it ... Okay. I fixed it by making the sound playing routine run in the main FS thread. It seems that, on WinXP, the termination of the thread playing the sound kills the sound too. This doesn't happen in Win7 which is why I never spotted it. Please download 3.989e or 4.628 from the Updates topic in the Downloads sub-forum above. Regards Pete
Alhard Horstmann Posted October 19, 2010 Report Posted October 19, 2010 Okay. I fixed it by making the sound playing routine run in the main FS thread. Hi Pete, good to hear from again you after your absence. I tested your new update for FS9 (version 3.989e) but without success. Tests on FSX will follow later these days. As you can read, I tested with two soundcards and on soundcard 2 (device 3) sound works. I changed all possible devices, but no sound on main sound card (device 2). My PC runs with XP SP2 and FS9.1 Here is my code and log: Sound section in FSUIPC.INI [Sounds] Path=Y:\FS9\Sound\ Device1=Primärer Soundtreiber Device2=Realtek HD Audio output Device3=C-Media PCI Audio LUA script -- "PlaySound" V1 example LUA plug-in, by AH, 10-10-16 -- --set message window to left side ipc.setdisplay(0) ipc.setdisplay(20,100,500,500) --show message for tracing ipc.lineDisplay("",0) -- Display löschen und warten ipc.sleep(2000) ipc.lineDisplay("sound starts",1) -- message line 1 -- -- now sound to be played -- ref = sound.play("barn_fx.wav",3) --sound played on device 3 while sound.query(ref) do ipc.sleep(3000) end -- ipc.lineDisplay("sound starts now device 3 rear speaker",2) -- message line 2 -- ref = sound.play("caapdis.wav",3,90,180) --sound played on device 3 rear while sound.query(ref) do ipc.sleep(3000) end -- ipc.lineDisplay("sound starts now device 2",3) -- message line 3 ref = sound.play("barn_fx.wav",2) --sound played on device 2 while sound.query(ref) do ipc.sleep(3000) end -- --show message for tracing ipc.lineDisplay("sound ends",5) -- message line 5 LUA LOG file ********* LUA: "ahPlaySound" Log [from FSUIPC version 3.989e] ********* 3186750 System time = 19/10/2010 13:49:13, FS2004 time = 16:07:13 (14:07Z) 3186750 LUA: 0 3186750 LUA: Y:\FS9\MODULES\ipcDebug.lua 3186750 LUA: return 3186766 LUA: 3186766 LUA: 0 3186766 LUA: Y:\FS9\MODULES\ipcDebug.lua 3186766 LUA: call 3186766 LUA: 3186766 LUA: Y:\FS9\MODULES\ipcDebug.lua:38 3186766 LUA: beginning "Y:\FS9\MODULES\ahPlaySound.lua" 3186766 LUA: Y:\FS9\MODULES\ahPlaySound.lua:4 3186766 LUA: Y:\FS9\MODULES\ahPlaySound.lua:5 3186782 LUA: Y:\FS9\MODULES\ahPlaySound.lua:7 3186782 LUA: Y:\FS9\MODULES\ahPlaySound.lua:8 3188782 LUA: Y:\FS9\MODULES\ahPlaySound.lua:9 3188782 LUA: Y:\FS9\MODULES\ahPlaySound.lua:13 3188797 LUA: Y:\FS9\MODULES\ahPlaySound.lua:14 3188813 LUA: Y:\FS9\MODULES\ahPlaySound.lua:15 3191813 LUA: Y:\FS9\MODULES\ahPlaySound.lua:14 3191813 LUA: Y:\FS9\MODULES\ahPlaySound.lua:15 3194813 LUA: Y:\FS9\MODULES\ahPlaySound.lua:14 3194813 LUA: Y:\FS9\MODULES\ahPlaySound.lua:18 3194813 LUA: Y:\FS9\MODULES\ahPlaySound.lua:20 3194828 LUA: Y:\FS9\MODULES\ahPlaySound.lua:21 3194844 LUA: Y:\FS9\MODULES\ahPlaySound.lua:22 3197844 LUA: Y:\FS9\MODULES\ahPlaySound.lua:21 3197844 LUA: Y:\FS9\MODULES\ahPlaySound.lua:25 3197844 LUA: Y:\FS9\MODULES\ahPlaySound.lua:26 3197860 LUA: Y:\FS9\MODULES\ahPlaySound.lua:27 3197860 LUA: Y:\FS9\MODULES\ahPlaySound.lua:28 3200860 LUA: Y:\FS9\MODULES\ahPlaySound.lua:27 3200875 LUA: Y:\FS9\MODULES\ahPlaySound.lua:28 3203875 LUA: Y:\FS9\MODULES\ahPlaySound.lua:27 3203875 LUA: Y:\FS9\MODULES\ahPlaySound.lua:32 3203891 LUA: ended "Y:\FS9\MODULES\ahPlaySound.lua" 3203891 System time = 19/10/2010 13:49:30, FS2004 time = 16:07:30 (14:07Z) ********* LUA execution terminated: Log Closed *********
Pete Dowson Posted October 19, 2010 Report Posted October 19, 2010 As you can read, I tested with two soundcards and on soundcard 2 (device 3) sound works. I changed all possible devices, but no sound on main sound card (device 2). There's no difference in the DirectSound code I use for any device, so there may not be a lot I can do about that. I don't really understand how any program can get sound from that device if the standard "Play" facilities in DirectSound don't work. From your Lua logging this part: 3197844 LUA: Y:\FS9\MODULES\ahPlaySound.lua:26 3197860 LUA: Y:\FS9\MODULES\ahPlaySound.lua:27 3197860 LUA: Y:\FS9\MODULES\ahPlaySound.lua:28 3200860 LUA: Y:\FS9\MODULES\ahPlaySound.lua:27 3200875 LUA: Y:\FS9\MODULES\ahPlaySound.lua:28 3203875 LUA: Y:\FS9\MODULES\ahPlaySound.lua:27 3203875 LUA: Y:\FS9\MODULES\ahPlaySound.lua:32 indicates that as far as FSUIPC was informed, the sound sent to device 2 did play -- that play command is on line 26, and the subsequent wait loop was executed twice before exiting (as shown by the line 27 28 repeats). This length of time seems to accord with the Device 3 play back of the same WAV file, so evidently DirectSound certainly thought the sound was playing! Is device 2 also the defalut device? If so have you tried with device numbers 0 or 1, or omitted? There is some Sound action logging in FSUIPC. To enable it add the following to the [General] section of the FSUIPC.INI file before running FS: Debug=Please LogExtras=x20 I suspect, however, that this will show everything apparently working from the FSUIPC end of things. You could also check settings for the sound card. Maybe it is set in some mode which isn't compatible with what FSUIPC is asking of it, though this sounds very very unlikely. The most I could do, I think, depending on the FSUIPC Log results you get, is add responses from DirectSound calls to the log -- maybe one of them returns an error number which will be useful. Regards Pete
Alhard Horstmann Posted October 19, 2010 Report Posted October 19, 2010 There's no difference in the DirectSound code .......................... Regards Pete Pete, I will try all what you proposed. In the meantime I started testing with FSX. Surprisingly device 2 sounds (which is default sound) but not device 3 ??!! Question: can I change in FS9/X.CFG the sound device? Where can I find descriptions fro the "SOUND" parameter there?? regerds Alhard
Pete Dowson Posted October 19, 2010 Report Posted October 19, 2010 In the meantime I started testing with FSX. Surprisingly device 2 sounds (which is default sound) but not device 3 ??!! Well that is truly weird. There is nothing in that part of FSUIPC that is at all related to what version of FS is being used. In fact the same modules are compiled into both FSUIPC3 and FSUIPC4. Question: can I change in FS9/X.CFG the sound device? Where can I find descriptions fro the "SOUND" parameter there?? Sorry, I don't know offhand. I'd do a search. There's probably a [sound] section in their someplace. Regards Pete
Alhard Horstmann Posted October 28, 2010 Report Posted October 28, 2010 Well that is truly weird. There is nothing in that part of FSUIPC that is at all related to what version of FS is being used. In fact the same modules are compiled into both FSUIPC3 and FSUIPC4. Sorry, I don't know offhand. I'd do a search. There's probably a [sound] section in their someplace. Regards Pete Hi Pete, after long research I found the "bug". LUA Sound is working as designed! As I wrote before I have two sound cards. One is the C-Media (four channels) and the other is the Realtek Audio 5.1 (six channels). The Realtek was configured with 6 speakers and what happened? LUA was playing always on the Center Speaker, which was NOT connected. The Realtek sound card was running in a 2 box stereo HARDWARE configuration without correct SOFTWARE configuration. More details of my research see in attached pdf file. The difference between FS9 and FSX behaviour (I reported before) was due to different default sound card assignments in Windows XP sound config. Additionally I found that in FSX sound section we have two entries for sound devices, which I could assign different GUIDs. Now I hear the engine sound via one sound card and the pilots and controller voice via another sound card (see details in attached paper). It is still open to me to assign two sound cards in FS9 ??????? Can somebody help?? Thanks for your help Regards Alhard PS: I used your additional debug feature during my research. Thanks. Sound Tests.pdf
Pete Dowson Posted October 28, 2010 Report Posted October 28, 2010 Hi Pete, after long research I found the "bug". LUA Sound is working as designed! Great! Thanks for getting back on this! It is still open to me to assign two sound cards in FS9 ??????? Can somebody help?? As far as I recall FS9 didn't have any sound selection options, though you could try assigning a different device to voice in the windows control panel Sound applet. Regards Pete
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now