diff --git a/A320-main.xml b/A320-main.xml index f1ca51c5..d1c5d0d2 100644 --- a/A320-main.xml +++ b/A320-main.xml @@ -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> diff --git a/Nasal/Effects/thunder-effects.nas b/Nasal/Effects/thunder-effects.nas new file mode 100644 index 00000000..affe1a18 --- /dev/null +++ b/Nasal/Effects/thunder-effects.nas @@ -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); \ No newline at end of file diff --git a/Sounds/A320-common-sound.xml b/Sounds/A320-common-sound.xml index 2ee8cafc..220039bc 100644 --- a/Sounds/A320-common-sound.xml +++ b/Sounds/A320-common-sound.xml @@ -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> \ No newline at end of file diff --git a/Sounds/Effects/pushback.wav b/Sounds/Effects/pushback.wav new file mode 100644 index 00000000..5f38b8c3 Binary files /dev/null and b/Sounds/Effects/pushback.wav differ diff --git a/Sounds/Effects/rain-windshield.wav b/Sounds/Effects/rain-windshield.wav new file mode 100644 index 00000000..06eddc56 Binary files /dev/null and b/Sounds/Effects/rain-windshield.wav differ diff --git a/Sounds/Effects/rain.wav b/Sounds/Effects/rain.wav new file mode 100644 index 00000000..c074f4a4 Binary files /dev/null and b/Sounds/Effects/rain.wav differ diff --git a/Sounds/Effects/thunder1.wav b/Sounds/Effects/thunder1.wav new file mode 100644 index 00000000..bfbcbe1c Binary files /dev/null and b/Sounds/Effects/thunder1.wav differ diff --git a/Sounds/Effects/thunder2.wav b/Sounds/Effects/thunder2.wav new file mode 100644 index 00000000..60e58b66 Binary files /dev/null and b/Sounds/Effects/thunder2.wav differ diff --git a/Sounds/Effects/thunder3.wav b/Sounds/Effects/thunder3.wav new file mode 100644 index 00000000..6c9306d4 Binary files /dev/null and b/Sounds/Effects/thunder3.wav differ diff --git a/Sounds/Effects/thunder4.wav b/Sounds/Effects/thunder4.wav new file mode 100644 index 00000000..2ee2d166 Binary files /dev/null and b/Sounds/Effects/thunder4.wav differ