I've been playing with the sound system for the A-4. Neat stuff. I
was getting bitten by some strange behavior, though, which I tracked
to an some uninitialized stack variables in fg_sound.cxx. If a sound
is defined without a specific scaling function (i.e., "just play this
sound"), the volume and pitch numbers can come out with arbitrary,
depending on the stack environment. This might explain some of the
inconsistent reports we hear occasionally about sounds not playing.
The patch is trivial, and included below.
Also, attached is my current a4-sound.xml file, if folks want to try
it. I've tweaked a bunch of things to make it more pleasing to my
ears. The engine pitch is scaled to the N1 RPM and is played at a
roughly constant volume rather than dying off at high thrust, and the
roar scales linearly with thrust rather than with the logarithm of
thrust, which matches my experience on jetliners better (most of the
sound exists only at the highest thrust settings). At idle, all you
hear is the engine whine -- no thrust rumble. The gear lock sounds
plays correctly now when the gear reach minimum extension.
I really like it -- you can definitely hear the engine spool up and
down now, and associate a given sound with a thrust setting. My
approaches in the A-4 have actually gotten better because of it. I'll
probably continue tweaking in the future, but it's good enough for
government work as-is, IMHO.
Andy
diff -u -r1.17 fg_sound.cxx
--- fg_sound.cxx 4 Jun 2002 14:27:20 -0000 1.17
+++ fg_sound.cxx 13 Jun 2002 16:39:47 -0000
@@ -318,7 +318,7 @@
double volume_offset = 0.0;
for(i = 0; i < max; i++) {
- double v;
+ double v = 1;
if (_volume[i].prop)
v = _volume[i].prop->getDoubleValue();
@@ -354,7 +354,7 @@
double pitch_offset = 0.0;
for(i = 0; i < max; i++) {
- double p;
+ double p = 1;
if (_pitch[i].prop)
p = _pitch[i].prop->getDoubleValue();
--
Andrew J. Ross NextBus Information Systems
Senior Software Engineer Emeryville, CA
[EMAIL PROTECTED] http://www.nextbus.com
"Men go crazy in conflagrations. They only get better one by one."
- Sting (misquoted)
<?xml version="1.0"?>
<PropertyList>
<fx>
<engine>
<name>engine</name>
<path>Sounds/jet.wav</path>
<mode>looped</mode>
<property>/engines/engine/running</property>
<volume>
<property>/engines/engine/prop-thrust</property>
<type>lin</type>
<factor>0.0002353</factor> <!-- Scales to 0-2 for 8500lb engine -->
</volume>
</engine>
<engine>
<name>whine</name>
<path>Sounds/whine.wav</path>
<mode>looped</mode>
<property>/engines/engine/running</property>
<pitch>
<property>/engines/engine/n1</property>
<type>lin</type>
<factor>.008</factor>
</pitch>
<volume>
<property>/engines/engine/n1</property>
<type>log</type>
<factor>0.1</factor> <!-- 10-100% rpm == 0.1 - 1 factor -->
</volume>
</engine>
<rumble>
<name>rumble</name>
<mode>looped</mode>
<path>Sounds/rumble.wav</path>
<condition>
<or>
<property>/gear/gear[0]/wow</property>
<property>/gear/gear[1]/wow</property>
<property>/gear/gear[2]/wow</property>
</or>
</condition>
<volume>
<property>/velocities/airspeed-kt</property>
<type>lin</type>
<factor>.012</factor>
</volume>
</rumble>
<gear>
<name>gear</name>
<mode>in-transit</mode>
<path>Sounds/gear.wav</path>
<property>/gear/gear[0]/position-norm</property>
<pitch>
<internal>dt_play</internal>
<offset>1.0</offset>
<factor>-0.001</factor>
</pitch>
</gear>
<gear>
<name>gear-lock</name>
<path>Sounds/gear-lck.wav</path>
<condition>
<equals>
<property>/gear/gear[0]/position-norm</property>
<value>0</value>
</equals>
</condition>
</gear>
<squeal>
<name>squeal</name>
<path>Sounds/squeal.wav</path>
<condition>
<or>
<property>/gear/gear[0]/wow</property>
<property>/gear/gear[1]/wow</property>
<property>/gear/gear[2]/wow</property>
</or>
</condition>
<volume>
<property>/velocities/speed-down-fps</property>
<factor>0.05</factor>
</volume>
<volume>
<property>/velocities/airspeed-kt</property>
<factor>0.01</factor>
</volume>
<volume>
<internal>dt_stop</internal>
<factor>0.05</factor>
<max>1.0</max>
</volume>
<pitch>
<property>/velocities/airspeed-kt</property>
<factor>0.0025</factor>
<offset>1.2</offset>
</pitch>
</squeal>
<flap>
<name>flaps</name>
<mode>in-transit</mode>
<path>Sounds/flaps.wav</path>
<property>/surface-positions/flap-pos-norm</property>
<volume>
<offset>0.25</offset>
</volume>
</flap>
<wind>
<name>wind</name>
<mode>looped</mode>
<path>Sounds/wind.wav</path>
<property>/velocities/airspeed-kt</property>
<volume>
<property>/position/altitude-ft</property>
<factor>-0.000015</factor>
<offset>1.0</offset>
<min>0.1</min>
<max>1.0</max>
</volume>
<volume>
<property>/velocities/airspeed-kt</property>
<factor>0.0015</factor>
<min>0.03</min>
<max>0.25</max>
</volume>
<pitch>
<property>/velocities/airspeed-kt</property>
<factor>0.01</factor>
<offset>1.25</offset>
</pitch>
</wind>
<stall>
<name>stall</name>
<path>Sounds/stall.wav</path>
<property>/sim/aero/alarms/stall-warning</property>
<volume>
<property>/velocities/airspeed-kt</property>
<min>30.0</min>
</volume>
</stall>
<!-- no binding yet?
<click>
<name>click</name>
<path>Sounds/click.wav</path>
</click>
-->
</fx>
</PropertyList>