Soundscape

From Valve Developer Community
Jump to: navigation, search
Русский

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:Cross fade time is defined by the convar soundscape_fadetime.
Tip:Use the convar soundscape_debug 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..
Note:Sound files will not properly loop unless they have a cue point. See Looping a Sound.
Note:Soundscapes cannot play two same sounds, even if the pitch, the volume or the sound level is different. See below for possibles solutions.


Browsing Soundscapes

The soundscapes are typically located in the game abbreviation\scripts\ folder of a game, stored across multiple text files named soundscapes_map name.txt. (They are packed away in the original Valve games, but are automatically overridden on map start by any unpacked files within that folder.)

These files are in turn all listed within the game abbreviation\scripts\soundscapes_manifest.txt file.

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: 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: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 him.

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


Tip:Use the convar 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, 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.

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 is 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 Source cannot play more than one identical sound at once, in some situation, it appear that it is possible to play the same sound multiple time at different location using channels. After many tests in various situations and source code exploration, it seems to be possible by using different channels. For example, instead using differents names, we use different channels like CHAN_STATIC, CHAN_STREAM, CHAN_AUTO, etc. For an unknown reason at the moment, this won't works everytime or at every map loading. See Soundscript for more informations.


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

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

	...
}

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.
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> (New with Portal 2)
Plays a sound at this origin.
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:Remember to enclose any values with space characters in "quote marks".

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

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.
"playlooping"
{
	"volume"	"0.98"
	"pitch"		"110"
	"soundlevel"	"SNDLVL_85dB"

	"position"	"0"

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

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.

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.
"playrandom"
{
	"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"
	}
}

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. To do: 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:Be careful when setting presets in soundscapes that could be used in many different locations.
Note:You can also use dsp_volume to define how loud the dsp effect is.
// Disable DSP and play no ambient sounds 
"Empty"
{ 
	"dsp"	"0"
	"dsp_volume"	"1"
}

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"

	...
}

Example

"swamp.water.slow"
{
	"dsp" "1"

	"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"

		"position"	"1"

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

Looping MP3 Files E.G.

//////////// 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:Mp3 soundscapes might save filesize for custom maps but are not recommended. 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.

Storing and using custom soundscapes

The engine uses the soundscapes_manifest.txt file to find all its soundscapes files.

It will look for this manifest (and typically the soundscapes as well) in the scripts\ folder on map start. Where this folder (and the root of custom soundscapes) is located, depends on whether the game is a modification (created through Create a Mod), or an original Valve game:

  • If it's a modification, the engine will look for it in the root folder of the mod.
  • If it's an original Valve game, the engine will instead look for it in the games game abbreviation\ folder. (For example, in the case of Half-Life 2: Episode 1 the engine will look for the manifest in the Steam\SteamApps\user\half-life 2 episode one\episodic\scripts\ folder.) In this case the scripts\ folder has to be created manually, and any custom soundscapes_manifest.txt found there, will override the original file.

To list a new soundscape in the manifest, simply add the line

"file" "location and file name"

within the curly brackets.

Typically the location and file name will be "scripts/soundscapes_custom map name.txt".

Note:All soundscape names must be globally unique within a game.
Tip:If you want to add custom soundscapes to your map, and you haven't already, you should consider creating a full modification (through the Create a Mod option found in the Source SDK menu. This will prevent your custom manifest from overriding any soundscape updates made to the original game.


See also