Soundscape: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Added link to Episode 2 soundscapes)
(alien swarm code has this)
 
(126 intermediate revisions by 47 users not shown)
Line 1: Line 1:
{{toc-right}}
{{LanguageBar}}
{{subpage|[[Sound and Music]]}}
{{tabsBar|main=s2|base=Soundscape}}


'''Soundscapes''' are audio scripts that create background ambience in maps. Sound clips can be looped or played randomly, and can be emitted evenly or from specific locations. A soundscape can also enforce [[DSP]] and [[Soundmixer]] profiles.
A '''Soundscape''' is a type of audio script used to add ambience to maps. It can be used in any number of maps, requires only a single entity to implement, and does not generate any network traffic.  Soundscapes use a mixture of looped and randomly played sounds, all of which have the option to be emitted from one of eight  assignable target locations; [[DSP]] and [[Soundmixer]] profiles can also be enforced.


A soundscape can be used in any number of maps, requires only a single entity to implement, and does not generate any network traffic. However, the sounds it plays cannot be precisely controlled and only one soundscape can be active at any given time.
Only one soundscape can be active at any given time, and the individual sounds used within it cannot be controlled via inputs. When another soundscape is activated, the game will cross fade from one to the other.


Soundscapes will crossfade between each other over a default of three seconds. Configure this from the console with <code>soundscape_fadetime</code>.
{{tip|
* Cross fade time is defined by the [[cvar]] <code>soundscape_fadetime</code>, or <code>fadetime</code> in newer branches.
* Use the [[cvar]] <code>soundscape_debug</code> to examine which soundscape is active and why.}}
{{note|
* Soundscapes will not work if the map has not been compiled with VVIS, at least in "-fast" mode.
* Sound files will not properly loop unless they have a cue point. See [[Looping a Sound]].
* In most ''Source'' engine branches, soundscapes cannot play two of the same sounds, even if the pitch, the volume or the sound level is different. See below for possible solutions.
* At least one soundscape radius or [[trigger_soundscape|trigger box]] should cover the [[info_player_start]] or whatever game specific [[:Category:player spawn entities|player spawn entities]] you have, else the players will spawn without loading any soundscape until they trigger a Soundscape.}}


== Implementing ==
==Soundscapes==
===Browsing Soundscapes===
Soundscapes are typically located in the <code>scripts\</code> folder of a game, stored across multiple text files prefixed with <code>soundscapes_</code>. Each file is loaded via <code>scripts\soundscapes_manifest.txt</code>, which lists all soundscape scripts that should be mounted by the game. Soundscapes mounted through the manifest can be used anywhere in the game, even if they're only intended for a specific area.


=== env_soundscape ===
Soundscapes can also be mounted on a per-map basis by naming them
{{pre|
scripts\soundscapes_<mapname>.txt
}}
with <code><mapname></code> being the map that they should be loaded on. These soundscapes will be mounted by that map automatically without changing the manifest and can only be used in that map.


Soundscapes are generally implemented with [[env_soundscape]]. Its keyvalues, inputs etc. should be self-explanatory.
{{note|These files are usually packed away in the original Valve games, but they can be overridden automatically by any unpacked files within that folder.}}


The active env_soundscape is the one that the player:
At the bottom of this article you will find links to lists of soundscapes for individual games, along with attempts at describing them.


# Has direct line of sight to
You can browse through all the available soundscapes in a current game first hand, using the in-game console command <code>PlaySoundscape</code>. After typing in the first letter as the commands parameter, the auto-complete feature will list them as suggestions. You can then scroll through this list using the arrow keys.
# Is in range of
# Is closest to (in case of a tie)


When an env_soundscape ceases to be active, the soundscape it began persists until another one is begun or the map changes.
===Configuring Soundscapes===
Soundscapes can only be configured through these entities:
*[[env_soundscape]]
*[[env_soundscape_triggerable]]
There are other entities which can activate the soundscape, but these are the only entities which actually define soundscape properties. The other entities will point to these and use them as masters to remotely trigger the soundscape.
Whenever these entities activate a soundscape, any positional audio will originate from the targets defined under their properties.{{tip| Many soundscapes define positions for sounds to emanate from, so it is always a good idea to  peek into the soundscape entry and get a feel for what you can do. Most entries are found in the text files listed in the <code><game>/scripts/soundscapes_manifest.txt</code> file. To better understand soundscape entries, [[Soundscape#Custom_Soundscapes|see below]].}}


{{tip|Use the [[convar]] <code>soundscape_debug</code> examine which entity is active and why.}}
===Activating Soundscapes===
Any soundscape entity that is enabled and becomes triggered by the player, activates its - or its master's - specified soundscape. Soundscapes remain active until a map change occurs, or another soundscape is activated, even if the entity that originally activated it becomes disabled. {{tip|The <code>soundscape_flush</code> console command will cancel an active soundscape.}}


=== trigger_soundscape ===


The other method is [[trigger_soundscape]]. The associated [[env_soundscape_triggerable]] will be played when the player is inside the trigger volume.
===Soundscape entities===
Soundscapes can be activated by any of the following entities:


{{note|Unlike env_soundscape, trigger_soundscape's soundscapes do not persist once the player leaves its influence.}}
*[[env_soundscape]]
*[[env_soundscape_triggerable]] (in turn typically activated by a [[trigger_soundscape]].)
*[[env_soundscape_proxy]] (in turn activates an env_soundscape or an env_soundscape_triggerable.)


=== Finding a soundscape ===
Soundscape entities are themselves [[point_entities|point-based]], but trigger when the player enters their specified radius and the entity has a [[line of sight]] to them.


Hammer doesn't list available soundscapes. The best way of finding one is loading up a map and using the [[concommand]] <code>playsoundscape</code> (which does know what's available and will autocomplete while you type) to start one up.
The two exceptions to this are env_soundscape_proxy (that is triggered through an env_soundscape or an env_soundscape_triggerable), and env_soundscape_triggerable (that is typically set to also be triggered by a trigger_soundscape).


== Creating ==
As only one soundscape can be active at any one time, if one or more soundscape entities are triggered simultaneously, the closest one is given precedence. (The radius of soundscape entities always take precedence over trigger_soundscape brushes.)


=== Example ===
Note that a soundscape will ''not'' stop playing just because a player exits its radius or it loses line of sight to them.


Soundscapes work like this:


<name>
{{tip|Use the [[cvar]] [[soundscape_debug]] to examine which entity is active and why.}}
{
<rule>
{
<keyvalue>
...
}
...
}


All must be stored in text files listed by <code>game\scripts\soundscapes_manifest.txt</code>. Each must have a globally unique name.


{{tip|Mappers can create <code>scripts\soundscapes_<map name no extension>.txt</code> to use new soundscapes without modifying the manifest.}}
===Soundscape Placement===
At first, a good rule is to place only as many soundscapes as you absolutely need. Try to choose from a similar set of soundscapes to be played, and then pick one that will be your primary soundscape. After that, place your secondary soundscapes at every contrasting location (e.g. house, generator room).  Make sure that every location with localized sound effects has its own master soundscape that is tied to the proper targets.


=== Common keyvalues ===
Once you've gotten a general idea of where your soundscapes will be located, you'll then be able to start adding/configuring the entities that will trigger your soundscapes and create a kind of ''blueprint'' for how soundscapes will flow from one to another. In many cases, you'll be placing entities that block off all exits from your contrasting locations with triggers to your primary soundscapes. Basically, the goal is to anticipate the player's movement throughout the map, and to block off each area in such a way that it will always have the proper soundscape activated.


After your flow is organized, you'll be able to specialize your soundscapes/triggers to behave in complex ways (e.g responding to game events).
===Multiple instances of one sound in one soundscape===
Currently, in most ''Source'' engine branches, it is impossible to play two or more identical sounds at same time in the same soundscape, even if the volume, the pitch or the sound level is different.
This issue has been remedied {{csgo|since}}, allowing soundscapes to play multiple instances of identical sounds concurrently. The fix involves using <code>enginesound->GetGuidForLastSoundEmitted()</code> and related functions in <code>c_soundscape.cpp</code> for looping sounds.
{{clarify|Has this been fixed in any pre-CS:GO branches?}}
A possible solution is to create a copy of the first sound and name it differently. This can be a workaround for really short sounds like light hum, but not recommended for others due to the fact that it increase the overall size uselessly. This is the solution that Valve has chosen in ''cs_militia'', in [[Counter-Strike:_Source|Counter-Strike Source]]. In the kitchen, there are two fluorescent lights with hum sounds, but the first one is "<code>ambient/machines/fluorescent_hum_1.wav</code>" and the second one is "<code>ambient/machines/fluorescent_hum_2.wav</code>". Those two sounds are completely identical, but need to be two different name in order to be used in the same soundscape.
Another example is the situation below. We have 3 fluorescent lights and we want hum sounds at their locations. In order to work correctly, soundscape file and Hammer entities should be configured like below.
[[File:Soundscape identicalsounds.jpg|right|325px]]
[[File:Hammer_identicalsounds.jpg|right|325px]]
{{pre|style=display:block|
"soundscape.demovdc"
{
"playlooping"
{
"volume" ".65"
"pitch" "92"
"channel" "CHAN_AUTO"
"position" "0"
"attenuation" "1.2"
"wave" "ambient\machines\fluorescent_hum_1.wav"
}
"playlooping"
{
"volume" ".65"
"pitch" "92"
"channel" "CHAN_AUTO"
"position" "1"
"attenuation" "1.2"
"wave" "ambient\machines\fluorescent_hum_2.wav"
}
"playlooping"
{
"volume" ".65"
"pitch" "92"
"channel" "CHAN_AUTO"
"position" "2"
"attenuation" "1.2"
"wave" "ambient\machines\fluorescent_hum_3.wav"
}
}
}}
Despite the fact that most Source engine branches cannot play more than one identical sound at once, in some situations, it appears that it is possible to play the same sound multiple time at different locations using channels.
After many tests in various situations and source code exploration, it seems to be possible by using different channels. For example, instead of using different names, we use different channels like <code>CHAN_STATIC</code>, <code>CHAN_STREAM</code>, <code>CHAN_AUTO</code>, etc. For an unknown reason at the moment, this won't work every time or for each time the map is loaded.
See [[Soundscript]] for more information.
==Custom Soundscapes==
===Creation===
Soundscape scripts are very similar to [[soundscripts]], but still remain entirely different things.
Soundscapes require a few of their own rules, and are placed in plain text files that are separate from normal soundscript files. A typical soundscape file might be named <code>soundscape_mall.txt</code> and may contain anywhere from 5-30 different soundscapes that take on the following format.
{{bug|hidetested=1|If a soundscape's name is too long, soundscape entities will not be able to trigger it, although it will still be triggerable through console. Character limit unknown.}}
{{pre|
<name>
{
<rule>
{
<keyvalue>
...
}
...
}
}}
===Common keyvalues===
; <code>wave <[[string]]></code>
; <code>wave <[[string]]></code>
: The path and filename of the sound to play, relative to <code>game\sound\</code>.
: The path and filename of the sound to play, relative to <code>game\sound\</code>.{{tip|Despite the name, this KV is used to play any supported audio filetype, not just [[WAV]] files.}}<!--Not explicitly mentioning MP3: while only WAV and MP3 are supported in vanilla first-party titles, third-party games and mods can add other types (ex: Black Mesa adds Ogg Vorbis).}}-->
; <code>volume <[[normal]]></code>
; <code>volume <[[normal]]></code>
: 1 is full power, 0 is silent.
: 1 is full power, 0 is silent.
; <code>pitch <[[integer]]></code>
; <code>pitch <[[integer]]></code>
: Percentage value. +/-30 is the useful range.
: Percentage value. 70-130 is the useful range.
; <code>music <[[boolean]]></code> {{ship|only}}
: The sound is considered "music", and will be affected by the music volume setting. Akin to setting the {{code|<nowiki>#</nowiki>}} [[sound character]], only it is affected by [[DSP]] and is directional.
[[File:Sound_attenuation.jpg|right|200px]]
; <code>position <0-7></code>
; <code>position <0-7></code>
: One of eight locations in the world (defined by the mapper) from which a sound can be emitted.
: One of eight locations in the world (defined by the mapper) from which a sound can be emitted.
; <code>position random</code>
; <code>position random</code>
: As above, but the sound emits from a completely random location near the player.
: As above, but the sound emits from a completely random location near the player.
; <code>origin <origin></code> {{l4d|since}}
: Plays a sound at this origin, for example <tt>"0,0,0"</tt>. The coordinates must be comma-delimited but may contain preceding and following spaces. {{note|Similar to <code>position</code> but the script itself decides where to play this sound. Only useful for soundscapes intended for one single map, because on other maps you won't have any way of changing the location of the sound.}}
; <code>attenuation <[[float]]></code>
; <code>attenuation <[[float]]></code>
: How quickly the sound's volume drops as the camera moves away from it. Only relevant with a <code>position</code> specified. {{todo|What are the rules?}}
: How quickly the sound's volume drops as the camera moves away from it. Only relevant with a <code>position</code> specified. Default value is: "1.00". The lower the value is, greater the radius of the sound will be. And the opposite, higher the value is, smaller the radius of the sound will be. See the image above for illustrated example.
; <code>soundlevel <string></code>
; <code>soundlevel <string></code>
: Can be used instead of <code>attenuation</code>. Accepts [[Soundscripts#SoundLevel|one of the engine's pre-set values]].
: Can be used instead of <code>attenuation</code>. Accepts [[Soundscripts#SoundLevel|one of the engine's pre-set values]].
{{warning|Remember to enclose any values with space characters in "quote marks".}}
{{warning|Remember to enclose any values with space characters in "quote marks".}}
; <code>suppress_on_restore <0 or 1></code>
: Prevents sound from restarting upon loading a saved game.{{tip|It's intended for music played inside soundscape.}}


=== Randomised values ===
===Randomized values===
 
Some rules accept 'upper' and 'lower' parameter values. For example:
Some rules accept 'upper' and 'lower' parameter values. For example:
 
{{pre|
pitch 80,120
"pitch" "80,120"
 
}}
Whenever the rule is executed the value will be randomly selected within the given range.  
Whenever the rule is executed the value will be randomly selected within the given range.  


=== Rules ===
===Rules===
====playlooping====
{{pre|style=float:right;margin-left:1em|
"playlooping"
{
"volume" "0.98"
"pitch" "110"
"soundlevel" "SNDLVL_85dB"


==== playlooping ====
"position" "0"


"wave" "ambient/swamps/water_Lap_loop_st.wav"
}
}}
Plays a sound constantly. Does not allow random values.
Plays a sound constantly. Does not allow random values.


{{note|Sound files will not properly loop unless they have a cue point. See [[Looping a Sound]].}}
{{note|Sound files will not properly loop unless they have a cue point. See [[Looping a Sound]].}}
{{bug|hidetested=1|If another soundscape containing the same "playlooping" sound is triggered, but the sound has a different "pitch" value, the sound will cease to play unless the soundscape is re-triggerred from the one not containing said sound.}}
{{clr}}
====playrandom====
{{pre|style=float:right;margin-left:1em|
"playrandom"
{
        // Play every 1 to 4 seconds
"time" "1,4"


==== playrandom ====
"volume" "0.4,1"
"pitch" "90,105"
"soundlevel" "SNDLVL_85dB"
"position" "0"
"rndwave"
{
"wave" "ambient/wind/wind_med1.wav"
"wave" "ambient/wind/wind_hit1.wav"
}
}
}}


Plays a sound after given number of seconds. Allows random values.
Plays a sound after the given range of the minimum and maximum numbers of seconds specified in the <code>time</code> KV. Allows random values.


Playrandom requires all <code>wave</code> KVs to be inside <code>rndwave</code> (even if there is only one). A random selection will be made every time the rule is executed.
Playrandom requires all <code>wave</code> KVs to be inside <code>rndwave</code> (even if there is only one). A random selection will be made every time the rule is executed.


playrandom
{{warning|Be careful not to specify any looping sounds in a playrandom group as they may not stop even if a different soundscape is activated.}}
{
:{{note|Even non-looping sounds such as mp3s will not stop if a different soundscape is activated. (Tested in {{css}})}}
time 1,4
{{clr}}
volume 0.4,1
pitch 90,105
rndwave
{
wave ambient/wind/wind_med1.wav
wave ambient/wind/wind_hit1.wav
}
}
 
==== playsoundscape ====


====playsoundscape====
{{pre|style=float:right;margin-left:1em|
"SubScape"
{
"playsoundscape"
{
"name" "GenericIndoor"
// Overall sub-scape volume to 50%
"volume" "0.5"
// Emit all positioned sounds from position 0
"positionoverride" "0"
// Emit all ambient sounds from position 1
"ambientpositionoverride" "1"
}
}
}}
Plays a complete soundscape. DSP presets in the 'sub-scape' are ignored.
Plays a complete soundscape. DSP presets in the 'sub-scape' are ignored.


Line 115: Line 241:
: Name of the soundscape to play.
: Name of the soundscape to play.
; <code>position <int></code>
; <code>position <int></code>
: Offsets each position index of the sub-scape. {{todo|What does that mean?}}
: Offsets each position index of the sub-scape.
: For example, if set to 2, then sounds at positions 0, 1, 2, and 3 from the sub-scape would be played at positions 2, 3, 4, and 5 respectively.
; <code>positionoverride <int></code>
; <code>positionoverride <int></code>
: Forces all positioned sounds in the sub-scape to emit from one location.
: Forces all positioned sounds in the sub-scape to emit from one location.
; <code>ambientpositionoverride <int></code>
; <code>ambientpositionoverride <int></code>
: Forces all unpositioned (i.e. ambient) sounds in the sub-scape to emit from one location.
: Forces all unpositioned (i.e. ambient) sounds in the sub-scape to emit from one location.
{{clr}}
====dsp <[[integer]]>====
{{pre|style=float:right;margin-left:1em|
// Disable DSP and play no ambient sounds
"Empty"
{
"dsp" "0"
"dsp_volume" "1.0"
}
//DSP room type with a DSP spatial type
"Empty2"
{
"dsp" "40"
        "dsp_spatial" "119"
"dsp_volume" "1.0"
}
}}
;dsp_spatial <[[integer]]>
;;dsp_volume <[[float]]>
Set the current [[DSP]] preset. {{code|"dsp" "1"}} derives from the [[$surfaceprop]] of nearby [[material]]s.
For a list of values, open <code>scripts\[[dsp_presets|dsp_presets.txt]]</code>. You may need to extract this from the relevant engine VPK with [[GCFScape]]. To preview a DSP preset, submit <code>room_type <[[int]]></code> to the console.
{{note|Be careful when setting presets in soundscapes that could be used in many different locations.}}
{{note|You can also use <code>dsp_volume</code> to define how loud the dsp effect is.}}
{{note|In newer branches of Source (2009+) the cvar for ''room_type'' is ''dsp_room'' with the addition of a spatial dsp preset ''dsp_spatial''.}}
{{note|A dsp spatial type can also be assigned to a soundscape in conjunction with dsp room type ("dsp") with <code>"dsp_spatial" "''n''"</code>}}
{{clr}}
====fadetime <[[float]]>====
{{pre|style=float:right;margin-left:1em|
"SoundScapeName"
{
"fadetime"  "1.0"
"playlooping"
{
// ...
}
}
}}
{{AS|since}}
The amount of time, in seconds, at which a soundscape fades in.
{{note|In games without fadetime such as {{css}} you can partially control it by setting a volume higher than 1 which will increase fadeout time from that soundscape.}}
{{bug|tested={{P2}}|If set to 0 this value will be ignored, and will instead use the value of the <code>soundscape_fadetime</code> [[cvar]]. If that value is also set to 0 it will use a default time of 3 {{confirm}} seconds. A workaround is to set this to a really low value near 0.}}
{{clr}}
====soundmixer <[[string]]>====
{{pre|style=float:right;margin-left:1em|
"quiet"
{
"soundmixer" "Citadel_Dialog_Only"
// ...
}
}}
Selects a custom [[soundmixer]]. Soundmixers manage the priority and volume of groups of sounds; create new ones in <code>scripts\soundmixers.txt</code>  (ALWAYS use Default_Mix as a template).
{{clr}}
===Example===
{{pre|style=display:block|
"swamp.water.slow"
{
"dsp" "1"
"dsp_spatial" "20"
"dsp_volume"  "1.0"
"fadetime"  "1.0"
"soundmixer" "outside_swap_mixer"
"playlooping"
{
"volume" "0.98"
"pitch" "110"
"soundlevel" "SNDLVL_85dB"
"position" "0"
"wave" "ambient/swamps/water_Lap_loop_st.wav"
}
"playrandom"
{
"time" "1,4"
"volume" "0.4,1"
"pitch" "90,105"
"soundlevel" "SNDLVL_85dB"
"origin" "3424.676025, 381.604095, 152.927948"
"rndwave"
{
"wave" "ambient/wind/wind_med1.wav"
"wave" "ambient/wind/wind_hit1.wav"
}
}
}
}}
====Looping MP3 Files====
MP3 files cannot be looped in Source, and are only recommended for non-looping sounds. Nonetheless, it is possible to somewhat simulate looping using {{code|rndwave}} with identical files and set the time to the length of those files:
{{pre|style=display:block|
//////////// Outside bird sounds (loop mp3 sound file trick by gtamike_TSGK) ////////////
//////////// The 2 .mp3 files are the same as each other just not the same file name ////////////
//////////// MP3 Sound file runtime 3.29mins {{=}} 3 X 60 + 29 {{=}} 209secs ////////////
// mp3_loop


SubScape
"mp3_loop"
{  
{
playsoundscape
"dsp" "1"
{  
"playlooping"
name GenericIndoor
{
"volume" "1.0"
// Overall sub-scape volume to 50%
"pitch" "100"
volume 0.5
"soundlevel" "SNDLVL_150dB"
// Emit all positioned sounds from position 0
positionoverride 0
// Emit all ambient sounds from position 1
ambientpositionoverride 1
}
}


==== dsp ====
"wave" "loop_mp3_soundscape/outside_1MB_20KB_part_1.mp3"
}


Overrides the current [[DSP]] preset (which would otherwise be derived from the [[$surfaceprop]] of nearby [[material]]s).
"playrandom"
{
"time" "209"
"volume" "1.0"
"pitch" "100"
"soundlevel" "SNDLVL_150dB"


For a list of values, open <code>scripts\dsp_presets.txt</code>. You may need to extract this from the relevant engine GCF with [[GCFScape]]. To preview a DSP preset, submit <code>room_type <[[int]]></code> to the console.
"rndwave"
{
"wave" "loop_mp3_soundscape/outside_1MB_20KB_part_1.mp3"
"wave" "loop_mp3_soundscape/outside_1MB_20KB_part_2.mp3"
}
}
}
}}


{{note|Be careful when setting presets in soundscapes that could be used in many different locations.}}
{{warning|Mp3 soundscapes might save filesize for custom maps but are not recommended for looping sounds. It can happen that the FIRST file at "rndwave" plays after the half of the time value has passed. In this case you have to double the value (418 in this case, but live with the consequence that there will be a pause after the soundfile has played twice. Consider using an ADPCM-compressed [[WAV]] instead; see [[Compression_(Source_1)#Audio_Compression]].}}
 
== Storing and using custom soundscapes ==


// Disable DSP and play no ambient sounds
The engine uses <code>scripts/soundscapes_manifest.txt</code> to find soundscapes files, but you could also use <code>scripts/soundscapes_%mapname%.txt</code> to load soundscapes on a map-by-map basis. All soundscapes are loaded on map start.
Empty
{{Note|In {{Mapbase|4}}, this method has been changed to <code>maps/%mapname%_soundscapes.txt</code>}}
{  
The <code>soundscapes_%mapname%</code> method should be used when modifying the manifest is unnecessary or impossible (e.g. on custom maps without their own mod directories). This file can be [[BSPZIP|zipped into the BSP itself]] as well.
dsp 0
}


{{todo|What is dsp_volume? Does it actually exist?}}
New soundscapes can be added to the manifest by adding a new "file" line at the bottom, like this:


==== soundmixer ====
{{pre|
"file" "<file location>"
}}


Selects a custom [[soundmixer]]. Soundmixers manage the priority and volume of groups of sounds; create new ones in <code>scripts\soundmixers.txt</code> (ALWAYS use Default_Mix as a template).
{{important|All soundscape names must be globally unique within a game.}}
{{modernConfusion|Although map-specific soundscripts are mounted in a similar way through <code>maps/%mapname%_level_sounds.txt</code>, soundscapes are mounted through the <code>scripts</code> folder and start with <code>soundscapes_</code> instead of starting in the <code>maps</code> folder with <code>%mapname%</code> at the beginning. You can still use both map-specific soundscripts and map-specific soundscapes at the same time.}}


quiet
{
soundmixer Citadel_Dialog_Only
...
}


== See also ==
== Creating Soundscapes using XBLAH's Modding Tool ==
See [[XBLAH's Modding Tool/Docs/Sounds/Soundscape Editor]]


==See also==
* [[env_soundscape]]
* [[env_soundscape]]
* [[env_soundscape_proxy]]
* [[env_soundscape_proxy]]
Line 173: Line 408:
* [[Notepad++ VDF languages]]
* [[Notepad++ VDF languages]]


* [[List of HL2 Soundscapes]]
{{soundscape lists}}
* [[List of EP2 Soundscapes]]
* [[List of CS:S Soundscapes]]
* [[List of DoD:S Soundscapes]]
* [[List of TF2 Soundscapes]]
* [[List of Portal soundscapes]]
* [[List of L4D Soundscapes]]


[[Category:Sound System]]
[[Category:Sound System]]
[[Category:Level Design]]
[[Category:Level Design]]
[[Category:Plain text formats]]
[[Category:Plain text files]]
[[Category:Tutorials]] <!-- due to XBLAH's Modding Tool -->

Latest revision as of 12:08, 31 August 2025

English (en)Español (es)Français (fr)Русский (ru)中文 (zh)Translate (Translate)

A Soundscape is a type of audio script used to add ambience to maps. It can be used in any number of maps, requires only a single entity to implement, and does not generate any network traffic. Soundscapes use a mixture of looped and randomly played sounds, all of which have the option to be emitted from one of eight assignable target locations; DSP and Soundmixer profiles can also be enforced.

Only one soundscape can be active at any given time, and the individual sounds used within it cannot be controlled via inputs. When another soundscape is activated, the game will cross fade from one to the other.

Tip.pngTip:
  • Cross fade time is defined by the cvar soundscape_fadetime, or fadetime in newer branches.
  • Use the cvar soundscape_debug to examine which soundscape is active and why.
Note.pngNote:
  • Soundscapes will not work if the map has not been compiled with VVIS, at least in "-fast" mode.
  • Sound files will not properly loop unless they have a cue point. See Looping a Sound.
  • In most Source engine branches, soundscapes cannot play two of the same sounds, even if the pitch, the volume or the sound level is different. See below for possible solutions.
  • At least one soundscape radius or trigger box should cover the info_player_start or whatever game specific player spawn entities you have, else the players will spawn without loading any soundscape until they trigger a Soundscape.

Soundscapes

Browsing Soundscapes

Soundscapes are typically located in the scripts\ folder of a game, stored across multiple text files prefixed with soundscapes_. Each file is loaded via scripts\soundscapes_manifest.txt, which lists all soundscape scripts that should be mounted by the game. Soundscapes mounted through the manifest can be used anywhere in the game, even if they're only intended for a specific area.

Soundscapes can also be mounted on a per-map basis by naming them

scripts\soundscapes_<mapname>.txt

with <mapname> being the map that they should be loaded on. These soundscapes will be mounted by that map automatically without changing the manifest and can only be used in that map.

Note.pngNote:These files are usually packed away in the original Valve games, but they can be overridden automatically by any unpacked files within that folder.

At the bottom of this article you will find links to lists of soundscapes for individual games, along with attempts at describing them.

You can browse through all the available soundscapes in a current game first hand, using the in-game console command PlaySoundscape. After typing in the first letter as the commands parameter, the auto-complete feature will list them as suggestions. You can then scroll through this list using the arrow keys.

Configuring Soundscapes

Soundscapes can only be configured through these entities:

There are other entities which can activate the soundscape, but these are the only entities which actually define soundscape properties. The other entities will point to these and use them as masters to remotely trigger the soundscape.

Whenever these entities activate a soundscape, any positional audio will originate from the targets defined under their properties.

Tip.pngTip: Many soundscapes define positions for sounds to emanate from, so it is always a good idea to peek into the soundscape entry and get a feel for what you can do. Most entries are found in the text files listed in the <game>/scripts/soundscapes_manifest.txt file. To better understand soundscape entries, see below.

Activating Soundscapes

Any soundscape entity that is enabled and becomes triggered by the player, activates its - or its master's - specified soundscape. Soundscapes remain active until a map change occurs, or another soundscape is activated, even if the entity that originally activated it becomes disabled.

Tip.pngTip:The soundscape_flush console command will cancel an active soundscape.


Soundscape entities

Soundscapes can be activated by any of the following entities:

Soundscape entities are themselves point-based, but trigger when the player enters their specified radius and the entity has a line of sight to them.

The two exceptions to this are env_soundscape_proxy (that is triggered through an env_soundscape or an env_soundscape_triggerable), and env_soundscape_triggerable (that is typically set to also be triggered by a trigger_soundscape).

As only one soundscape can be active at any one time, if one or more soundscape entities are triggered simultaneously, the closest one is given precedence. (The radius of soundscape entities always take precedence over trigger_soundscape brushes.)

Note that a soundscape will not stop playing just because a player exits its radius or it loses line of sight to them.


Tip.pngTip:Use the cvar soundscape_debug to examine which entity is active and why.


Soundscape Placement

At first, a good rule is to place only as many soundscapes as you absolutely need. Try to choose from a similar set of soundscapes to be played, and then pick one that will be your primary soundscape. After that, place your secondary soundscapes at every contrasting location (e.g. house, generator room). Make sure that every location with localized sound effects has its own master soundscape that is tied to the proper targets.

Once you've gotten a general idea of where your soundscapes will be located, you'll then be able to start adding/configuring the entities that will trigger your soundscapes and create a kind of blueprint for how soundscapes will flow from one to another. In many cases, you'll be placing entities that block off all exits from your contrasting locations with triggers to your primary soundscapes. Basically, the goal is to anticipate the player's movement throughout the map, and to block off each area in such a way that it will always have the proper soundscape activated.

After your flow is organized, you'll be able to specialize your soundscapes/triggers to behave in complex ways (e.g responding to game events).

Multiple instances of one sound in one soundscape

Currently, in most Source engine branches, it is impossible to play two or more identical sounds at same time in the same soundscape, even if the volume, the pitch or the sound level is different.

This issue has been remedied (in all games since Counter-Strike: Global Offensive), allowing soundscapes to play multiple instances of identical sounds concurrently. The fix involves using enginesound->GetGuidForLastSoundEmitted() and related functions in c_soundscape.cpp for looping sounds.

Clarify: Has this been fixed in any pre-CS:GO branches?

A possible solution is to create a copy of the first sound and name it differently. This can be a workaround for really short sounds like light hum, but not recommended for others due to the fact that it increase the overall size uselessly. This is the solution that Valve has chosen in cs_militia, in Counter-Strike Source. In the kitchen, there are two fluorescent lights with hum sounds, but the first one is "ambient/machines/fluorescent_hum_1.wav" and the second one is "ambient/machines/fluorescent_hum_2.wav". Those two sounds are completely identical, but need to be two different name in order to be used in the same soundscape.

Another example is the situation below. We have 3 fluorescent lights and we want hum sounds at their locations. In order to work correctly, soundscape file and Hammer entities should be configured like below.

Soundscape identicalsounds.jpg
Hammer identicalsounds.jpg
"soundscape.demovdc"
{
	"playlooping"
	{
		"volume"	".65"
		"pitch"		"92"
		"channel"	"CHAN_AUTO"
		"position"	"0"
		"attenuation"	"1.2"
		"wave"		"ambient\machines\fluorescent_hum_1.wav"
	}
	
	"playlooping"
	{
		"volume"	".65"
		"pitch"		"92"
		"channel"	"CHAN_AUTO"
		"position"	"1"
		"attenuation"	"1.2"
		"wave"		"ambient\machines\fluorescent_hum_2.wav"
	}
	
	"playlooping"
	{
		"volume"	".65"
		"pitch"		"92"
		"channel"	"CHAN_AUTO"
		"position"	"2"
		"attenuation"	"1.2"
		"wave"		"ambient\machines\fluorescent_hum_3.wav"
	}
}

Despite the fact that most Source engine branches cannot play more than one identical sound at once, in some situations, it appears that it is possible to play the same sound multiple time at different locations using channels. After many tests in various situations and source code exploration, it seems to be possible by using different channels. For example, instead of using different names, we use different channels like CHAN_STATIC, CHAN_STREAM, CHAN_AUTO, etc. For an unknown reason at the moment, this won't work every time or for each time the map is loaded. See Soundscript for more information.

Custom Soundscapes

Creation

Soundscape scripts are very similar to soundscripts, but still remain entirely different things.

Soundscapes require a few of their own rules, and are placed in plain text files that are separate from normal soundscript files. A typical soundscape file might be named soundscape_mall.txt and may contain anywhere from 5-30 different soundscapes that take on the following format.

Icon-Bug.pngBug:If a soundscape's name is too long, soundscape entities will not be able to trigger it, although it will still be triggerable through console. Character limit unknown.
<name>
{
	<rule>
	{
		<keyvalue>
		...
	}

	...
}

Common keyvalues

wave <string>
The path and filename of the sound to play, relative to game\sound\.
Tip.pngTip:Despite the name, this KV is used to play any supported audio filetype, not just WAV files.
volume <normal>
1 is full power, 0 is silent.
pitch <integer>
Percentage value. 70-130 is the useful range.
music <boolean> (only in The Ship: Murder Party)
The sound is considered "music", and will be affected by the music volume setting. Akin to setting the # sound character, only it is affected by DSP and is directional.
Sound attenuation.jpg
position <0-7>
One of eight locations in the world (defined by the mapper) from which a sound can be emitted.
position random
As above, but the sound emits from a completely random location near the player.
origin <origin> (in all games since Left 4 Dead)
Plays a sound at this origin, for example "0,0,0". The coordinates must be comma-delimited but may contain preceding and following spaces.
Note.pngNote:Similar to position but the script itself decides where to play this sound. Only useful for soundscapes intended for one single map, because on other maps you won't have any way of changing the location of the sound.
attenuation <float>
How quickly the sound's volume drops as the camera moves away from it. Only relevant with a position specified. Default value is: "1.00". The lower the value is, greater the radius of the sound will be. And the opposite, higher the value is, smaller the radius of the sound will be. See the image above for illustrated example.
soundlevel <string>
Can be used instead of attenuation. Accepts one of the engine's pre-set values.
Warning.pngWarning:Remember to enclose any values with space characters in "quote marks".
suppress_on_restore <0 or 1>
Prevents sound from restarting upon loading a saved game.
Tip.pngTip:It's intended for music played inside soundscape.

Randomized values

Some rules accept 'upper' and 'lower' parameter values. For example:

"pitch"	"80,120"

Whenever the rule is executed the value will be randomly selected within the given range.

Rules

playlooping

"playlooping"
{
	"volume"	"0.98"
	"pitch"		"110"
	"soundlevel"	"SNDLVL_85dB"

	"position"	"0"

	"wave"	"ambient/swamps/water_Lap_loop_st.wav"
}

Plays a sound constantly. Does not allow random values.

Note.pngNote:Sound files will not properly loop unless they have a cue point. See Looping a Sound.
Icon-Bug.pngBug:If another soundscape containing the same "playlooping" sound is triggered, but the sound has a different "pitch" value, the sound will cease to play unless the soundscape is re-triggerred from the one not containing said sound.

playrandom

"playrandom"
{
        // Play every 1 to 4 seconds
	"time"		"1,4"

	"volume"	"0.4,1"
	"pitch"		"90,105"
	"soundlevel"	"SNDLVL_85dB"
	
	"position"	"0"
	
	"rndwave"
	{
		"wave"	"ambient/wind/wind_med1.wav"
		"wave"	"ambient/wind/wind_hit1.wav"
	}
}

Plays a sound after the given range of the minimum and maximum numbers of seconds specified in the time KV. Allows random values.

Playrandom requires all wave KVs to be inside rndwave (even if there is only one). A random selection will be made every time the rule is executed.

Warning.pngWarning:Be careful not to specify any looping sounds in a playrandom group as they may not stop even if a different soundscape is activated.
Note.pngNote:Even non-looping sounds such as mp3s will not stop if a different soundscape is activated. (Tested in Counter-Strike: Source)

playsoundscape

"SubScape"
{
	"playsoundscape"
	{
		"name"	"GenericIndoor"
		
		// Overall sub-scape volume to 50%
		"volume"	"0.5"
		
		// Emit all positioned sounds from position 0
		"positionoverride"	"0"
		
		// Emit all ambient sounds from position 1
		"ambientpositionoverride"	"1"
	}
}

Plays a complete soundscape. DSP presets in the 'sub-scape' are ignored.

name
Name of the soundscape to play.
position <int>
Offsets each position index of the sub-scape.
For example, if set to 2, then sounds at positions 0, 1, 2, and 3 from the sub-scape would be played at positions 2, 3, 4, and 5 respectively.
positionoverride <int>
Forces all positioned sounds in the sub-scape to emit from one location.
ambientpositionoverride <int>
Forces all unpositioned (i.e. ambient) sounds in the sub-scape to emit from one location.

dsp <integer>

// Disable DSP and play no ambient sounds
"Empty"
{
	"dsp"	"0"
	"dsp_volume"	"1.0"
}

//DSP room type with a DSP spatial type
"Empty2"
{ 
	"dsp"	"40"
        "dsp_spatial"	"119"
	"dsp_volume"	"1.0"
}
dsp_spatial <integer>
dsp_volume <float>

Set the current DSP preset. "dsp" "1" derives from the $surfaceprop of nearby materials.

For a list of values, open scripts\dsp_presets.txt. You may need to extract this from the relevant engine VPK with GCFScape. To preview a DSP preset, submit room_type <int> to the console.

Note.pngNote:Be careful when setting presets in soundscapes that could be used in many different locations.
Note.pngNote:You can also use dsp_volume to define how loud the dsp effect is.
Note.pngNote:In newer branches of Source (2009+) the cvar for room_type is dsp_room with the addition of a spatial dsp preset dsp_spatial.
Note.pngNote:A dsp spatial type can also be assigned to a soundscape in conjunction with dsp room type ("dsp") with "dsp_spatial" "n"

fadetime <float>

"SoundScapeName"
{
	"fadetime"  "1.0"
	"playlooping"
	{
		// ...
	}
}

(in all games since Alien Swarm)

The amount of time, in seconds, at which a soundscape fades in.

Note.pngNote:In games without fadetime such as Counter-Strike: Source you can partially control it by setting a volume higher than 1 which will increase fadeout time from that soundscape.
Icon-Bug.pngBug:If set to 0 this value will be ignored, and will instead use the value of the soundscape_fadetime cvar. If that value is also set to 0 it will use a default time of 3 [confirm] seconds. A workaround is to set this to a really low value near 0.  (tested in: Portal 2)

soundmixer <string>

"quiet"
{
	"soundmixer"	"Citadel_Dialog_Only"
	
	// ...
}

Selects a custom soundmixer. Soundmixers manage the priority and volume of groups of sounds; create new ones in scripts\soundmixers.txt (ALWAYS use Default_Mix as a template).

Example

"swamp.water.slow"
{
	"dsp" "1"
	"dsp_spatial" "20"
	"dsp_volume"  "1.0"
	"fadetime"  "1.0"
	"soundmixer" "outside_swap_mixer"
	"playlooping"
	{
		"volume"	"0.98"
		"pitch"		"110"
		"soundlevel"	"SNDLVL_85dB"
		
		"position"	"0"
		
		"wave"	"ambient/swamps/water_Lap_loop_st.wav"
	}
	
	"playrandom"
	{
		"time"		"1,4"
		"volume"	"0.4,1"
		"pitch"		"90,105"
		"soundlevel"	"SNDLVL_85dB"
		"origin"	"3424.676025, 381.604095, 152.927948"
		
		"rndwave"
		{
			"wave"	"ambient/wind/wind_med1.wav"
			"wave"	"ambient/wind/wind_hit1.wav"
		}
	}
}

Looping MP3 Files

MP3 files cannot be looped in Source, and are only recommended for non-looping sounds. Nonetheless, it is possible to somewhat simulate looping using rndwave with identical files and set the time to the length of those files:

//////////// Outside bird sounds (loop mp3 sound file trick by gtamike_TSGK) ////////////
//////////// The 2 .mp3 files are the same as each other just not the same file name ////////////
//////////// MP3 Sound file runtime 3.29mins = 3 X 60 + 29 = 209secs ////////////

// mp3_loop

"mp3_loop"
{
	"dsp" "1"
	"playlooping"
	{
		"volume"	"1.0"
		"pitch"		"100"
		"soundlevel"	"SNDLVL_150dB"

		"wave"	"loop_mp3_soundscape/outside_1MB_20KB_part_1.mp3"
	}

	"playrandom"
	{
		"time"		"209"
		"volume"	"1.0"
		"pitch"		"100"	
		"soundlevel"	"SNDLVL_150dB"

		"rndwave"
		{
			"wave"	"loop_mp3_soundscape/outside_1MB_20KB_part_1.mp3"
			"wave"	"loop_mp3_soundscape/outside_1MB_20KB_part_2.mp3"
		}
	}
} 
Warning.pngWarning:Mp3 soundscapes might save filesize for custom maps but are not recommended for looping sounds. It can happen that the FIRST file at "rndwave" plays after the half of the time value has passed. In this case you have to double the value (418 in this case, but live with the consequence that there will be a pause after the soundfile has played twice. Consider using an ADPCM-compressed WAV instead; see Compression_(Source_1)#Audio_Compression.

Storing and using custom soundscapes

The engine uses scripts/soundscapes_manifest.txt to find soundscapes files, but you could also use scripts/soundscapes_%mapname%.txt to load soundscapes on a map-by-map basis. All soundscapes are loaded on map start.

Note.pngNote:In Mapbase Mapbase, this method has been changed to maps/%mapname%_soundscapes.txt

The soundscapes_%mapname% method should be used when modifying the manifest is unnecessary or impossible (e.g. on custom maps without their own mod directories). This file can be zipped into the BSP itself as well.

New soundscapes can be added to the manifest by adding a new "file" line at the bottom, like this:

	"file"		"<file location>"
Icon-Important.pngImportant:All soundscape names must be globally unique within a game.
Warning.pngRisk of Confusion:Although map-specific soundscripts are mounted in a similar way through maps/%mapname%_level_sounds.txt, soundscapes are mounted through the scripts folder and start with soundscapes_ instead of starting in the maps folder with %mapname% at the beginning. You can still use both map-specific soundscripts and map-specific soundscapes at the same time.


Creating Soundscapes using XBLAH's Modding Tool

See XBLAH's Modding Tool/Docs/Sounds/Soundscape Editor

See also