Sounds.lua: Difference between revisions

From Spring
Jump to navigationJump to search
Created page with "'''WARNING : file not verified ! (contain some random errors)''' --[[DefaultsForSounds = { -- this are default settings file = "ThisEntryMustBePresent.wav", gain = 1.0, pi..."
 
Gajop (talk | contribs)
 
(22 intermediate revisions by 6 users not shown)
Line 1: Line 1:
'''WARNING : file not verified ! (contain some random errors)'''
==Location==
<code>sounds.lua</code> is a file in the <code>Gamedata/</code> 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:


* {{sourcelink|file=rts/System/Sound/SoundItem.cpp}}


--[[DefaultsForSounds = { -- this are default settings
==Data Types==
{{DataTypes}}


file = "ThisEntryMustBePresent.wav",
==Details==
Wherever a sound is played in Spring, be it associated with a [[Gamedev:UnitDefs|UnitDef]], [[Gamedev: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.


gain = 1.0,
Additionally, multiple '''SoundItems''' can use one single file with different settings, this is very efficient, as they only use 1 shared buffer.


pitch = 1.0,
{{new|89.0}}: All item names are treated in lowercase.


priority = 0,
==Tips==
You can update & reload your sounddefs at runtime via Spring.LoadSoundDef("gamedata/sounds.lua").


maxconcurrent = 16, --- some reasonable limits
===Reserved SoundItems===
The following '''SoundItems''' are reserved for specific engine sounds:


--maxdist = FLT_MAX, --- no cutoff at all
* <code>IncomingChat</code> - Is played when a chat message is received.
* <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.
* <code>default</code> - Used for all sounds that aren't listed in <code>sounds.lua</code>.


},
===SoundItem Properties===


--- EXAMPLE ONLY!
{{tag
|name = gain
|type = float
|default = 1.0
|description = This varies the loudness, > <code>1.0</code> is louder, < <code>1.0</code>  is quieter. <code>0.0</code> is silent.}}


]]
{{tag
|name = gainmod
|type = float
|default = 0.0
|description = If > <code>0.0</code> then this adds a random amount to {{taglink|gain}} each time the sound is played. Clamped between <code>0.0</code> and <code>1.0</code>. The result is in the range '''['''({{taglink|gain}} * (1 + {{taglink|gainMod}}))''',''' ({{taglink|gain}} * (1 - {{taglink|gainMod}}))''']'''.}}


{{tag
|name = pitch
|type = float
|default = 1.0
|description = Varies the pitch of the sound, > <code>1.0</code> is higher pitched, < <code>1.0</code> is lower.}}


{{tag
|name = pitchmod
|type = float
|default = 0.0
|description = If > <code>0.0</code> then this adds a random amount to {{taglink|pitch}} each time the sound is played. Clamped between <code>0.0</code> and <code>1.0</code>. The result is in the range '''['''({{taglink|pitch}} * (1 + {{taglink|pitchMod}}))''',''' ({{taglink|pitch}} * (1 - {{taglink|pitchMod}}))''']'''.}}


local Sounds = {
{{tag
|name = dopplerscale
|type = float
|default = 1.0
|description = How unit and camera speed affects the pitch of the sound, to exaggerate it, use values > <code>1.0</code>. Use <code>0.0</code> to completely disable the effect.}}


SoundItems = {
{{tag
|name = priority
|type = int
|default = 0
|description = When lots of sounds are played, sounds with lower {{taglink|priority}} are more likely to get cut off. A {{taglink|priority}} > <code>0</code> will never be cut of (priorities can be negative).}}


--- RESERVED FOR SPRING, DON'T REMOVE
{{tag
|name = maxconcurrent
|type = int
|default = 16
|description = How many copies of this sound can be played at once?}}


IncomingChat = {
{{tag
|name = maxdist
|type = float
|default = MAX_FLOAT
|description = The cut-off distance (in [[elmo]]s) at which this sound will no longer be played.}}


file = "sounds/killyu1.wav",
{{tag
|name = rolloff
|type = float
|default = 1.0
|description = How fast the sound becomes quieter with distance. <code>0.0</code> means always the same loudness regardless of distance.}}


rolloff = 0.1,  
{{tag
|name = in3d
|type = bool
|default = true
|description = Non-3d sounds always came out of the front-speakers (or the centre one). 3d sounds are, well, in 3d.}}


maxdist = 10000,
{{tag
|name = looptime
|type = int
|default = 0
|description = The time in milliseconds the sound should loop for.}}


priority = 100,  
==Examples==
===default sounds===
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).
<pre>
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,
    },


maxconcurrent = 1,
    -- new since 89.0
    default = {
      gainmod = 0.35,
      pitchmod = 0.3,
      pitch = 0.7,
      in3d = true,
    },
  },
}


},
return Sounds
 
</pre>
 
===Using PitchMod to prevent loud explosions====
 
Taken from this thread by jK: {{forumlink|topic=28819|title=Use PitchMod in sounds.lua to prevent loud explosions}}
MultiSelect = {
 
file = "sounds/cestpour.wav",
 
rolloff = 0.1, --- how fast it becomes more quiet in the distance (0 means aleays the same loudness regardless of dist)
 
maxdist = 10000,--- cutoff distance
 
priority = 50,---  sounds with lwoer priority are more likely to get cut off > 0 will never be cut of (priorities can be negative)
 
maxconcurrent = 1,--- this sound will not be played more than  at a time
 
dopplerscale = 0,--- how unit / camera speed affects the sound, to exagerate it, use values > 1, 0 completely disables the effect
 
in3d = "false",--- non-3d sounds do always came out of the front-speakers (or the center one)
 
preload = false,
 
gain = 1.1,--- loudness, > 1 is louder, < 1  is more quiet, you will most likely not set it to 0
 
pitch = 0.3,--- > 1 -> high pitched, < 1 lowered
 
looptime = 0,--- you can loop it for X miliseconds
 
},
 
 
 
MapPoint = {


file = "sounds/imnotgay.wav",
Explosions can sound louder than intended when they are started in the same simFrame and so are played in sync -> resonance. PitchMod now changes the playback time (e.g. with 0.3 the sounds should have a playback time of 100-130%) and so there isn't a resonance anymore even when the sound is started multiple times in the same simframe.


rolloff = 0.1,
<pre>
local files = VFS.DirList("sounds/explosions/")
local t = Sounds.SoundItems
for i=1,#files do
  local fileName = files[i]
  t[fileName] = {
      file    = fileName;
      pitchmod = 0.3;
      gainmod  = 0.2;
      maxconcurrent = 8;
  }
end
</pre>


maxdist = 10000,


priority = 100,


maxconcurrent = 1,
===External Examples===
{{sourcelink|file=cont/base/springcontent/gamedata/sounds.lua}} - The original default <code>sounds.lua</code>


},
[https://github.com/ZeroK-RTS/Zero-K/blob/master/gamedata/sounds.lua ZeroK sounds.lua]


--- END RESERVED
==Further Reading==
 
{{forumlink|topic=17647&start=25|title=Information about sounds.lua}}
--manu = {
{{forumlink|topic=20685|title=Information about gainMod and pitchMod}}
 
[[Category:gamedata]]
repair = {
 
},
 
arrived = {
 
},
 
select = {
 
},
 
deactivate = {
 
},
 
activate = {
 
},
 
ok= {
 
},
 
cant= {
 
},
 
working= {
 
},
 
build= {
 
},
 
underattack = {
 
file = "sounds/killyu1.wav",
 
rolloff = 0.1,
 
maxdist = 10000,
 
priority = 100, --- higher numbers = less chance of cutoff
 
maxconcurrent = 3, ---how many maximum can we hear?
 
},
 
--},
 
--WEAPONS
 
 
 
},
 
}
 
 
 
return Sounds

Latest revision as of 12:17, 18 December 2018

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:

Data Types

int
An integer number. eg. 5
float
A number with decimals. eg 1.023
bool
A value which can be true or false. eg true
string
Text, or more precisely a string of alphanumeric characters. eg "string of characters"
rgb
Three float components, representing red, green and blue components, ranged from 0.0 to 1.0. eg {0.0, 0.0, 0.0}
float3
Three float components, eg {0.0, 0.0, 0.0}
float4
Four float components, eg {0.0, 0.0, 0.0, 0.0}

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 one single file with different settings, this is very efficient, as they only use 1 shared buffer.

New in version 89.0: All item names are treated in lowercase.

Tips

You can update & reload your sounddefs at runtime via Spring.LoadSoundDef("gamedata/sounds.lua").

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.
  • default - Used for all sounds that aren't listed in sounds.lua.

SoundItem Properties

float gain  default: 1.0 

This varies the loudness, > 1.0 is louder, < 1.0 is quieter. 0.0 is silent.

float gainmod  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))].

float pitch  default: 1.0 

Varies the pitch of the sound, > 1.0 is higher pitched, < 1.0 is lower.

float pitchmod  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))].

float dopplerscale  default: 1.0 

How unit and camera speed affects the pitch of the sound, to exaggerate it, use values > 1.0. Use 0.0 to completely disable the effect.

int priority  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).

int maxconcurrent  default: 16 

How many copies of this sound can be played at once?

float maxdist  default: MAX_FLOAT 

The cut-off distance (in elmos) at which this sound will no longer be played.

float rolloff  default: 1.0 

How fast the sound becomes quieter with distance. 0.0 means always the same loudness regardless of distance.

bool in3d  default: true 

Non-3d sounds always came out of the front-speakers (or the centre one). 3d sounds are, well, in 3d.

int looptime  default: 0 

The time in milliseconds the sound should loop for.

Examples

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,
    },

    -- new since 89.0
    default = {
      gainmod = 0.35,
      pitchmod = 0.3,
      pitch = 0.7,
      in3d = true,
    },
  },
}

return Sounds

Using PitchMod to prevent loud explosions=

Taken from this thread by jK: Use PitchMod in sounds.lua to prevent loud explosions

Explosions can sound louder than intended when they are started in the same simFrame and so are played in sync -> resonance. PitchMod now changes the playback time (e.g. with 0.3 the sounds should have a playback time of 100-130%) and so there isn't a resonance anymore even when the sound is started multiple times in the same simframe.

local files = VFS.DirList("sounds/explosions/")
local t = Sounds.SoundItems
for i=1,#files do
   local fileName = files[i]
   t[fileName] = {
      file     = fileName;
      pitchmod = 0.3;
      gainmod  = 0.2;
      maxconcurrent = 8;
   }
end


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