c172p-team / c172p

A high detailed version of the Cessna 172P aircraft for FlightGear
GNU General Public License v2.0
79 stars 44 forks source link

Thunder sound #443

Closed gilbertohasnofb closed 8 years ago

gilbertohasnofb commented 9 years ago

According to: http://wiki.flightgear.org/FlightGear_Newsletter_August_2015#Atmospheric_Light_Scattering

Since the simulation writes the position and range of the lightning strike relative to the current eye position into the /environment/lightning node of the Property Tree (lightning-pos-x, lightning-pos-y, and lightning-range), aircraft modellers can use this information to trigger a thunder sound after a delay.

So it would be cool if we implement some thunder sounds in our plane. I can come up with the sound and maybe @onox could give me a hand implementing it.

(Both could be supported if we can spawn sounds at absolute positions).

onox commented 8 years ago

About the interruption of the sounds: it seems AW will spawn at most 2 thunderstorms. Each can trigger a flash at most every second. That would mean an upper bound of 18 sounds :sob:

gilbertohasnofb commented 8 years ago

Make sure you use spaces

Just changed my indentation preferences in gedit.

Yes, first thing you can do is replace 1.0 in with /sim/model/c172p/sound/volume-boost-doors.

Will do that.

About the interruption of the sounds: it seems AW will spawn at most 2 thunderstorms. Each can trigger a flash at most every second. That would mean an upper bound of 18 sounds

Yep, I realised that. Maybe we could convince Thorsten to diminish a bit the number of lightnings for the Thunderstorm theme, but anyway there should be some METAR which produce less lightnings per second

gilbertohasnofb commented 8 years ago

Question: in xml, how do I work with multiple conditions inside an block? like condition1 or condition2 or condition3 ?

onox commented 8 years ago
<condition>
    <or>
onox commented 8 years ago

I think we need a Nasal API to trigger an arbitrary amount of sounds. This would also be useful for the click sounds.

gilbertohasnofb commented 8 years ago

I think we need a Nasal API to trigger an arbitrary amount of sounds.

Yes, that would be ideal. Also, right now the sounds stop when a lightning strikes, not when the thunder sound comes, which makes a clear interruption between thunder sounds. If we managed to at least interrupt the previous playback only at the moment of the new one, the cut would not be so noticiable.

gilbertohasnofb commented 8 years ago

And I fix all the indentation on the previous additions of mine.

onox commented 8 years ago

I'm writing to the mailing list about it.

gilbertohasnofb commented 8 years ago

Perfect. I just committed now the wind shield rain sound and code. Can you test and see what you think? I included all four internal views.

onox commented 8 years ago

@gilbertohasnofb I would use <property>/sim/current-view/internal</property>.

onox commented 8 years ago

And make sure you indent the whole block to the same level as the other sounds :wink:

gilbertohasnofb commented 8 years ago

Ok!

gilbertohasnofb commented 8 years ago

Should be okay now. Can you test the sounds and see what you think? I particularly like the result :smile:

onox commented 8 years ago

I don't see <property>/sim/model/c172p/sound/volume-boost-doors</property> in <thunder> and <rain> yet?

onox commented 8 years ago

No need to add it to <rain-windshield>, but it can be added to the other two sounds.

gilbertohasnofb commented 8 years ago

You need to check your :eyes: , it's there :wink:

onox commented 8 years ago

Ok, had to do another git pull :smile:

gilbertohasnofb commented 8 years ago

No, I am joking, I just added after you wrote me :smile:

onox commented 8 years ago

Oh, haha. It sounds nice.

onox commented 8 years ago

How about increasing the volume a bit depending on airspeed?

gilbertohasnofb commented 8 years ago

Oh the windshield rain? Or both?

onox commented 8 years ago

Just the wind shield.

gilbertohasnofb commented 8 years ago

I just did that, but I am having some troubles setting up the parameters for a decent result. I am actually preferring the constant volume sound.

onox commented 8 years ago

I'll be AFK for now. If you want to work on the airspeed thing, I think you could add a new <filter> to Systems/sounds.xml and then add a <property> to the <volume> block of <rain-windshield>.

About the <position> element of <rain-windshield>: you can try to use <x>-0.5</x>. That should make it directional.

onox commented 8 years ago

We can use constant volume for now then.

gilbertohasnofb commented 8 years ago

I had added a block:

            <volume>
                <property>velocities/airspeed-kt</property>
                <factor>0.0015</factor>
                <min>0.03</min>
                <max>0.25</max>
            </volume>
gilbertohasnofb commented 8 years ago

Ok, so I will not push. I also have to go, so we continue some other time. Take care and thanks a lot for all the help!

onox commented 8 years ago

That block might work just as well.

onox commented 8 years ago

I'll fix <x>.

gilbertohasnofb commented 8 years ago

It works, but the parameters aren't giving a good result. Let's try some other time to play around with that, if not we leave the constant volume.

onox commented 8 years ago

I think we need <offset>0.7</offset> instead.

gilbertohasnofb commented 8 years ago

Inside that volume block?

onox commented 8 years ago

Yes, let me test.

gilbertohasnofb commented 8 years ago

Ok!

onox commented 8 years ago

Committed. Create a PR?

gilbertohasnofb commented 8 years ago

Sure. Do you want me to do it myself?

onox commented 8 years ago

You can create a PR if you want. Just mention this issue in the PR to create a reference on Github.

gilbertohasnofb commented 8 years ago

Ok, I will do that right now.

onox commented 8 years ago

Shall we merge it now? Thunder sound might need some work (depending on work by core devs) in a new issue.

gilbertohasnofb commented 8 years ago

I would still make the thunder sound volume depend on the distance, what do you think? Then we can merge and wait to see what the core devs say.

onox commented 8 years ago

Hmm... yeah, I want the rain sounds merged :stuck_out_tongue_winking_eye:

onox commented 8 years ago

Thunder sound is not good anyway right now because of the interruptions.

gilbertohasnofb commented 8 years ago

I want the rain sounds merged

Hehehe me as well, I like it a lot! So let's just merge it, and then later we see what to do with the thunders.

onox commented 8 years ago

OK. We can keep the branch and reopen the issue once simgear has been patched.

gilbertohasnofb commented 8 years ago

I'd say let's not delete branch bug-443 yet if we plan to do more work on these thunder sounds.

gilbertohasnofb commented 8 years ago

@onox Here is a crazy idea: if the devs won't implement the feature we need for proper thunder, what about instead of using a simple listener we also use a counter with module 20, so that when the listener detects a change the counter is incremented and it calls one of the 20 copies of the thunder function? Sounds ridiculous and it would look ugly in the code, but it would get the job done I believe.

wlbragg commented 8 years ago

This function doesn't have a way of finding out if a sound it still active and if so activating a different one, it simply stops the previous sound.

@gilbertohasnofb, you beat me to it. I was getting ready to propose something similar. If we have a var telling us a sound has been played and we know how long that sound is then we have all we need to make our own function to manage the sounds. It doesn't have to be a hack or ugly, it's just done in nasal space instead of c space. I think it could work.

Oh and by the way, great job with this whole implementation.

wlbragg commented 8 years ago

With that said, I know next to nothing about sound implementation in FG. Can you play multiple sounds at the same time? If so then I don't understand where the problem is exactly. I'll explain if the answer to my last question is true!

wlbragg commented 8 years ago

I just finished testing the thunder sound implementation, really cool. While I was at it I noticed the engine sound and the thunder at the same time, so multiple sounds can be played at the same time.

So why can't we do something like the following pseudo code? This is a really rough idea of the code, only meant as an example of how it might work. Syntax is not even close to reality but should get the point across.

array thunderSounds=[10][bool=false]; 
# array of 10 thunderSounds available, all initially set to false (not currently playing)

if  thunder is triggered
{
   doWhile thunderSounds[randomNumber][true] 
   {
    #loop until we find a sound that is not already playing

     thunderSounds[theRandomNumber][now=true];
     #found one that is not playing already, make it true (it's playing now)
   }
   generateSound(theRandomNumber);
}

func generateSound(theRandomNumber){
     soundFile = theRandomNumber;
     lengthOfSound = lengthOf(soundFile);
     playSound(soundFile);
    if  lengthOfSound is finished
    {
        thunderSounds[theRandomNumber][false]
    }
}
gilbertohasnofb commented 8 years ago

It doesn't have to be a hack or ugly, it's just done in nasal space instead of c space. I think it could work.

Great, so let's try implementing it!

Oh and by the way, great job with this whole implementation.

Thanks a lot, I am taking my first baby steps towards learning Nasal :smile:

Can you play multiple sounds at the same time?

Yes, you can. The problem is not about playing multiple sounds, the problem is that the listener was trigering a same function, which would stop any previous sound it had been playing. So if we had n instances of this function, we could rotate them with a counter+module and thus the problem would be solved. I think 18 or 20 instances would suffice (@onox did the maths yesterday)

This is a really rough idea of the code

I just don't get why you are using randomNumber. I would say that the counter with module 20 is the way to go.