c172p-team / c172p

A high detailed version of the Cessna 172P aircraft for FlightGear
GNU General Public License v2.0
78 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).

gilbertohasnofb commented 9 years ago

@wlbragg Sound uploaded to branch bug-443.

thevirtualfer commented 9 years ago

Hi guys.

I lost my password.

When i inform my username and e-mail address, the page says that the e-mail/username information submitted could not be found.

How to go ahead ?

Cheers, to all of you.

2015-08-19 18:12 GMT-03:00 Gilberto Agostinho notifications@github.com:

@wlbragg https://github.com/wlbragg Sound uploaded to branch bug-443.

— Reply to this email directly or view it on GitHub https://github.com/Juanvvc/c172p-detailed/issues/443#issuecomment-132786079 .

onox commented 9 years ago

You only have to enter your e-mail address when you click on that lost password link on the log-in page. And you should know your e-mail address because Github is sending notifications (c172p-detailed related) to it.

gilbertohasnofb commented 8 years ago

@onox when you have time, could you please have a look on this? I already uploaded the sound to branch bug-443

onox commented 8 years ago

@gilbertohasnofb Don't we need to be able to set the position dynamically for this? That's not possible right now in simgear.

wlbragg commented 8 years ago

@onox I'm not sure what your referring to, According to Thorsten the position of the strike is accesible from the prop tree. We just need to calculate the distance to the strike and use that to compute the sound delay and maybe the sound volume also.

gilbertohasnofb commented 8 years ago

@onox I think @wlbragg is correct, Thorsten told me the same thing in the forum. But if for some reason we can't use the position and distance of the lightning strikes, no worries, we can either randomize it a bit or just simply fix it as a straight ahead thunder and far away.

Also, it would be nice to add some delays between the lightning strike and the thunder sounds, just like in real life. If we could use the distance to create this delay it would be so cool!

onox commented 8 years ago

I understand you can compute the distance, but wouldn't it be nice if you could hear that the thunderstrike happened behind you or to your right, for example?

gilbertohasnofb commented 8 years ago

@onox As far as I remember, Thorsten mentioned that we can have a property not only for distance but also the direction of the thunder, but I may be mistaken with that.

onox commented 8 years ago

The wiki says that should be already possible because it writes the offset (x, y, z) to the property tree. The problem is how to use in the sound system, because a <position> in the sound xml file is static. It cannot change during runtime. So what I was trying to say is that direction is not possible, only delay and activation of the sound.

Anyway, @gilbertohasnofb would you like to implement this? I know you don't know Nasal, so this is a good opportunity to learn :smile: :+1: I don't have much time to spend on programming for the next couple of months. I can review your code though if you add it to bug-443 branch.

What I suggest is to create a listener for /environment/lightning/lightning-pos-x. In the callback (a function) you use the x, y, and z offsets to compute the distance. Use the speed of sound (try to find it in the property tree or compute it yourself) to determine the delay in seconds.

Then use settimer() to set a boolean property (just like the click sounds for the buttons/switches) to activate the sound. What you could do is find the click() function in Nasal/c172p.nas and add a third parameter delay=0. Then use settimer() to delay the calling of the setprop() and second settimer() code (lines 39 to 46).

I can do this second part if you do the first part (determining the delay in seconds) :smile:

Btw, are we using those irradiance maps? It seems like Thorsten added it to create a screenshot of it, but he didn't bother to send in a patch to us :disappointed:

gilbertohasnofb commented 8 years ago

@onox I can give it a shot but very likely not for the next weeks, I have quite a lot of things to finish until the end of the month. But if there is no hurry then sure!

onox commented 8 years ago

:+1: There's no hurry.

gilbertohasnofb commented 8 years ago

@onox cool, I will give it a shot as soon as I can! And totally unrelated, but have you left the forum, onox? I just noticed while reading some old posts that your username is now black.

onox commented 8 years ago

And totally unrelated, but have you left the forum, onox?

Yes, I asked the moderators to retire me.

thevirtualfer commented 8 years ago

Hi there, @onox !

Your contributions are all valuable and amazing. And you have a strong experience and knowledge on flightgear internals.

Excuses to ask, but there is a technical reason to leave us ?

It is a enormous pity, @onox.

gilbertohasnofb commented 8 years ago

@thevirtualfer you are mistaking leaving the forum with leaving the project. As far as I understood, @onox only left the first, not the second.

wlbragg commented 8 years ago

@onox only left the first, not the second.

Yes, that does appear so.

thevirtualfer commented 8 years ago

Oh !

I and my english doing bad conclusions !!!!!!!!!

gilbertohasnofb commented 8 years ago

@onox Ok, so I am trying to implement this but I am running into all sorts of troubles, and I am sure there are tons of mistakes with my code. First, I added the following lines to c172p.nas:

##########################################
# Thunder Sound
##########################################

var thunder = func (name, timeout=0.1) {
    var sound_prop = "/sim/model/c172p/sound/thunder";
    var lightning_pos_X = "/environment/lightning/lightning-pos-x";
    var lightning_pos_Y = "/environment/lightning/lightning-pos-y";
    var lightning_distance = sqrt(pow(lightning_pos_X,2) + pow(lightning_pos_Y,2));
    var delay_seconds = lightning_distance * 340.29;

    # Play the sound
    settimer(func {
        setprop(sound_prop, 1);
                # Reset the property after 20 seconds (length of the file) so that the sound can be played again.
                settimer(func {
                    setprop(sound_prop, 0);
                }, 20);        
    }, delay_seconds);
};

And then the following one to c172-sound.xml:

    <thunder>
        <name>Thunder</name>
        <mode>once</mode>
        <path>Sounds/thunder.wav</path>
        <condition>
            <property>/sim/model/c172p/sound/thunder</property>
        </condition>
        <position>
            <x>
                <property>/environment/lightning/lightning-pos-x</property>
            </x>
            <y>
                <property>/environment/lightning/lightning-pos-y</property>
            </y>
            <z>0</z>
        </position>
        <reference-dist>0.2</reference-dist>
        <max-dist>5.0</max-dist>
    </thunder>

Am I too far from the solution?

gilbertohasnofb commented 8 years ago

And by the way, I couldn't find the property with the speed of sound, so I just hard coded it for this little experiment.

wkitty42 commented 8 years ago

On 10/30/2015 12:46 PM, Gilberto Agostinho wrote:

And then the following one to c172-sound.xml:

Thunder once Sounds/thunder.wav /sim/model/c172p/sound/thunder /environment/lightning/lightning-pos-x /environment/lightning/lightning-pos-y

you are missing the and tags around this property...

<z>0</z>

0.2 5.0

NOTE: No off-list assistance is given without prior approval. Please keep mailing list traffic on the list unless private contact is specifically requested and granted.

gilbertohasnofb commented 8 years ago

Thanks! I fixed my previous post

onox commented 8 years ago
var lightning_distance = sqrt(pow(lightning_pos_X,2) + pow(lightning_pos_Y,2));

Shouldn't you use z here as well?

# Play the sound
    settimer(func {
        setprop(sound_prop, 1);
                # Reset the property after 20 seconds (length of the file) so that the sound can be played again.
                settimer(func {
                    setprop(sound_prop, 0);
                }, 20);        
    }, delay_seconds);

I think it's better to improve the click() function.

<position>
    <x>
        <property>/environment/lightning/lightning-pos-x</property>
    </x>
    <y>
        <property>/environment/lightning/lightning-pos-y</property>
    </y>
    <z>0</z>
</position>

This is not possible currently, as I have explained in https://github.com/Juanvvc/c172p-detailed/issues/443#issuecomment-140281501. It would require changes to SimGear. You could ask Erik on the mailing list if he can implement it.

onox commented 8 years ago

@gilbertohasnofb I have rebased the single commit in bug-443 on top of master. (Otherwise we're going to get those nasty changed files because of Linux/OSX versus Windows line endings). Going to force push.

gilbertohasnofb commented 8 years ago

Shouldn't you use z here as well?

I don't think there is a z property for the lightning. Also, probably only x and y is enough for a reasonable distance calculation.

I think it's better to improve the click() function.

I don't think I understand, do you want me to improve the function? In which sense?

This is not possible currently, as I have explained in #443 (comment). It would require changes to SimGear. You could ask Erik on the mailing list if he can implement it.

I will talk to him.

I have rebase the single commit in bug-443 on top of master.

Hmm, sure, I just don't get why (my only commit so far was a sound file), but you know better what to do.

onox commented 8 years ago

I have already improved the function, will push in a minute.

Hmm, sure, I just don't get why (my only commit so far was a sound file), but you know better what to do.

That commit was done somewhere in August. At the point in time, there were still some files with wrong line endings (CRLF line endings). They result in "changed files" in git status on Linux or OS X.

onox commented 8 years ago

Okay, committed. Check that you are in the bug-443 branch. Then do git pull --force.

Use click("thunder", 20.0, delay_seconds);.

gilbertohasnofb commented 8 years ago

Ok!

onox commented 8 years ago

One more thing: wouldn't it be better to use /environment/lightning/lightning-range?

gilbertohasnofb commented 8 years ago

I don't know what that property is, can you explain it to me?

onox commented 8 years ago

I guess it's the distance? I found it in http://wiki.flightgear.org/FlightGear_Newsletter_August_2015#Atmospheric_Light_Scattering

gilbertohasnofb commented 8 years ago

I will give it a try and see what it is about.

gilbertohasnofb commented 8 years ago

@onox I can't hear any thunder sounds at all... and I have no idea what I am doing wrong. I just pushed my current attempt to the branch bug-443, do you think you can take a look at it?

Also, I was thinking about adding a rain sound to our plane, what do you think? Is there a way of telling if it's raining (but not snowing!) in the sim?

onox commented 8 years ago

You added stuff from the bug-117b branch? :worried:

onox commented 8 years ago

The problem is in the xml file you're using /sim/model/c172p/sound/thunder instead of /sim/model/c172p/sound/click-thunder.

onox commented 8 years ago

But can you remove that commit, it's not very nice to start importing stuff from other feature branches :stuck_out_tongue_closed_eyes:

onox commented 8 years ago

Or I'll do it for you if you don't know how to do it.

gilbertohasnofb commented 8 years ago

You added stuff from the bug-117b branch? :worried:

??! git status tells me:

gilberto@gilberto-Inspiron-7520 ~/WorkingFG/c172p/c172p $ git branch
  bug-117b
* bug-443
  bug-463
  heat-air-refactor
  master
  splash7
gilbertohasnofb commented 8 years ago

also, GitHub says the last commit to bug-117b was yours, "Position wind sound"

Or I'll do it for you if you don't know how to do it.

That would be nice, I never did that before.

onox commented 8 years ago

You are in the correct branch, but you added stuff from the bug-117b branch. Are you using this workflow in which you have a separated git repo + folder for FG?

onox commented 8 years ago

I let FG directly read from my git repo.

gilbertohasnofb commented 8 years ago

separated git repo + folder for FG?

Yep, and it's a pain. But when I tried to create a symlink, I would get tons of errors in the console about wrong paths.

gilbertohasnofb commented 8 years ago

Oh, forget that. Why use a symlink when I can simply add it to my #FG_AIRCRAFT. Sorry but I am not on my brightest day today :sob:

onox commented 8 years ago

Have you added --fg-aircraft=/home/gilbertohasnofb/flightgear/c172p to .fgfsrc?

onox commented 8 years ago

OK, going to force push. You can do git pull --force again.

Why use a symlink when I can simply add it to my #FG_AIRCRAFT

Hehe. I still use a folder with just symlinks to whitelist only certain aircraft.

gilbertohasnofb commented 8 years ago

Thanks onox, but what should I do about this?:

gilberto@gilberto-Inspiron-7520 ~/WorkingFG/c172p/c172p $ git pull --force
Auto-merging c172-sound.xml
Auto-merging Nasal/c172p.nas
CONFLICT (content): Merge conflict in Nasal/c172p.nas
Automatic merge failed; fix conflicts and then commit the result.
onox commented 8 years ago

Do this:

git reset --hard a8c06e8172b29ab7539ab0636c218ebb7a099479
git pull
gilbertohasnofb commented 8 years ago

Yeah, there were changed to be committed. So now with the hard reset it seems to be fine. Thanks a lot and sorry for the mess.......

onox commented 8 years ago

Did lightning-range work?

onox commented 8 years ago

Btw, ehh.. where's the code that calls thunder()? :laughing: Also, the 'timeout' parameter of thunder() isn't used, so it can be removed.