Sounds.lua: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
Flozi (talk | contribs)
Flesh out sounds.lua more fully
Line 1: Line 1:
Gamedata/Sounds.lua
==Location==
==Location==
sounds.lua is stored in the <code>gamedata\</code> directory of a Spring Game.
<code>sounds.lua</code> is a file in the <code>Gamedata/</code> directory of a Spring Game.


==Purpose==
==Purpose==
Can be used to create ''SoundItems'' from audio files.
The file is used to define '''SoundItems'''. Beside simply "linking" to an audio file, '''SoundItems''' can use various tags to alter the playback of the file.
Beside simply "linking" to an audio file, ''SoundItems'' can use various tags to alter the playback of the file, ie adjust volume.


These ''SoundItems'' can then be used in [[Units-UnitDefs | UnitDefs]] and [[Weapon-weaponDefs]] (what about Lua ???)
==Source==
The engine source code which parses the data from this file is viewable here: {{sourcelink|file=rts/System/Sound/SoundItem.cpp}}


This file is not mandatory.
==Details==
Wherever a sound is played in Spring, be it associated with a [[Units-UnitDefs|UnitDef]], [[Weapon-WeaponDefs|WeaponDef]] or via the [[Lua_UnsyncedCtrl#Sounds|lua API]], a '''SoundItem''' is used. If you access a raw sound file, a '''SoundItem''' with the defaults is created for you.


==Example==
Additionally, multiple '''SoundItems''' can use on single file with different settings, this is very efficient, as they only use 1 shared buffer.
===default sounds===
sounds.lua as found in <code>base\springcontent.sdz\gamedata\</code>
<pre>
--- Valid entries used by engine: IncomingChat, MultiSelect, MapPoint
--- other than that, you can give it any name and access it like before with filenames
local Sounds = {
SoundItems = {
IncomingChat = {
--- always play on the front speaker(s)
file = "sounds/beep4.wav",
in3d = "false",
},
MultiSelect = {
--- always play on the front speaker(s)
file = "sounds/button9.wav",
in3d = "false",
},
MapPoint = {
--- respect where the point was set, but don't attuenuate in distace
--- also, when moving the camera, don't pitch it
file = "sounds/beep6.wav",
rolloff = 0,
dopplerscale = 0,
},
ExampleSound = {
--- some things you can do with this file


--- can be either ogg or wav
===Reserved SoundItems===
file = "somedir/subdir/soundfile.ogg",
The following '''SoundItems''' are reserved for specific engine sounds:


--- loudness, > 1 is louder, < 1  is more quiet, you will most likely not set it to 0
* <code>IncomingChat</code> - Is played when a chat message is received.
gain = 1,
* <code>MultiSelect</code> - Is played when multiple units are selected simultaneously.
* <code>MapPoint</code> - Is played when a map point is placed by the player or an ally.
* <code>FailedCommand</code> - Is played when a unit fails to execute a command. e.g. When a unit cannot reach it's destination etc.


--- > 1 -> high pitched, < 1 lowered
===SoundItem Properties===
pitch = 1,


--- how unit / camera speed affects the sound, to exagerate it, use values > 1
* '''<code>gain</code>''' - type: <code>float</code> - default: <code>1.0</code>
--- dopplerscale = 0 completely disables the effect
: This varies the loudness, > <code>1.0</code> is louder, < <code>1.0</code>  is quieter. <code>0.0</code> is silent.
dopplerscale = 1,
* '''<code>gainmod</code>''' - type: <code>float</code> - default: <code>0.0</code>
: If > <code>0.0</code> then this adds a random amount to <code>gain</code> each time the sound is played. Clamped between <code>0.0</code> and <code>1.0</code>. The result is in the range '''['''(<code>gain</code> * (1 + <code>gainMod</code>))''',''' (<code>gain</code> * (1 - <code>gainMod</code>))''']'''.
* '''<code>pitch</code>''' - type: <code>float</code> - default: <code>1.0</code>
: Varies the pitch of the sound, > <code>1.0</code> is higher pitched, < <code>1.0</code> is lower.
* '''<code>pitchmod</code>''' - type: <code>float</code> - default: <code>0.0</code>
: If > <code>0.0</code> then this adds a random amount to <code>pitch</code> each time the sound is played. Clamped between <code>0.0</code> and <code>1.0</code>. The result is in the range '''['''(<code>pitch</code> * (1 + <code>pitchMod</code>))''',''' (<code>pitch</code> * (1 - <code>pitchMod</code>))''']'''.
* '''<code>dopplerscale</code>''' - type: <code>float</code> - default: <code>1.0</code>
: How unit and camera speed affects the sound, to exaggerate it, use values > <code>1.0</code>. Use <code>0.0</code> to completely disable the effect.
* '''<code>priority</code>''' - type: <code>int</code> - default: <code>0</code>
: When lots of sounds are played, sounds with lower <code>priority</code> are more likely to get cut off. A <code>priority</code> > <code>0</code> will never be cut of (priorities can be negative).
* '''<code>maxconcurrent</code>''' - type: <code>int</code> - default: <code>16</code>
: How many copies of this sound can be played at once?
* '''<code>maxdist</code>''' - type: <code>float</code> - default: <code>FLT_MAX</code>
: The cut-off distance (in [[elmos]]) at which this sound will no longer be played.
* '''<code>rolloff</code>''' - type: <code>float</code> - default: <code>1.0</code>
: How fast the sound becomes quieter with distance. <code>0.0</code> means always the same loudness regardless of distance.
* '''<code>in3d</code>''' - type: <code>bool</code> - default: <code>true</code>
: Non-3d sounds always came out of the front-speakers (or the centre one). 3d sounds are, well, in 3d.
* '''<code>looptime</code>''' - type: <code>int</code> - default: <code>0</code>
: The time in milliseconds the sound should loop for.


--- when lots of sounds are played, sounds with lwoer priority are more likely to get cut off
==Example==
--- priority > 0 will never be cut of (priorities can be negative)
===default sounds===
priority = 0,
The following is the default <code>sounds.lua</code> supplied in the base content [[springcontent.sdz]] archive, with some of the comments removed (As the information is presented here).
 
<code><pre>
--- this sound will not be played more than 16 times at a time
local Sounds = {
maxconcurrent = 16,
  SoundItems = {
 
    IncomingChat = {
--- cutoff distance
      --- always play on the front speaker(s)
maxdist = 20000,
      file = "sounds/beep4.wav",
 
      in3d = "false",
--- how fast it becomes more quiet in the distance (0 means aleays the same loudness regardless of dist)
    },
rolloff = 1,
    MultiSelect = {
 
      --- always play on the front speaker(s)
--- non-3d sounds do always came out of the front-speakers (or the center one)
      file = "sounds/button9.wav",
--- 3d sounds are, well, in 3d
      in3d = "false",
in3d = true,
    },
 
    MapPoint = {
--- you can loop it for X miliseconds
      --- respect where the point was set, but don't attenuate in distance
looptime = 0,
      --- also, when moving the camera, don't pitch it
},
      file = "sounds/beep6.wav",
},
      rolloff = 0,
      dopplerscale = 0,
    },
    ExampleSound = {
      --- some things you can do with this file
      --- can be either ogg or wav
      file = "somedir/subdir/soundfile.ogg",
      gain = 1,
      pitch = 1,
      dopplerscale = 1,
      priority = 0,
      maxconcurrent = 16,
      maxdist = 20000,
      rolloff = 1,
      in3d = true,
      looptime = 0,
    },
  },
}
}


return Sounds
return Sounds
</pre>
</pre></code>
===External Examples===
{{sourcelink|file=cont/base/springcontent/gamedata/sounds.lua}} - The original default <code>sounds.lua</code>
 
[http://code.google.com/p/zero-k/source/browse/trunk/mods/zk/gamedata/sounds.lua ZeroK sounds.lua]


==Further Reading==
{{forumlink|topic=17647|title=Information about sounds.lua}}
{{forumlink|topic=20685|title=Information about gainMod and pitchMod}}
[[Category:gamedata]]
[[Category:gamedata]]

Revision as of 16:11, 7 July 2011

Location

sounds.lua is a file in the Gamedata/ directory of a Spring Game.

Purpose

The file is used to define SoundItems. Beside simply "linking" to an audio file, SoundItems can use various tags to alter the playback of the file.

Source

The engine source code which parses the data from this file is viewable here: rts/System/Sound/SoundItem.cpp

Details

Wherever a sound is played in Spring, be it associated with a UnitDef, WeaponDef or via the lua API, a SoundItem is used. If you access a raw sound file, a SoundItem with the defaults is created for you.

Additionally, multiple SoundItems can use on single file with different settings, this is very efficient, as they only use 1 shared buffer.

Reserved SoundItems

The following SoundItems are reserved for specific engine sounds:

  • IncomingChat - Is played when a chat message is received.
  • MultiSelect - Is played when multiple units are selected simultaneously.
  • MapPoint - Is played when a map point is placed by the player or an ally.
  • FailedCommand - Is played when a unit fails to execute a command. e.g. When a unit cannot reach it's destination etc.

SoundItem Properties

  • gain - type: float - default: 1.0
This varies the loudness, > 1.0 is louder, < 1.0 is quieter. 0.0 is silent.
  • gainmod - type: float - default: 0.0
If > 0.0 then this adds a random amount to gain each time the sound is played. Clamped between 0.0 and 1.0. The result is in the range [(gain * (1 + gainMod)), (gain * (1 - gainMod))].
  • pitch - type: float - default: 1.0
Varies the pitch of the sound, > 1.0 is higher pitched, < 1.0 is lower.
  • pitchmod - type: float - default: 0.0
If > 0.0 then this adds a random amount to pitch each time the sound is played. Clamped between 0.0 and 1.0. The result is in the range [(pitch * (1 + pitchMod)), (pitch * (1 - pitchMod))].
  • dopplerscale - type: float - default: 1.0
How unit and camera speed affects the sound, to exaggerate it, use values > 1.0. Use 0.0 to completely disable the effect.
  • priority - type: int - default: 0
When lots of sounds are played, sounds with lower priority are more likely to get cut off. A priority > 0 will never be cut of (priorities can be negative).
  • maxconcurrent - type: int - default: 16
How many copies of this sound can be played at once?
  • maxdist - type: float - default: FLT_MAX
The cut-off distance (in elmos) at which this sound will no longer be played.
  • rolloff - type: float - default: 1.0
How fast the sound becomes quieter with distance. 0.0 means always the same loudness regardless of distance.
  • in3d - type: bool - default: true
Non-3d sounds always came out of the front-speakers (or the centre one). 3d sounds are, well, in 3d.
  • looptime - type: int - default: 0
The time in milliseconds the sound should loop for.

Example

default sounds

The following is the default sounds.lua supplied in the base content springcontent.sdz archive, with some of the comments removed (As the information is presented here).

local Sounds = {
  SoundItems = {
    IncomingChat = {
      --- always play on the front speaker(s)
      file = "sounds/beep4.wav",
      in3d = "false",
    },
    MultiSelect = {
      --- always play on the front speaker(s)
      file = "sounds/button9.wav",
      in3d = "false",
    },
    MapPoint = {
      --- respect where the point was set, but don't attenuate in distance
      --- also, when moving the camera, don't pitch it
      file = "sounds/beep6.wav",
      rolloff = 0,
      dopplerscale = 0,
    },
    ExampleSound = {
      --- some things you can do with this file
      --- can be either ogg or wav
      file = "somedir/subdir/soundfile.ogg",
      gain = 1,
      pitch = 1,
      dopplerscale = 1,
      priority = 0,
      maxconcurrent = 16,
      maxdist = 20000,
      rolloff = 1,
      in3d = true,
      looptime = 0,
    },
  },
}

return Sounds

External Examples

cont/base/springcontent/gamedata/sounds.lua - The original default sounds.lua

ZeroK sounds.lua

Further Reading

Information about sounds.lua Information about gainMod and pitchMod