Soundscape: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Robot: fixing template case.)
(redone)
Line 1: Line 1:
[[Category:Sound System]]
{{toc-right}}
'''Soundscapes''' are definitions of sounds to be played within the Source engine. These soundscapes include settings for various [[DSP]] effects (effects such as echo that reflect the environment) as well as commands for controlling sound playback (randomizing, looping etc background noise, for a more complex sound environment than can be provided by [[ambient_generic]]). The sound system will play one soundscape at a time and crossfade between soundscapes as they are changed. There is some flexibility here that will be explained later in the document. The entity <code>[[env_soundscape]]</code> can be used to set a player's soundscape if he moves within its radius and it has line of sight to the player. Only one [[env_soundscape]] can be active per player at any one time. The <code>env_soundscape</code> refers to individual soundscapes that are defined in the <code>soundscapes.txt</code> script file, or in a custom, map-specific file.


* {{HL2}} [[List of HL2 Soundscapes]]
'''Soundscapes''' are audio scripts that contain instructions for creating background ambience in a map. Sound clips can be looped or played randomly, and can be emitted globally or from specific locations. A soundscape can also specify [[DSP]] and [[Soundmixer]] profiles.
* {{CSS}} [[List of CS:S Soundscapes]]
* {{DODS}} [[List of DoD:S Soundscapes]]
* [[Image:Tf2-16px.png]] [[List of TF2 Soundscapes]]
* [[Image:Portal logo.jpg|15px]] [[List of Portal soundscapes|List of Portal Soundscapes]]


=Using the env_soundscape Entity=
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 can be playing at any given time.


To control soundscapes in a game map, we use the <code>env_soundscape</code> entity. Each entity has a ''radius'' and ''soundscape'' field. The ''soundscape'' field is the name of a soundscape to play when activated, as defined in <code>soundscapes.txt</code>. The radius describes a sphere around the entity that a player must be within to be considered for activating the soundscape. The player must also be visible to the soundscape entity (not occluded by walls or other obstructions). Once a player has triggered a soundscape, that soundscape will remain active until a new one is activated by the player. This means that even if a player leaves a soundscape's radius after having activated it, the soundscape will continue to play. Only one soundscape may play at any one time. If a new soundscape is activated, the currently playing soundscape will fade out while the new one fades in.
Soundscapes will crossfade between each other over a default of three seconds. Configure this from the console with <code>soundscape_fadetime</code>.


The entity also has eight entity references slots available for use. These correspond to the position values declared in the soundscape. These may point to any valid entity, and will use that entity's ''position'' as a reference point for sound spatialization.
== Implementing ==


=Creating and Editing soundscapes.txt Entries=
=== env_soundscape ===


<code>Soundscapes.txt</code> is a simple key/value pair file with the same format as .[[VMT]] or .[[VMF]]:
Soundscapes are generally implemented with [[env_soundscape]]. Its keyvalues, inputs etc. should be self-explanatory.


<pre>
The active env_soundscape is the one that the player:
"example"
{
  "key1" "value1"
  "key2" "value2"
  "subexample"
  {
          "key3" "value3"
  }
  "key4" "value4"
}


// Comment text, not parsed
# Has direct line of sight to
"example2"        // This is a comment as well
# Is in range of
{
# Is closest to (in case of a tie)
}
</pre>


Each root-level section (a section that is not within another section) is considered to be a definition of a soundscape. The name given to this soundscape is referenced by the <code>env_soundscape</code> entity.
When an env_soundscape ceases to be active, the soundscape it began persists until another one is begun or the map changes.


=Adding custom soundscapes=
{{tip|Use the [[convar]] <code>soundscape_debug</code> examine which entity is active and why.}}


==Adding soundscapes to a mod==
=== trigger_soundscape ===


The soundscapes which are loaded are defined in <code><game directory>\scripts\soundscapes_manifest.txt</code>. Add the name of your custom soundscape(s).
The other method is [[trigger_soundscape]]. The associated [[env_soundscape_triggerable]] will be played when the player is inside the trigger volume.


Place your soundscape(s) in <code><game directory>\scripts\''my_custom_soundscape''.txt</code>.
{{note|Unlike env_soundscape, trigger_soundscape's soundscapes do not persist once the player leaves its influence.}}


==Adding a soundscape to a map==
=== Finding a soundscape ===


If you are third-party mapping for a game or modification and therefore can not change the original <code>soundscapes_manifest.txt</code>, you can give your soundscape the same name as your map and it will be loaded with this map.
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.


For example, with a Counter-Strike: Source map called my_custom_map.bsp:
== Creating ==


<code><game directory>\scripts\soundscapes_my_custom_map.txt</code>
=== Example ===


=Commands=
Soundscapes work like this:


==dsp==
<name>
{
<rule>
{
<keyvalue>
...
}
...
}


Sets the DSP effect to a particular room number. In general this should be set to 1, which is the “automatic” DSP. With this DSP the sound engine will attempt to discover the proper parameters based on the surrounding geometry. Setting the DSP to 0 will result in effectively turning DSP effects off. Using other pre-sets are only recommended for special cases. These pre-sets are declared in the <code>../hl2/scripts/dsp_preset.txt</code> file.
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.}}


Example
=== Common keyvalues ===
<pre>
    // This soundscape disables DSP and plays no sounds
        "Nothing"
        {
              "dsp"  "0"
        }
</pre>


==playlooping==
; <code>wave <[[string]]></code>
: The path and filename of the sound to play, relative to <code>game\sound\</code>.
; <code>volume <[[normal]]></code>
: 1 is full power, 0 is silent.
; <code>pitch <[[integer]]></code>
: Percentage value. +/-30 is the useful range.
; <code>position <0-7></code>
: One of eight locations in the world (defined by the mapper) from which a sound can be emitted.
; <code>position random</code>
: As above, but the sound emits from a completely random location near the player.
; <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?}}
; <code>soundlevel <string></code>
: Can be used instead of <code>attenuation</code>. Accepts [[Soundscripts#SoundLevel|one of the engine's pre-set values]].


Plays a looping sound until a new soundscape is triggered.
{{warning|Remember to enclose any values with space characters in "quote marks".}}


<code>wave</code>
=== Randomised values ===
* The name of the wave file.


<code>volume</code>
Some rules accept 'upper' and 'lower' parameter values. For example:
* Sets the wave's volume (0-1).


<code>pitch</code>
pitch 80,120
* Sets the pitch for the wave (100 is normal).


<code>attenuation</code>
Whenever the rule is executed the value will be randomly selected within the given range.  
* Sets the attenuation of the wave (only used if a "position" command follows).
** {{note|These can be random intervals - the random value will be chosen once each time the soundscape is triggered.}}


<code>position</code>
=== Rules ===
* References a position by index (0-7) that the level designer has pointed to in the <code>env_soundscape</code> entity.


Example
==== playlooping ====
<pre>
    // This plays a single looping sound, with a generic reverb (room type 1)
    "GenericIndoor"
    {
        "dsp"  "1"
        "playlooping"
        {
                "volume"      "1"
                "pitch"        "100"
                "wave"        "ambient/areas/air_exchange/indoor2.wav"
        }
    }
</pre>


{{note|In order to use the function of playlooping you need to set make sure your wavfile has cues so that the [[Source]] engine knows where to loop the sound. To find out one way of doing this then read the following article..also note this article is for [[Goldsource]] and you can now use higher sample rates, for example 44100hz.}} [http://collective.valve-erc.com/index.php?doc=1070392493-12550200]
Plays a sound constantly. Does not allow random values.


==playrandom==
{{note|Sound files will not properly loop unless they have a cue point. See [[Looping a Sound]].}}


Plays random sound events until a new soundscape is triggered.
==== playrandom ====


<code>time</code>
Plays a sound after given number of seconds. Allows random values.
* Time interval of the random event.


<code>volume</code>
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.
* Random volume interval (0-1).


<code>pitch</code>
playrandom
* Random pitch interval (50-250).
{
time 1,4
volume 0.4,1
pitch 90,105
rndwave
{
wave ambient/wind/wind_med1.wav
wave ambient/wind/wind_hit1.wav
}
}


<code>attenuation</code>
==== playsoundscape ====
* Random attenuation of sound.


<code>rndwave</code>
Plays a complete soundscape. DSP presets in the 'sub-scape' are ignored.
* A list of random wave files to choose from.


<code>position</code>
; <code>name</code>
* Position to use, if spatialized (0-7), or "random" for a random position.
: Name of the soundscape to play.
; <code>position <int></code>
: Offsets each position index of the sub-scape. {{todo|What does that mean?}}
; <code>positionoverride <int></code>
: Forces all positioned sounds in the sub-scape to emit from one location.
; <code>ambientpositionoverride <int></code>
: Forces all unpositioned (i.e. ambient) sounds in the sub-scape to emit from one location.


Example
SubScape
<pre>
{  
    "GenericOutdoor"
playsoundscape
   
{  
    {  
name GenericIndoor
        "dsp"  "1"
       
// Overall sub-scape volume to 50%
        "playrandom"
volume 0.5
        {  
            // Play every 0.1 to 1.5 seconds
// Emit all positioned sounds from position 0
            "time" "0.1, 1.5"
positionoverride 0
           
            // At a volume of 0.5 to 1
// Emit all ambient sounds from position 1
            "volume" "0.5,1"
ambientpositionoverride 1
           
}  
            // At a pitch of 50% to 120%
}
            "pitch" "50,120"
           
            // With an attenuation of 0.7
            "attenuation" "0.7"
           
            // At entity specified at position 1  
            "position"  "1"
           
            // Play one of these .wav files randomly each time
            "rndwave"
            {
                "wave" "temp/soundscape_test/music_snippet1.wav"
                "wave" "temp/soundscape_test/music_snippet2.wav"
                "wave" "temp/soundscape_test/music_snippet3.wav"
            }  
        }
    }


</pre>
==== dsp ====


==playsoundscape==
Overrides the current [[DSP]] preset (which would otherwise be derived from the [[$surfaceprop]] of nearby [[material]]s).


Plays another soundscape and all of its sub-commands.
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.


{{note|DSP effects cannot be altered by sub-soundscapes.}}
{{note|Be careful when setting presets in soundscapes that could be used in many different locations.}}


<code>name</code>
// Disable DSP and play no ambient sounds
* Sub-soundscape to play.
Empty
{
dsp 0
}


<code>volume</code>
{{todo|What is dsp_volume? Does it actually exist?}}
* All volumes in the sub-soundscape are scaled by this value (0-1).


<code>position</code>
==== soundmixer ====
* An offset added to each position index of the sub-soundscape (0-7).


<code>positionoverride</code>
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).
* Forces all sub-soundscape positional sounds to occur at a single position originating from the entity at this index (0-7).


<code>ambientpositionoverride</code>
quiet
* Forces all sub-soundscape ambient sounds to be spatialized at a particular position originating from the entity at this index. Useful to make ambient sounds come “from a direction" (0-7).
{
soundmixer Citadel_Dialog_Only
...
}


Example
== See also ==
<pre>
    "SubSoundscape"
    {
        "dsp"  "1"
       
        "playsoundscape"
        {
            // Sub-soundscape to play
            "name" "GenericIndoor"
           
            // All sub-soundscape volumes reduced by 50%
            "volume" "0.5"
           
            // All sub-soundscape position sounds will come from this point
            "positionoverride" "0"
           
            // All sub-soundscape ambient sounds will come from this point
            "ambientpositionoverride" "1"
        }
    }
</pre>


==soundmixer==
* [[env_soundscape]]
* [[env_soundscape_proxy]]
* [[env_soundscape_triggerable]]
* [[trigger_soundscape]]
* [[Notepad++ VDF languages]]


Sound mixers are used to provide custom volume control over various sound categories, called mix groups. Sound mixers are referenced in Soundscapes via "SOUNDMIXER" "name".
* [[List of HL2 Soundscapes]]
 
Example
<pre>
"automatic"
{
"dsp" "1"
"dsp_volume" "1.0"
"SOUNDMIXER" "Default_Mix"
}
</pre>
 
'''Always''' use Default_Mix as a template.
 
<pre>
"Default_Mix"
{
// group name mix value
// ---------- ---------
"Explosions" "0.90"
"Player_Weapons_Loud" "1.0"
"Player_Suit" "0.56"
"Weapons" "0.79"
"AHELI_WEAPON" "0.85"
"GUNSHIP_WEAPON" "0.85"
"STRIDER_WEAPON" "0.85"
"bullethit" "0.67"
"Music" "0.81"
"All" "0.72"
}
</pre>
 
=References=
 
* <code>/scripts/soundmixers.txt</code> from create a mod, source sdk
* <code>/scripts/soundscapes.txt</code> from create a mod, source sdk
 
=See also=
* [[env_soundscape]]
*[[env_soundscape_proxy]] Point entity that acts like a soundscape but gets all of its sound parameters from another [[env_soundscape]] entity.
*[[env_soundscape_triggerable]] Point entity just like [[env_soundscape]] except that it works in conjunction with the [[trigger_soundscape]] entity to determine when a player hears it.
*[[trigger_soundscape]] Brush-based soundscape trigger. Does not need outputs, as it automatically triggers the soundscape specified by its Soundscape property.
* [[List of CS:S Soundscapes]]
* [[List of CS:S Soundscapes]]
* [[List of DoD:S Soundscapes]]
* [[List of DoD:S Soundscapes]]
* [[List of HL2 Soundscapes]]
* [[List of TF2 Soundscapes]]
* [[List of Portal soundscapes]]
 
[[Category:Sound System]]
[[Category:Level Design]]

Revision as of 13:07, 10 April 2009

Soundscapes are audio scripts that contain instructions for creating background ambience in a map. Sound clips can be looped or played randomly, and can be emitted globally or from specific locations. A soundscape can also specify DSP and Soundmixer profiles.

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 can be playing at any given time.

Soundscapes will crossfade between each other over a default of three seconds. Configure this from the console with soundscape_fadetime.

Implementing

env_soundscape

Soundscapes are generally implemented with env_soundscape. Its keyvalues, inputs etc. should be self-explanatory.

The active env_soundscape is the one that the player:

  1. Has direct line of sight to
  2. Is in range of
  3. 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.

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

trigger_soundscape

The other method is trigger_soundscape. The associated env_soundscape_triggerable will be played when the player is inside the trigger volume.

Note.pngNote:Unlike env_soundscape, trigger_soundscape's soundscapes do not persist once the player leaves its influence.

Finding a soundscape

Hammer doesn't list available soundscapes. The best way of finding one is loading up a map and using the concommand playsoundscape (which does know what's available and will autocomplete while you type) to start one up.

Creating

Example

Soundscapes work like this:

<name>
{
	<rule>
	{
		<keyvalue>
		...
	}

	...
}

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

Tip.pngTip:Mappers can create scripts\soundscapes_<map name no extension>.txt to use new soundscapes without modifying the manifest.

Common keyvalues

wave <string>
The path and filename of the sound to play, relative to game\sound\.
volume <normal>
1 is full power, 0 is silent.
pitch <integer>
Percentage value. +/-30 is the useful range.
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.
attenuation <float>
How quickly the sound's volume drops as the camera moves away from it. Only relevant with a position specified.
Todo: What are the rules?
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".

Randomised 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

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.

playrandom

Plays a sound after given number of seconds. 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.

playrandom
{
	time	1,4
	volume	0.4,1
	pitch	90,105

	rndwave
	{
		wave	ambient/wind/wind_med1.wav
		wave	ambient/wind/wind_hit1.wav
	}
}

playsoundscape

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.
Todo: What does that mean?
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.
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
	} 
}

dsp

Overrides the current DSP preset (which would otherwise be derived 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 GCF 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.
// Disable DSP and play no ambient sounds 
Empty
{ 
	dsp	0
}
Todo: What is dsp_volume? Does it actually exist?

soundmixer

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

quiet
{
	soundmixer	Citadel_Dialog_Only

	...
}

See also