| 1 |
Users Guide to FlightGear sound configuration |
| 2 |
Version 0.9.8, October 30, 2005 |
| 3 |
Author: Erik Hofman <erik at ehofman dot com> |
| 4 |
|
| 5 |
This document is an attempt to describe the configuration of |
| 6 |
FlightGear flight simulator's aircraft sound in XML. |
| 7 |
|
| 8 |
Sound Architecture: |
| 9 |
------------------ |
| 10 |
All of the sound configuration files are XML-encoded* property lists. |
| 11 |
The root element of each file is always named <PropertyList>. Tags are |
| 12 |
almost always found in pairs, with the closing tag having a slash |
| 13 |
prefixing the tag name, i.e </PropertyList>. The exception is the tag |
| 14 |
representing an aliased property. In this case a slash is prepended to |
| 15 |
the closing angle bracket. (see section Aliasing) |
| 16 |
|
| 17 |
The top level sound configuration file is composed of a <fx>, a |
| 18 |
<name>, a <path> sound file and zero or more <volume> and/or <pitch> |
| 19 |
definitions. |
| 20 |
|
| 21 |
[ Paths are relative to $FG_ROOT (the root of the installed base package .) ] |
| 22 |
[ Absolute paths may be used. Comments are bracketed with <!-- -->. ] |
| 23 |
|
| 24 |
A limited sound configuration file would look something like this: |
| 25 |
|
| 26 |
<PropertyList> |
| 27 |
<fx> |
| 28 |
<engine> |
| 29 |
<name>engine</name> |
| 30 |
<path>Sounds/wasp.wav</path> |
| 31 |
<mode>looped</mode> |
| 32 |
<condition> |
| 33 |
<property>/engines/engine/running</property> |
| 34 |
</condition> |
| 35 |
<volume> |
| 36 |
<property>/engines/engine/mp-osi</property> |
| 37 |
<factor>0.005</factor> |
| 38 |
<min>0.15</min> |
| 39 |
<max>0.5</max> |
| 40 |
<offset>0.15</offset> |
| 41 |
</volume> |
| 42 |
<pitch> |
| 43 |
<property>/engines/engine/rpm</property> |
| 44 |
<factor>0.0012</factor> |
| 45 |
<min>0.3</min> |
| 46 |
<max>5.0</max> |
| 47 |
<offset>0.3</offset> |
| 48 |
</pitch> |
| 49 |
</engine> |
| 50 |
</fx> |
| 51 |
</PropertyList> |
| 52 |
|
| 53 |
This would define an engine sound event handler for a piston engine driven |
| 54 |
aeroplane. The sound representing the engine is located in $FG_ROOT/Sounds |
| 55 |
and is named wasp.wav. The event is started when the property |
| 56 |
/engines/engine/running becomes non zero. |
| 57 |
|
| 58 |
When that happens, the sound will be played looped (see <mode>) until the |
| 59 |
property returns zero again. As you can see the volume is mp-osi dependent, |
| 60 |
and the pitch of the sound depends on the engine rpm. |
| 61 |
|
| 62 |
Configuration description: |
| 63 |
------------------------- |
| 64 |
|
| 65 |
<fx> |
| 66 |
Named FX subtree living under /sim/sound |
| 67 |
|
| 68 |
< ... > |
| 69 |
This is the event separator. The text inside the brackets |
| 70 |
can be anything. Bit it is advised to give it a meaningful name |
| 71 |
like: crank, engine, rumble, gear, squeal, flap, wind or stall |
| 72 |
|
| 73 |
The value can be defined multiple times, thus anything which is |
| 74 |
related may have the same name (grouping them together). |
| 75 |
|
| 76 |
<name> |
| 77 |
This defines the name of the event. This name is used internally |
| 78 |
and, although it can me defined multiple times in the same file, |
| 79 |
should normally have an unique value. |
| 80 |
|
| 81 |
Multiple definitions of the same name will allow multiple sections |
| 82 |
to interfere in the starting and stopping of the sample. |
| 83 |
|
| 84 |
This method can't be used to control the pitch or volume of the |
| 85 |
sample, but instead multiple volume or pitch section should be |
| 86 |
included inside the same event. |
| 87 |
|
| 88 |
The types "raise" and "fall" will stop the playback of the sample |
| 89 |
regardless of any other event. This means that when the type "raise" |
| 90 |
is supplied, sample playback will stop when the event turns false. |
| 91 |
Using the type "fall" will stop playback when the event turns true. |
| 92 |
|
| 93 |
IMPORTANT: |
| 94 |
If the trigger is used for anything else but stopping the sound |
| 95 |
at a certain event, all sections with the same name *should* have |
| 96 |
exactly the same sections for everything but property and type. |
| 97 |
|
| 98 |
In the case of just stopping the sample at a certain event, the |
| 99 |
sections for path, volume and pitch may be omitted. |
| 100 |
|
| 101 |
<path> |
| 102 |
This defined th path to the sound file. The path is relative to the |
| 103 |
FlightGear root directory but could be specified absolute. |
| 104 |
|
| 105 |
<condition> |
| 106 |
Define a condition that triggers the event. |
| 107 |
For a complete description of the FlightGear conditions, |
| 108 |
please read docs-mini/README.conditions |
| 109 |
|
| 110 |
An event should define either a condition or a property. |
| 111 |
|
| 112 |
<property> |
| 113 |
Define which property triggers the event, and refers to a node |
| 114 |
in the FlightGear property tree. Action is taken when the property |
| 115 |
is non zero. |
| 116 |
|
| 117 |
A more sophisticated mechanism to trigger the event is described |
| 118 |
in <condition> |
| 119 |
|
| 120 |
<mode> |
| 121 |
This defines how the sample should be played: |
| 122 |
|
| 123 |
once: the sample is played once. |
| 124 |
this is the default. |
| 125 |
|
| 126 |
looped: the sample plays continuously, |
| 127 |
until the event turns false. |
| 128 |
|
| 129 |
in-transit: the sample plays continuously, |
| 130 |
while the property is changing its value. |
| 131 |
|
| 132 |
<type> |
| 133 |
This defines the type os this sample: |
| 134 |
|
| 135 |
fx: this is the default type and doesn't need to be defined. |
| 136 |
|
| 137 |
avionics: sounds set to this time don't have a position and |
| 138 |
orientation but are treated as if it's mounted to |
| 139 |
the aircraft panel. it's up to the user to define |
| 140 |
if it can always be heard or only when in cockpit |
| 141 |
view. |
| 142 |
|
| 143 |
<volume> / <pitch> |
| 144 |
Volume or Pitch definition. Currently there may be up to 5 |
| 145 |
volume and up to 5 pitch definitions defined within one sound |
| 146 |
event. |
| 147 |
|
| 148 |
The volume elements are processed as follows |
| 149 |
|
| 150 |
total_offset = 0 |
| 151 |
total_volume = 1.0 |
| 152 |
|
| 153 |
for each <volume> element: |
| 154 |
|
| 155 |
(a) if an <expression> is defined: |
| 156 |
and the value/result is >= 0 |
| 157 |
total_volume = total_volume * expression_value |
| 158 |
process next <volume> element |
| 159 |
(b) Use either <property> or <internal> as the base value |
| 160 |
(c) apply any <type> function to the value |
| 161 |
(d) value = value * abs(factor) |
| 162 |
(e) value = max(value, <max>) |
| 163 |
(f) value = min(value, <min>) |
| 164 |
(g) if <factor> was originally negative then use |
| 165 |
subtract-mode otherwise use normal mode |
| 166 |
|
| 167 |
(normal-mode) |
| 168 |
if (value >= 0) |
| 169 |
total_offset = total_offset + offset |
| 170 |
total_volume = total_volume * value |
| 171 |
|
| 172 |
(subtract-mode) |
| 173 |
value = value + offset |
| 174 |
if (value >= 0) |
| 175 |
total_volume = total_volume * value |
| 176 |
|
| 177 |
Then after processing all of the <volume> blocks the total |
| 178 |
volume will be determined by |
| 179 |
|
| 180 |
volume = total_offset + total_volume; |
| 181 |
|
| 182 |
If volume exceeds 1 it will be clipped to 1. |
| 183 |
|
| 184 |
The pitch elements are processed as follows |
| 185 |
|
| 186 |
total_offset = 0 |
| 187 |
total_pitch = 1.0 |
| 188 |
|
| 189 |
for each <pitch> element: |
| 190 |
|
| 191 |
(a) if an <expression> is defined: |
| 192 |
total_pitch = total_pitch * expression_value |
| 193 |
process next <pitch> element |
| 194 |
(b) Use either <property> or <internal> as the base value |
| 195 |
(c) apply any <type> function to the value |
| 196 |
(d) value = value * abs(factor) |
| 197 |
(e) value = max(value, <max>) |
| 198 |
(f) value = min(value, <min>) |
| 199 |
(g) if <factor> was originally negative then use |
| 200 |
subtract-mode otherwise use normal mode |
| 201 |
|
| 202 |
(normal-mode) |
| 203 |
total_offset = total_offset + offset |
| 204 |
total_pitch = total_pitch * value |
| 205 |
|
| 206 |
(subtract-mode) |
| 207 |
total_pitch = offset - value |
| 208 |
|
| 209 |
Then after processing all of the <pitch> blocks the total |
| 210 |
pitch will be determined by |
| 211 |
|
| 212 |
pitch = total_offset + total_pitch; |
| 213 |
|
| 214 |
<expression> |
| 215 |
Defines the AN SGExpression to be used to calculate the volume |
| 216 |
or pitch. When an expression is used all other tags in the |
| 217 |
volume block are ignored. |
| 218 |
Refs: README.expressions |
| 219 |
http://wiki.flightgear.org/Expressions |
| 220 |
|
| 221 |
<property> |
| 222 |
Property to use for the base value for the calculation. |
| 223 |
|
| 224 |
<factor> |
| 225 |
Defines the multiplication factor for the property value. |
| 226 |
|
| 227 |
If factor is negative then it will cause the calculation for |
| 228 |
this element to use the subtract-mode as defined above. The |
| 229 |
negative value for the factor will be converted to positive |
| 230 |
|
| 231 |
<offset> |
| 232 |
The offset elements will be summed and added to the to the |
| 233 |
calculated volume from all of the volume blocks, except when |
| 234 |
using subtract-mode in which case the offset is directly added |
| 235 |
to the calculated volume within each volume block |
| 236 |
|
| 237 |
<internal> |
| 238 |
Defines which internal variable should be used for the calculation. |
| 239 |
|
| 240 |
The value is treated as a floating point number. |
| 241 |
|
| 242 |
The following internals are available at this time: |
| 243 |
|
| 244 |
dt_play: the number of seconds since the sound started playing. |
| 245 |
|
| 246 |
dt_stop: the number of seconds after the sound has stopped. |
| 247 |
|
| 248 |
<delay-sec> |
| 249 |
Defines the delay after the volume block becomes active. |
| 250 |
|
| 251 |
An example would be to have two sounds that relate to a single |
| 252 |
property and the delay-sec element can be used to allow one |
| 253 |
sound to start after the end of the first one simply by |
| 254 |
setting the delay-sec to the duration of the sample. |
| 255 |
|
| 256 |
<type> |
| 257 |
Defines the function that should be used upon the property |
| 258 |
before it is used for calculating the net result: |
| 259 |
|
| 260 |
lin: linear handling of the property value. |
| 261 |
this is the default. |
| 262 |
|
| 263 |
ln: convert the property value to a natural logarithmic |
| 264 |
value before scaling it. Anything below 1 will return |
| 265 |
zero. |
| 266 |
|
| 267 |
log: convert the property value to a true logarithmic |
| 268 |
value before scaling it. Anything below 1 will return |
| 269 |
zero. |
| 270 |
|
| 271 |
inv: inverse linear handling (1/x). |
| 272 |
|
| 273 |
abs: absolute handling of the value (always positive). |
| 274 |
|
| 275 |
sqrt: calculate the square root of the absolute value |
| 276 |
before scaling it. |
| 277 |
|
| 278 |
<random> |
| 279 |
Add a bit of randomness to the offset. Only used for pitch. |
| 280 |
|
| 281 |
<min> |
| 282 |
Minimum allowed value. |
| 283 |
This is useful if sounds start to sound funny. Anything lower |
| 284 |
will be truncated to this value. |
| 285 |
|
| 286 |
<max> |
| 287 |
Maximum allowed value. |
| 288 |
This is useful if sounds gets to loud. Anything higher will be |
| 289 |
truncated to this value. |
| 290 |
|
| 291 |
<position> |
| 292 |
Specify the position of the sounds source relative to the |
| 293 |
aircraft center. The coordinate system used is a left hand |
| 294 |
coordinate system where +Y = left, -Y = right, -Z = down, +Z = |
| 295 |
up, -X = forward, +X = aft. Distances are in meters. |
| 296 |
The volume calculation due to distance and orientation of the |
| 297 |
sounds source ONLY work on mono samples! |
| 298 |
|
| 299 |
<x> |
| 300 |
X dimension offset |
| 301 |
|
| 302 |
<y> |
| 303 |
Y dimension offset |
| 304 |
|
| 305 |
<z> |
| 306 |
Z dimension offset |
| 307 |
|
| 308 |
|
| 309 |
<orientation> |
| 310 |
Specify the orientation of the sounds source. |
| 311 |
|
| 312 |
The zero vector is default, indicating that a Source is not directional. |
| 313 |
Specifying a non-zero vector will make the Source directional in |
| 314 |
the X,Y,Z direction |
| 315 |
|
| 316 |
<x> |
| 317 |
X dimension |
| 318 |
|
| 319 |
<y> |
| 320 |
Y dimension |
| 321 |
|
| 322 |
<z> |
| 323 |
Z dimension |
| 324 |
|
| 325 |
<inner-angle> |
| 326 |
The inner edge of the audio cone in degrees (0.0 - 180.0). |
| 327 |
Any sound withing that angle will be played at the current gain. |
| 328 |
|
| 329 |
<outer-angle> |
| 330 |
The outer edge of the audio cone in degrees (0.0 - 180.0). |
| 331 |
Any sound beyond the outer cone will be played at "outer-gain" volume. |
| 332 |
|
| 333 |
<outer-gain> |
| 334 |
The gain at the outer edge of the cone. |
| 335 |
|
| 336 |
|
| 337 |
<reference-dist> |
| 338 |
Set a reference distance of sound in meters. This is the |
| 339 |
distance where the volume is at its maximum. |
| 340 |
Volume is clamped to this maximum for any distance below. |
| 341 |
Volume is attenuated for any distance above. |
| 342 |
Attenuation depends on reference and maximum distance. See |
| 343 |
OpenAL specification on "AL_INVERSE_DISTANCE_CLAMPED" mode |
| 344 |
for details on exact computation. |
| 345 |
|
| 346 |
<max-dist> |
| 347 |
Set the maximum audible distance for the sound in meters. |
| 348 |
Sound is cut-off above this distance. |
| 349 |
|
| 350 |
Known issue: if a sample with mode 'once' goes out of range, |
| 351 |
it stops playing entirely, and going back into range of the |
| 352 |
sound does not allow to hear the end of the sample. |
| 353 |
|
| 354 |
|
| 355 |
Creating a configuration file: |
| 356 |
------------------------------ |
| 357 |
|
| 358 |
To make things easy, there is a default value for most entries to allow a |
| 359 |
sane configuration when a certain entry is omitted. |
| 360 |
|
| 361 |
Default values are: |
| 362 |
|
| 363 |
type: lin |
| 364 |
factor: 1.0 |
| 365 |
offset: 0.0 for volume, 1.0 for pitch |
| 366 |
min: 0.0 |
| 367 |
max: 0.0 (don't check) |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
Calculations are made the following way (for both pitch and volume): |
| 372 |
|
| 373 |
value = 0; |
| 374 |
offs = 0; |
| 375 |
|
| 376 |
for (n = 0; n < max; n++) { |
| 377 |
if (factor < 0) |
| 378 |
{ |
| 379 |
value += offset[n] - abs(factor[n]) * function(property[n]); |
| 380 |
} |
| 381 |
else |
| 382 |
{ |
| 383 |
value += factor[n] * function(property[n]); |
| 384 |
offs += offset[n]; |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
volume = offs + value; |
| 389 |
|
| 390 |
where function can be one of: lin, ln, log, inv, abs or sqrt |