Howto:Add sound effects to aircraft: Difference between revisions

→‎Configuration tags: moved delay-sec out of volume tag
No edit summary
(→‎Configuration tags: moved delay-sec out of volume tag)
(15 intermediate revisions by 4 users not shown)
Line 109: Line 109:
: Define a condition that triggers the event.
: Define a condition that triggers the event.


: For a complete description of the FlightGear conditions, please read docs-mini/README.conditions
: For a complete description of the FlightGear conditions, please read docs-mini/README.conditions or read the [[Conditions]] article on the wikie.


: An event should define either a condition or a property.
: An event should define either a condition or a property.
Line 133: Line 133:


; <code>&lt;type&gt;</code>
; <code>&lt;type&gt;</code>
: This defines the type os this sample:
: This defines the type of this sample, each type also have seperate volume slider in sound settings menu:


:; fx
:; fx
Line 142: Line 142:


:: It is up to the user to define if it can always be heard or only when in cockpit view.
:: It is up to the user to define if it can always be heard or only when in cockpit view.
:; atc
:: Is used by the ATC chatter add-on.
; <code>&lt;delay-sec&gt;</code>
: Delay after which the sound starts playing.
: This is useful to let a property start two sounds at the same time, where the second is delayed until the first stopped playing.


; <code>&lt;volume&gt;</code> / <code>&lt;pitch&gt;</code>
; <code>&lt;volume&gt;</code> / <code>&lt;pitch&gt;</code>
Line 148: Line 156:
: Currently there may be up to 5 volume and up to 5 pitch definitions defined within one sound event.
: Currently there may be up to 5 volume and up to 5 pitch definitions defined within one sound event.


: Normally all offset values are added together and the results after property calculations will be multiplied.
: There are two important results from each <volume> and <pitch> section: the offset and the value. Normally all offset values from the different volume/pitch are added together to create the total offset.  The values from each <volume> or <pitch> section are multiplied together to create an final value.  Then the volume (or pitch, respectively) is set to total offset + final value.


: A special condition occurs when the value of factor is negative, in which case the offset doesn't get added to the other offset values but instead will be used in the multiplication section.
: A special condition occurs when the value of factor is negative, in which case the offset doesn't get added to the other offset values but instead will be used in the multiplication section.


; <code>&lt;property&gt;</code>
: Pitch final output can range from 0 to 2. 1 represents the original pitch of the sound file.  Offset defaults to 1, meaning that if no specific <pitch> parameters are given the file will be played at its original pitch.
: Defines which property supplies the value for the calculation.
 
: Volume final output can range from 0 to 1. 1 represents full volume and 0 is silence.


: Either a <property> or an <internal> should be defined.
:; <code>&lt;expression&gt;</code>
:: Defines an expression, and will replace all other tags in this volume/pitch tag.


: The value is treated as a floating point number.
:; <code>&lt;property&gt;</code>
:: Defines which property supplies the value for the calculation.


; <code>&lt;internal&gt;</code>
:: Either a <property> or an <internal> should be defined.  If none is defined, the property reverts to its default.  For volume this is 0, meaning the sound will not be audible at all.
: Defines which internal variable should be used for the calculation.


: The value is treated as a floating point number.
:: The value is treated as a floating point number.


: The following internals are available at this time:
:; <code>&lt;internal&gt;</code>
:: Defines which internal variable should be used for the calculation.


:; dt_play
:: The value is treated as a floating point number.
:: The number of seconds since the sound started playing.


:; dt_stop
:: The following internals are available at this time:
:: The number of seconds after the sound has stopped.


; <code>&lt;delay-sec&gt;</code>
::; dt_play
: Delay after which the sound starts playing.
::: The number of seconds since the sound started playing.


: This is useful to let a property start two sounds at the same time, where the second is delayed until the first stopped playing.
::; dt_stop
::: The number of seconds after the sound has stopped.


; <code>&lt;type&gt;</code>
:; <code>&lt;type&gt;</code>
: Defines the function that should be used upon the property before it is used for calculating the net result:
:: Defines the function that should be used upon the property before it is used for calculating the net result:


:; lin
::; lin
:: Linear handling of the property value. This is the default.
::: Linear handling of the property value. This is the default.
   
   
:; ln
::; ln
:: Convert the property value to a natural logarithmic value before scaling it.
:: Convert the property value to a natural logarithmic value before scaling it.


:: Anything below 1 will return zero.
::: Anything below 1 will return zero.
   
   
:; log
::; log
:: convert the property value to a true logarithmic value before scaling it.
::: convert the property value to a true logarithmic value before scaling it. (log base 10)


:: Anything below 1 will return zero.
::: Anything below 1 will return zero.


:; inv
::; inv
:: Inverse linear handling (1/x).
::: Inverse linear handling (1/x).


:; abs
::; abs
:: Absolute handling of the value (always positive).
:: Absolute handling of the value (always positive).


:; sqrt
::; sqrt
:: Calculate the square root of the absolute value before scaling it.
::: Calculate the square root of the absolute value before scaling it.
 
:; <code>&lt;factor&gt;</code>
:: Defines the multiplication factor for the property value.
 
:: A special condition is when scale is defined as a negative value. In this case the result of |<scale>| * <property) will be subtracted from &lt;default&gt;


; <code>&lt;factor&gt;</code>
:; <code>&lt;offset&gt;</code>
: Defines the multiplication factor for the property value.
:: The initial value for this sound.


: A special condition is when scale is defined as a negative value. In this case the result of |<scale>| * <property) will be subtracted from &lt;default&gt;
:: This value is also used as an offset value for calculating the end result.


; <code>&lt;offset&gt;</code>
:; <code>&lt;random&gt;</code>
: The initial value for this sound.
:: Add a bit of randomness to the offset. Only used for pitch.


: This value is also used as an offset value for calculating the end result.
:; <code>&lt;min&gt;</code>
:: Minimum allowed value.


; <code>&lt;min&gt;</code>
:: This is useful if sounds start to sound funny. Anything lower will be truncated to this value.
: Minimum allowed value.


: This is useful if sounds start to sound funny. Anything lower will be truncated to this value.
:; <code>&lt;max&gt;</code>
:: Maximum allowed value.


; <code>&lt;max&gt;</code>
:: This is useful if sounds gets to loud. Anything higher will be truncated to this value.
: Maximum allowed value.


: This is useful if sounds gets to loud. Anything higher will be truncated to this value.
:: Keep in mind that min & max are applied first, then offset.  So for example if min = 0, max = 0.5 and offset = 1.0, then the resulting values will range 1 to 1.5.


; <code>&lt;position&gt;</code>
; <code>&lt;position&gt;</code>
Line 232: Line 247:


; <code>&lt;x&gt;</code>
; <code>&lt;x&gt;</code>
: X dimension offset
: X dimension offset (-X = forward, +X = aft, in meters)


; <code>&lt;y&gt;</code>
; <code>&lt;y&gt;</code>
: Y dimension offset
: Y dimension offset (+Y = left, -Y = right)


; <code>&lt;z&gt;</code>
; <code>&lt;z&gt;</code>
: Z dimension offset
: Z dimension offset (-Z = down, +Z = up)


; <code>&lt;orientation&gt;</code>
; <code>&lt;orientation&gt;</code>
Line 257: Line 272:


; <code>&lt;inner-angle&gt;</code>
; <code>&lt;inner-angle&gt;</code>
: The inner edge of the audio cone in degrees (0.0 - 180.0).
: The inner edge of the audio cone in degrees (0.0 - 360.0).


: Any sound withing that angle will be played at the current gain.
: Any sound withing that angle will be played at the current gain.


; <code>&lt;outer-angle&gt;</code>
; <code>&lt;outer-angle&gt;</code>
: The outer edge of the audio cone in degrees (0.0 - 180.0).
: The outer edge of the audio cone in degrees (0.0 - 360.0).


: Any sound beyond the outer cone will be played at "outer-gain" volume.
: Any sound beyond the outer cone will be played at "outer-gain" volume.
Line 270: Line 285:


; <code>&lt;reference-dist&gt;</code>
; <code>&lt;reference-dist&gt;</code>
: Set a reference distance of sound in meters. This is the distance where the volume is at its maximum.
: Set a reference distance of sound in meters. This is the distance where the volume is at its maximum. Default is 60.


: Volume is clamped to this maximum for any distance below.
: Volume is clamped to this maximum for any distance below.
Line 279: Line 294:


; <code>&lt;max-dist&gt;</code>
; <code>&lt;max-dist&gt;</code>
: Set the maximum audible distance for the sound in meters.
: Set the maximum audible distance for the sound in meters. Default is 6000.


: Sound is cut-off above this distance.
: Sound is cut-off above this distance.
Line 311: Line 326:
         value += offset[n] - abs(factor[n]) * function(property[n]);
         value += offset[n] - abs(factor[n]) * function(property[n]);
     } else {
     } else {
         value += factor[n] * function(property[n]);
         value *= factor[n] * function(property[n]);
         offs += offset[n];
         offs += offset[n];
     }
     }
Line 317: Line 332:


volume = offs + value;
volume = offs + value;
if (volume > 1.0) vol = 1.0;
</syntaxhighlight>
</syntaxhighlight>
where function can be one of: lin, ln, log, inv, abs or sqrt
where function can be one of: lin, ln, log, inv, abs or sqrt
Line 342: Line 358:
* [[Conditions]]
* [[Conditions]]
* [[Expressions]]
* [[Expressions]]
* [[Howto:Reload sound config without restarting FG]]
* [[Howto:Reload sound configuration without restarting]]


=== Readme file ===
=== Readme file ===
Line 348: Line 364:


=== Source code ===
=== Source code ===
* {{repo link
* {{simgear file|simgear/sound/xmlsound.hxx}}
| site  = sf
* {{simgear file|simgear/sound/xmlsound.cxx}}
| proj  = flightgear/simgear
* {{flightgear file|src/Sound/fg_fx.hxx}}
| path  = simgear/sound/xmlsound.hxx
* {{flightgear file|src/Sound/fg_fx.cxx}}
| text  = simgear/simgear/sound/xmlsound.hxx
}}
* {{repo link
| site  = sf
| proj  = flightgear/simgear
| path  = simgear/sound/xmlsound.cxx
| text  = simgear/simgear/sound/xmlsound.cxx
}}
* {{repo link
| site  = sf
| proj  = flightgear/flightgear
| path  = src/Sound/fg_fx.hxx
| text  = flightgear/src/Sound/fg_fx.hxx
}}
* {{repo link
| site  = sf
| proj  = flightgear/flightgear
| path  = src/Sound/fg_fx.cxx
| text  = flightgear/src/Sound/fg_fx.cxx
}}


[[Category:Aircraft enhancement]]
[[Category:Aircraft enhancement]]
579

edits