Jump to content
The simFlight Network Forums

Turbulence loppoing sound


Recommended Posts

Hi,

I would implement a looping sound until a weather turbulence is on.

I have tried to do that reading the differen turbulence offsets with the free tool PMSounds (Project Magenta) but without any success.

I think the reason is due to the fact that PMSounds reads only if a particular offset is on or off and, for what I have understood, the different turbulence offsets have not an on/off status but values from 0 to 255.

Do you have any suggestion about how I could solve this? Is there any offest that I'm missing simply saying if the weather turbulence is on or off?

Thanks in advance for the help

best regards

Joe

Link to comment
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Do you have any suggestion about how I could solve this?

Support for pmSounds would be by PM. I'm afraid I don't know it that well. You could try asking PM.

Alternatively it would be easy using Lua which supports sounds. In fact there's another recent thread near here about Lua sounds.

Regards

Pete

Link to comment
Share on other sites

Thanks from the prompt reply.

I will try with the LUA script .

Please allow me two more question:

- calling the lUA script as soon as FSUIPC is connected (calling it ipcintit.lua) does this men that the turbulence offsets are constantly monitored during the FSX session/flight?

- I am not able to find in the lua docs I have which are the parameters to have the sound looping (if the turbulence is on) or stopped (when the turbulence is off)

Thanks again

Link to comment
Share on other sites

- calling the lUA script as soon as FSUIPC is connected (calling it ipcintit.lua) does this men that the turbulence offsets are constantly monitored during the FSX session/flight?

Don't use ipcInit.lua for anything reading offsets because that is run as soon as FSUIPC is initialised. You need to use ipcReady.lua which is run when FS is ready to fly.

And Lua programs only continue to run if they are in a never-ending loop (not the best way) or use events to get themselves called regularly. You'd use "event.offset(...)" to get your sound-making function called whenever the offset changes.

- I am not able to find in the lua docs I have which are the parameters to have the sound looping (if the turbulence is on) or stopped (when the turbulence is off)

Sorry, I don't understand. You can't find the documents you have?

If you mean you can't find the Lua documentation, please look inside your FSUIPC Documents folder, inside the FS Modules folder.

BTW I have deleted the other identical thread you started. Please stick to one thread per subject. Thank you.

Pete

Link to comment
Share on other sites

Hi,

thanks for the support.

I have tried to build the lua file naming it ipcready as suggested and following your inputs. Here the script:

function turbulence(offset,value)

if (value > 0) and (sndflg == 0) then

sound.playloop("c:\\mysound\\turb.wav")

sndflg=1

end

if (value == 0) and (sndflg == 1) then

sound.stop("c:\\mysound\\turb.wav")

sndflg=0

end

end

-- FSUIPC different layers turbulence wind and clouds --

event.offset(0x0ED2,"UW","turbulence")

event.offset(0x0EDE,"UW","turbulence")

event.offset(0x0EEA,"UW","turbulence")

event.offset(0x0EFC,"UW","turbulence")

event.offset(0x0F02,"UW","turbulence")

event.offset(0x0F08,"UW","turbulence")

event.offset(0x0F54,"UW","turbulence")

event.offset(0x0F60,"UW","turbulence")

event.offset(0x0F6C,"UW","turbulence")

event.offset(0x0F76,"UW","turbulence")

event.offset(0x0F7E,"UW","turbulence")

event.offset(0x0F84,"UW","turbulence")

event.offset(0x0F8A,"UW","turbulence")

The script is executed (I see the log in the module dir), but nothing is happening. Could you please to be so patient to address me to the possible errors i'm doing?

Thanks in advance

Link to comment
Share on other sites

-- FSUIPC different layers turbulence wind and clouds --

event.offset(0x0ED2,"UW","turbulence")

event.offset(0x0EDE,"UW","turbulence")

event.offset(0x0EEA,"UW","turbulence")

event.offset(0x0EFC,"UW","turbulence")

event.offset(0x0F02,"UW","turbulence")

event.offset(0x0F08,"UW","turbulence")

event.offset(0x0F54,"UW","turbulence")

event.offset(0x0F60,"UW","turbulence")

event.offset(0x0F6C,"UW","turbulence")

event.offset(0x0F76,"UW","turbulence")

event.offset(0x0F7E,"UW","turbulence")

event.offset(0x0F84,"UW","turbulence")

event.offset(0x0F8A,"UW","turbulence")

Er ... if ANY one of those is changed to non-zero the sound will start, but if any one of them is changed to zero, the sound will stop. Are you sure that's what you want? Perhaps you need to explain what it is you want to achieve.

Events are only triggered when the offset value changes. If none of them actually change the function will never be called. Are you testing by setting turbulence on and off somehow, or are you just loading up FS with initial turbulence at the start -- which won't be triggering anything of course?

If you want to initialise things for start-up settings you'd have to call the function explicitly too, like so:

turbulence( 0x0ED2, ipc.readUW(0x0ED2) )

[Note here that this is such a common need that I am now seriously considering making the initial function call automatic. This should save a lot of this confusion].

but for every offset you are checking? No, that seems wrong -- it would keep turning the sound on and off according to each value, probably too fast for you to hear anything.

If you'd like to explicitly describe what it is you want to really achieve, maybe I can offer more constructive suggestions?

Pete

Link to comment
Share on other sites

Hi Pete,

.. and thanks for your support and patience.

What I would get with the script is to play a looping sound, simulating the shaking cabin noise of the aircraft, in case of turbulence and until that is active.

To test it I have loaded a saved flight without any turbulence and after some minutes i have changed in FSX the weather to have the strongest turbulence from 1000 ft up to 36000 ft (my FL is 32000). As mentioned nothing has happened. What I can see is that the turbulence is surely active (the aircraft is badly shaked), but no sound.

Joe

Link to comment
Share on other sites

What I would get with the script is to play a looping sound, simulating the shaking cabin noise of the aircraft, in case of turbulence and until that is active.

So you don't want to enable it just because of any turbulence at any altitude, only where the aircraft is? That isn't how you've written it so far.

To test it I have loaded a saved flight without any turbulence and after some minutes i have changed in FSX the weather to have the strongest turbulence from 1000 ft up to 36000 ft (my FL is 32000). As mentioned nothing has happened. What I can see is that the turbulence is surely active (the aircraft is badly shaked), but no sound.

The way you've programmed it, you have no checks for aircraft altitude, so it wouldn't matter even if it was on the ground.

But first things first -- I think the problem you have in your program is that you test "sndflg == 0" when the variable "sndflg" has not previously been declared. Therefore it is actually "nil" (a sepecial Lua value signifying nothing ot undefined). This is not a number and is never equal to zero, or 1, so neither parts of your function are ever executed and sndflg is never set.

You can fix that by simply putting "sndflg = 0" as a line on its own before your function.

As a general rule, in Lua, all variables to be used are best defined in this way at the beginning.

The other problem, only having the sound when the aircraft is actually IN a turbulent layer, can be worked out too -- but check this change first.

Pete

Link to comment
Share on other sites

Hi Pete,

I have done the change you suggested, below the new script with the flag declaration:

-- Turbulence looping sound --

-- Initializing sound flag --

sndflg=0

-- Function to play sound if and until turbulence is detected --

function turbulence(offset,value)

if (value > 0) and (sndflg == 0) then

sound.playloop("c:\\mysound\\turb.wav")

sndflg=1

end

if (value == 0) and (sndflg == 1) then

sound.stop("c:\\mysound\\turb.wav")

sound.play("c:\\mysound\\noturbadvise.wav")

sndflg=0

end

end

-- FSUIPC different layers turbulence wind and clouds are changing? If so exec function --

event.offset(0x0ED2,"UW","turbulence")

event.offset(0x0EDE,"UW","turbulence")

event.offset(0x0EEA,"UW","turbulence")

event.offset(0x0EFC,"UW","turbulence")

event.offset(0x0F02,"UW","turbulence")

event.offset(0x0F08,"UW","turbulence")

event.offset(0x0F54,"UW","turbulence")

event.offset(0x0F60,"UW","turbulence")

event.offset(0x0F6C,"UW","turbulence")

event.offset(0x0F76,"UW","turbulence")

event.offset(0x0F7E,"UW","turbulence")

event.offset(0x0F84,"UW","turbulence")

event.offset(0x0F8A,"UW","turbulence")

and things are changed: now I can hear the sound I want... the only problem is that now I hear it also without any turbulence (if I stop all the turbulence I hear the sound I have put to advise that the turbulence is finished, but after a moment the turbulence noise is back). sigh

Effectively I think I should check only the turbulence offset where the aircraft is, but I have no idea how to do that

Thanks again

Joe

Link to comment
Share on other sites

and things are changed: now I can hear the sound I want... the only problem is that now I hear it also without any turbulence (if I stop all the turbulence I hear the sound I have put to advise that the turbulence is finished, but after a moment the turbulence noise is back). sigh

That is because you are not stopping it. your line:

sound.stop("c:\\mysound\\turb.wav")

is not doing anything. The stop and query functions need the reference number for the sound which is returned by the play and playloop functions. Please do have another look at the documentation. Each time you play a sound it constitutes a "job" -- something being done. It is the JOB that has to stop. Re-addressing the Wave file doesn't help. It is quite possible to have the same wave being played several times, maybe on different speakers or at slightly different times (eg to simulate echo).

The 'ref' number is the reference to the sound job, as documented. The word "ref" used in the documentation is short for "reference". Sorry, but I thought that to be a quite commonly understood abbreviation?

Pete

Link to comment
Share on other sites

Hi Pete,

thanks, thanks, thanks !!!

After your last suggestion now the sound is played and stopped as that should be.

Now the only point I have to understand is how to activate the sound only if a turbulence is active at the altitude of the aircraft

I am really interested in this script: maybe you can share it when you finish your test and everything is ok...

Many thanks in advance.

Ciao

Fabio

Edited by fabiosko
Link to comment
Share on other sites

Now the only point I have to understand is how to activate the sound only if a turbulence is active at the altitude of the aircraft

That's actually much more difficult. It involves searching the cloud and wind layers to find which one the aircraft is within. The offsets you are currently using really only cover a few of the layers possible. Active Sky, among others, sets up to 12 layers. So the correct offsets to read are those of the "New Weather Interface", documented separately in the FSUIPC SDK. The offsets relating to weather at the aircraft position are 0xC000 to 0xC3FF, with:

Number of Wind Layers at 0xC0F8, full sets of data for each of up to 24 layers following at 0xC0FC

Number of Cloud Layers at 0xC27C, full sets of data for each of up to 24 layers following at 0xC280

You would need to read the aircraft altitude at 0x570 (just the whole number of metres at 0x0574 "SD" would do), then scan the tables of winds and clouds to see which layer you are in, before finally checking that layer's turbulence setting.

You would most certainly not want that sort of procedure to be executed every time the aircraft altitude changed a little, nor would monitoring that number of offsets make sense. Additionally if you doing this for FSX then I'm afraid the cloud turbulence will be a bit of a guess, as FSX doesn't supply the actual cloud height (i.e. we get the base altitude, but not the tops). So FSUIPC fills in a nominal value, different for each cloud type. Also, no matter whether it is FS9 orr FSX, you can't really detect if you are actually IN the cloud with turbulence: a cloud layer may only be 2 oktas with lots of blue sky between. I don't know of any way of detecting this without looking out of the window.

Quite honestly I wouldn't really attempt any of this for a fully programmed solution outside FS, let alone a Lua script. How important is it? What aircraft has this facility you are trying to make work?

Is this for FSX? If it is really important to get this working, the only thing I can think of is for me to add some more offsets which will provide more data on the conditions at the aircraft, without having to scan everything. This isn't too difficult to do for FSX and ESP, but I would be very reluctant to do it for FS9 or before.

Regards

Pete

Link to comment
Share on other sites

Hi Pete,

thanks for the explanation... a little complicated and scaring me.

Aniway the script is for FSX (and I use ASE). The reason to try is that this capability(that I find really realistic and nice) is in an add-on I have, but causing crashes on my FSX (despite several reinstallations).

So the idea is to replicate it by myself .

For the moment from the sript I have done, I will try to read in the function the info regarding the aircraft altitude to activate the sound only if I'm in the middle of a turbulence area (confronting the base and the ceiling of the layers).

I will let you know the result.

For Fabio: let me do some more test, after I will put it here for who interested (without the sounds .. coming from a payware add-on I don't think I can publish them).

Link to comment
Share on other sites

thanks for the explanation... a little complicated and scaring me.

Yes, it would scare me to try and do it well in a Lua script.

Aniway the script is for FSX (and I use ASE).

Good. In that case it is quite easy for me to provide just a couple of offsets for you to check -- one for wind turbulence, the other for cloud turbulence (with the provisos I mentioned about the latter inaccuracy).

I'll get back to you when it is done, maybe later today else over the weekend.

Regards

Pete

Link to comment
Share on other sites

I'll get back to you when it is done, maybe later today else over the weekend.

Okay. Done. told you it was easy! ;-)

Download 4.644 from the Download Links subforum. The change is this:

Additional offsets are now provided to allow applications to get weather data relevant to the user aircraft's current altitude. These are basically an extension to the provisions for populating the old FS98 weather values.

The new values provided are:

0E84 1 byte Cloud type, 1-10, if the aircraft is in a cloud layer. Otherwise 0

0E85 1 byte Cloud coverage, 0 - 8 "Oktas" or eighths of the sky.

0E86 2 bytes Cloud icing level 0-4

0E88 2 bytes Cloud turbulence level, 0-255 (as for older offsets 0EFC etc).

0E94 2 bytes Wind gusting value (max speed in knots, or 0 if no gusts)

0E96 2 bytes Wind directional variation -- degrees in the same units as wind directions

0E98 2 bytes Wind turbulence value, 0-255, just like offset 0ED2, etc.

So, you only need to have events set for offsets 0E88 and 0E98.

Okay?

Pete

Link to comment
Share on other sites

Hi Pete,

I do not know how to thank you !!!!! You are simply exceptional.. by the way like your tool.

I'm going to try that and I will let you know soon about the result.

By the way I'm getting passionate of these LUA scripts and I'm extending what I'm doing to include ATC radio chatters, several crew messages in different situations... and it is just the beginning !!!

Thanks again

Link to comment
Share on other sites

Hi Pete,

I do not know how to thank you !!!!! You are simply exceptional.. by the way like your tool.

I'm going to try that and I will let you know soon about the result.

By the way I'm getting passionate of these LUA scripts and I'm extending what I'm doing to include ATC radio chatters, several crew messages in different situations... and it is just the beginning !!!

Thanks again

exceptional thread indeed!!!

always more interested in you script cellular!!!

great support from pete... incredible

thanks all

ciao

fabio

Link to comment
Share on other sites

Hi Pete,

I have done several flights for test and... everything goes great and wonderfully !!!!

Those offsets you added are fantastic and detect the turbulence in a perfect way (the sound starts to play exactly when I notice the shaking of the aircraft in the turbulence).

I had only to add a control to check if the aircraft is on the ground to avoid the sound in case of turbulence at level of terrain that is quite unrealistic.

I really thank you more and more for the support and patience you showed supporting me in this.

I was asking myself if you think possible to attach in a post here my work in case other guys are interested with it and for eventual adds I could do in the script.

Thanks.. thanks again

Link to comment
Share on other sites

I was asking myself if you think possible to attach in a post here my work in case other guys are interested with it and for eventual adds I could do in the script.

Please, could you make a new thread for your project in the subforum called "User Contributions". Then it won't get lost. Please make the title really informative so folks know what they see.

Better clearly mark it for FSUIPC4 (FSX) because those new offsets are not available for FSUIPC3 (FS9).

Thank you!

Pete

Link to comment
Share on other sites

I was asking myself if you think possible to attach in a post here my work in case other guys are interested with it and for eventual adds I could do in the script.

Thanks for posting it. I've taken the liberty of enclosing the code part in code parentheses, to make it easier to identify and select. Code parentheses are put on by selecting text and using the <> button just above the edit area.

Regards

Pete

Link to comment
Share on other sites

  • 9 months later...

So, you only need to have events set for offsets 0E88 and 0E98.

Pete - Having tested these offsets it appears the offsets only trigger (ie value =1) when the aircraft transitions into (or curiously out of) the cloud or turbulance layer, that is at the boundry only.

Does this seem logical/the correct function? The implication is that the offset may trigger when the aircraft moves out of a turbulance layer, which isnt necessarily the desired funtion.

Link to comment
Share on other sites

Pete - Having tested these offsets it appears the offsets only trigger (ie value =1) when the aircraft transitions into (or curiously out of) the cloud or turbulance layer, that is at the boundry only.

Does this seem logical/the correct function? The implication is that the offset may trigger when the aircraft moves out of a turbulance layer, which isnt necessarily the desired funtion.

Sorry, I'm not with you. Lua events on offsets trigger when the offset changes. That's the whole point. If you want different actions on the values, check it -- it is supplied to the event function.

Pete

Link to comment
Share on other sites

Is there way to make this work with FS9?

I don't know. I'll take a look when I get time -- maybe next week. i have a lot of catching up to do after my holiday and I'm away this weekend too.

Most of cockpit builders use FS9

I don't think it is "most" any more. It was about 50:50 a while ago, but with the new cheaper faster Intel processors a lot more are moving to FSX now. My cockpit runs beautifully with FSX.

Regards

Pete

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.