1
0
Fork 0

Port J-Maverick 16's sound work

This commit is contained in:
legoboyvdlp R 2020-05-04 21:15:13 +01:00
parent 757f70222b
commit d5995a7ce6
10 changed files with 238 additions and 0 deletions

View file

@ -3935,6 +3935,7 @@
<systems>
<file>Aircraft/A320-family/Nasal/Systems/APU.nas</file>
<file>Aircraft/A320-family/Nasal/Effects/effects.nas</file>
<file>Aircraft/A320-family/Nasal/Effects/thunder-effects.nas</file>
<file>Aircraft/A320-family/Nasal/Systems/electrical.nas</file>
<file>Aircraft/A320-family/Nasal/Systems/pneumatics.nas</file>
<file>Aircraft/A320-family/Nasal/Systems/hydraulics.nas</file>

View file

@ -0,0 +1,85 @@
########### Thunder sounds (from c172p) ###################
var clamp = func(v, min, max) { v < min ? min : v > max ? max : v };
var speed_of_sound = func (t, re) {
# Compute speed of sound in m/s
#
# t = temperature in Celsius
# re = amount of water vapor in the air
# Compute virtual temperature using mixing ratio (amount of water vapor)
# Ratio of gas constants of dry air and water vapor: 287.058 / 461.5 = 0.622
var T = 273.15 + t;
var v_T = T * (1 + re/0.622)/(1 + re);
# Compute speed of sound using adiabatic index, gas constant of air,
# and virtual temperature in Kelvin.
return math.sqrt(1.4 * 287.058 * v_T);
};
var thunder_listener = func {
var thunderCalls = 0;
var lightning_pos_x = getprop("/environment/lightning/lightning-pos-x");
var lightning_pos_y = getprop("/environment/lightning/lightning-pos-y");
var lightning_distance = math.sqrt(math.pow(lightning_pos_x, 2) + math.pow(lightning_pos_y, 2));
# On the ground, thunder can be heard up to 16 km. Increase this value
# a bit because the aircraft is usually in the air.
if (lightning_distance > 20000)
return;
var t = getprop("/environment/temperature-degc");
var re = getprop("/environment/relative-humidity") / 100;
var delay_seconds = lightning_distance / speed_of_sound(t, re);
# Maximum volume at 5000 meter
var lightning_distance_norm = std.min(1.0, 1 / math.pow(lightning_distance / 5000.0, 2));
settimer(func {
var thunder1 = getprop("sim/sound/thunder1");
var thunder2 = getprop("sim/sound/thunder2");
var thunder3 = getprop("sim/sound/thunder3");
var thunder4 = getprop("sim/sound/thunder4");
var vol = getprop("sim/current-view/internal");
if (!thunder1) {
thunderCalls = 1;
setprop("sim/sound/dist-thunder1", lightning_distance_norm * vol * 1.75);
}
else if (!thunder2) {
thunderCalls = 2;
setprop("sim/sound/dist-thunder2", lightning_distance_norm * vol * 1.75);
}
else if (!thunder3) {
thunderCalls = 3;
setprop("sim/sound/dist-thunder3", lightning_distance_norm * vol * 1.75);
}
else if (!thunder4) {
thunderCalls = 4;
setprop("sim/sound/dist-thunder4", lightning_distance_norm * vol * 1.75);
}
else
return;
# Play the sound (sound files are about 9 seconds)
play_thunder("thunder" ~ thunderCalls, 9.0, 0);
}, delay_seconds);
};
var play_thunder = func (name, timeout=0.1, delay=0) {
var sound_prop = "/sim/sound/" ~ name;
settimer(func {
# Play the sound
setprop(sound_prop, 1);
# Reset the property after timeout so that the sound can be
# played again.
settimer(func {
setprop(sound_prop, 0);
}, timeout);
}, delay);
};
setlistener("/environment/lightning/lightning-pos-y", thunder_listener);

View file

@ -1794,5 +1794,157 @@
<reference-dist>10</reference-dist>
<max-dist>100.0</max-dist>
</stall-voice>
<rain>
<name>RainInside</name>
<mode>looped</mode>
<path>Aircraft/A320-family/Sounds/Effects/rain.wav</path>
<condition>
<property>sim/current-view/internal</property>
<greater-than>
<property>/environment/rain-norm</property>
<value>0</value>
</greater-than>
</condition>
<volume>
<property>/environment/rain-norm</property>
<factor>0.095</factor>
</volume>
</rain>
<rain-windshield>
<name>RainWindshieldInside</name>
<mode>looped</mode>
<path>Aircraft/A320-family/Sounds/Effects/rain-windshield.wav</path>
<condition>
<property>sim/current-view/internal</property>
<greater-than>
<property>/environment/rain-norm</property>
<value>0</value>
</greater-than>
</condition>
<volume>
<property>velocities/airspeed-kt</property>
<factor>0.0075</factor>
<min>0.04</min>
<max>0.38</max>
</volume>
</rain-windshield>
<thunder1>
<name>thunder1</name>
<mode>once</mode>
<path>Aircraft/A320-family/Sounds/Effects/thunder1.wav</path>
<type>avionics</type>
<property>sim/sound/thunder1</property>
<pitch>
<property>sim/sound/dist-thunder1</property>
<factor>2</factor>
<offset>0.50</offset>
<min>1.00</min>
<max>2.00</max>
</pitch>
<volume>
<property>sim/sound/dist-thunder1</property>
</volume>
</thunder1>
<thunder2>
<name>thunder2</name>
<mode>once</mode>
<path>Aircraft/A320-family/Sounds/Effects/thunder2.wav</path>
<type>avionics</type>
<property>sim/sound/thunder2</property>
<pitch>
<property>sim/sound/dist-thunder2</property>
<factor>2</factor>
<offset>0.50</offset>
<min>1.00</min>
<max>2.00</max>
</pitch>
<volume>
<property>sim/sound/dist-thunder2</property>
</volume>
</thunder2>
<thunder3>
<name>thunder3</name>
<mode>once</mode>
<path>Aircraft/A320-family/Sounds/Effects/thunder3.wav</path>
<type>avionics</type>
<property>sim/sound/thunder3</property>
<pitch>
<property>sim/sound/dist-thunder3</property>
<factor>1</factor>
<offset>0.50</offset>
<min>1.00</min>
<max>2.00</max>
</pitch>
<volume>
<property>sim/sound/dist-thunder3</property>
</volume>
</thunder3>
<thunder4>
<name>thunder4</name>
<mode>once</mode>
<path>Aircraft/A320-family/Sounds/Effects/thunder4.wav</path>
<type>avionics</type>
<property>sim/sound/thunder4</property>
<pitch>
<property>sim/sound/dist-thunder4</property>
<factor>1</factor>
<offset>0.50</offset>
<min>1.00</min>
<max>2.00</max>
</pitch>
<volume>
<property>sim/sound/dist-thunder4</property>
</volume>
</thunder4>
<pushback>
<name>Pushback_outside</name>
<mode>looped</mode>
<path>Aircraft/A320-family/Sounds/Effects/pushback.wav</path>
<condition>
<and>
<not>
<property>/sim/current-view/internal</property>
</not>
<property>/sim/model/autopush/enabled</property>
</and>
</condition>
<volume>
<value>0.35</value>
</volume>
<pitch>
<property>sim/model/autopush/force-lbf</property>
<factor>0.0001</factor>
<offset>0.50</offset>
<min>0.50</min>
<max>0.65</max>
</pitch>
</pushback>
<pushback>
<name>Pushback_inside</name>
<mode>looped</mode>
<path>Aircraft/A320-family/Sounds/Effects/pushback.wav</path>
<condition>
<and>
<property>/sim/current-view/internal</property>
<property>/sim/model/autopush/enabled</property>
</and>
</condition>
<volume>
<value>0.15</value>
</volume>
<pitch>
<property>sim/model/autopush/force-lbf</property>
<factor>0.0001</factor>
<offset>0.50</offset>
<min>0.50</min>
<max>0.65</max>
</pitch>
</pushback>
</fx>
</PropertyList>

BIN
Sounds/Effects/pushback.wav Normal file

Binary file not shown.

Binary file not shown.

BIN
Sounds/Effects/rain.wav Normal file

Binary file not shown.

BIN
Sounds/Effects/thunder1.wav Normal file

Binary file not shown.

BIN
Sounds/Effects/thunder2.wav Normal file

Binary file not shown.

BIN
Sounds/Effects/thunder3.wav Normal file

Binary file not shown.

BIN
Sounds/Effects/thunder4.wav Normal file

Binary file not shown.