L4D2 Custom Sound and Music Tutorial: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Such bad grammar. Good night!)
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:L4D2 Custom Sound and Music Tutorial}}
{{DISPLAYTITLE:L4D2 Custom Sound and Music Tutorial}}
{{Note|Due to the "The Passing" Update (April 22, 2010), L4D2 no longer uses _master.cache to cache sound files. There is currently a new soundcache system in place that only reads on disk but not within VPK. Currently, the only custom sounds that will work shipped/packed a VPK are .MP3 files.}}


==Introduction==
==Introduction==
{{l4d2}} Adding custom sound and music in a Left 4 Dead 2 map appears to be more flexible than Left 4 Dead (no random sounds, screeching, sound length requirements, strict sound file specs). The following tutorial will first get in-game sounds to work, followed by customizing existing in-game events/sounds (such as music and sound effects), then finally discusses the issue of sound file updating. The techniques in this tutorial maintains two key advantages:
{{Note|Due to the August 20, 2010 update, L4D2 now official supports custom sound caches packed within the VPK. Instructions provided by Valve are available in the [[L4D2 Campaign Add-on Tutorial#Creating a sound.cache files|L4D2 Campaign Add-on Tutorial article.]]}}
#Convenience for the end-user
#Avoids conflicts with audio of other add-ons, existing audio, and versions of the game in different languages.


{{Warning|Simply packing an updated [[Soundcache|'''maps/soundcache/_master.cache''']] file into a VPK is not an ideal solution and should not be done in any case. It causes conflicts with other add-ons that do the same thing and there are unpredictable consequences that will frustrate or inconvenience end-users. [[Valve]] is aware of the current situation with custom sounds, although there has been no estimated time that a solution will be patched into the game.}}
{{todo|Re-do tutorial to reflect changes to the new soundcache system. This article may no longer be necessary.}}
{{todo|update tutorial when Valve improves support for custom sounds for add-ons}}
 
It is recommended to start with at least the following:
#A map that can be loaded in-game named however you like - '''maps/<map name>.bsp'''
#A blank per-map [[Soundscripts|soundscript]] (a .txt file) named '''maps/<map name>_level_sounds.txt'''
 
==Sound File Requirements==
The following file types and specifications have been known to work:
*.WAV - 16-Bit - 22 Khz and 44 Khz - Mono and Stereo
*.MP3 - 128 Kbps - 22 Khz and 44 Khz - Mono and Stereo
{{note|These specifications may not be universal. There may be differences with ambient, music, loops, etc.}}
{{note|You can test out specifications. These are confirmed to work with custom music and ambient sounds.}}
{{note|[[Looping_a_Sound|Sound loops]] are dependent on .WAV file type}}
{{todo|test out other sound specs}}<br>
{{todo|create table}}<br>
There are a lot of great '''free and trial''' [[Music_Composition|third-party programs for audio conversion]].
 
==Preparing the Files==
First convert the audio file to a file type and specification that you may consider to work (or use the recommended specs). In most cases, it's just copying over audio files or embedding them.
===MP3 Method===
.MP3 sound files will play in-game and '''do not need to be embedded''' to work in-game or when shipping a VPK. There are some issues with .MP3 files since "The Passing" Update. For example, the audio can cut off early. This appears to be the only working method for custom sounds when the entire campaign is shipped as a VPK.
{{note| .MP3 files are a lot smaller than .WAV files, but there is a possibility of performance issues when using such a highly compressed audio format. The lack of looping for .MP3 files can be another disadvantage, as well.}}
 
===Embedded BSP Method===
During development, a custom .WAV file can be played on a test computer without the need to embed it within '''<map name>.bsp'''. This is done by updating the sound cache via console:
<pre>snd_updateaudiocache</pre>
The in-game menu will freeze up temporarily and will eventually output results regarding the sound cache update.
 
Custom .WAV files should be [[BSPZIP|embedded in a BSP]] when shipped as a VPK. The files can be placed anywhere within the BSP, preferably under the '''sound''' folder for the internal path. Third-party tools like [[Pakrat]] currently do not work with L4D2 BSP files.
{{note|Successfully playing a custom .WAV file in-game will update the client '''/maps/soundcache/_master.cache'''. As a result, the sound file embedded in the BSP can be played by any other BSP after such a change. This can potentially save space if multiple BSP files use the same sound files. Although, getting the user to play the sound once and then restarting the client can be inconvenient.}}
Create a list of files you would like to embed '''C:\Program Files\Steam\steamapps\common\left 4 dead 2\bin\<listfile>.txt''':<br><pre>internal_path\file1
external_path\file1
internal_path\file2
external_path\file2
...</pre>
* Internal paths ('relative paths') are the location the file will take within the BSP, e.g. <code>materials/metal/new_steel.vmt</code>.
* External paths ('full paths') are the location of the file to be packed, e.g. <code>C:\Users\Public\our_maps\materials\metal\new_steel.vmt</code>.
{{Note|The internal path should be typed exactly as shown in the example. Use of forward slash ("/") instead of backslash ("\").}}
 
# Copy '''<map name>.bsp''' to '''C:\Program Files\Steam\steamapps\common\left 4 dead 2\bin''' (Windows 32-Bit, default)
# Open the Windows Command Prompt, preferable with administrator privileges.
# Go to bin directory containing bspzip.exe:<br><pre>cd C:\Program Files\Steam\steamapps\common\left 4 dead 2\bin</pre>
# Embed the files with the following commands:<br><pre>bspzip -addlist <bspfile> <listfile> <newbspfile></pre>{{tip|You can quickly select your file in command prompt by typing in the first letters of <map name> and hit <code>TAB</code> to cycle through file names}}
# If BSPZIP is looking for gameinfo.txt try:<br><pre>bspzip -addlist <bspfile> <listfile> <newbspfile> -game "C:\Program Files\Steam\steamapps\common\left 4 dead 2\left4dead2"</pre>
# Optional: You can see if the files have been embedded in the proper internal path by extracting the BSP or viewing the BSP with [[GCFScape]]. Note that this is not a way to check if the internal paths are in correct format (the use of slashes).
 
==Creating the Soundscript==
Open '''<map name>_level_sounds.txt''' with a text editor.
 
===Soundscript Entries===
An [[Soundscripts|entry]] can be played in-game via console or entity, such as ambient_generic or ambient_music. An example entry:
<pre>entry.name
{
channel CHAN_AUTO
volume VOL_NORM
pitch PITCH_NORM
soundlevel SNDLVL_NORM
wave common/null.wav
}</pre>
If a value has a space or tab character within it, wrap it in "quote marks".
=== Examples ===
<pre>Ambience.Siren
{
channel CHAN_WEAPON
volume VOL_NORM
pitch PITCH_NORM
soundlevel SNDLVL_NORM
wave siren1.wav
}</pre>
<pre>Arbitrary.Song
{
channel CHAN_AUTO
volume VOL_NORM
pitch PITCH_NORM
soundlevel SNDLVL_NORM
wave music/singalongsong.wav
}</pre>
<pre>Foo.Song_mp3
{
channel CHAN_STATIC
volume VOL_NORM
pitch 100
soundlevel SNDLVL_NORM
wave music/songalongdong.mp3
}</pre>
 
==Testing In-Game==
===By Console===
#Open '''<map name>.bsp'''<br><pre>map <map name> coop</pre>
#Test out the sound<br><pre>playgamesound entry.name</pre>
#In most cases, if a sound refuses to stop playing, stop the sound<br><pre>stopsound</pre>
 
===By Entities===
#Create an [[Ambient_generic|ambient_generic]], [[Ambient_music|ambient_music]], or any other entity that has a property that requires a sound name{{tip|For ambient_generic, if the sound file is programmed to [[Looping_a_Sound|loop]] (the actual sound file itself), then un-check the flag "is NOT looped" in order to be able to stop the sound from continuously looping with input <code>StopSound</code>. Ambient_music does not have this flag, but it is not necessary.}}
#Change the [[Targetname|targetname]] and change sound name to the soundscript entry of your choice
#Optional: create an entity that will trigger the sound, if necessary or desired
#Open '''<map name>.bsp''' via console<br><pre>map <map name> coop</pre>
#Test out the sound via "trigger entity" or console command:<br><pre>ent_fire <ambient_generic targetname> PlaySound</pre>
#In most cases, if a sound refuses to stop playing, stop the sound via console<br><pre>stopsound</pre>
 
==Soundscapes==
Custom [[soundscapes]] in L4D2 appear to work well without the need to modify the official soundscapes manifest during development or when shipped as a VPK (named as a per-map soundscape).<br><br>
{{todo|thoroughly test vpks with custom per-map soundscapes with other users or computers}}<br><br>
In short, custom soundscapes in L4D2 are text files located in the scripts folder, named "per-map" as '''scripts/soundscapes_<map name>.txt'''<br>
There is nothing different about preparing the sound files in order for the soundscapes to play, although using .MP3 files for soundscapes would be unusual.
==Customizing Existing Sound and Music==
===Official Sound and Music Uses Soundscripts===
All official in-game sound effects, vocalizations, and music rely on soundscripts to tweak the sound to the correct channels, volume, pitch, etc. With '''maps/<map name>_level_sounds.txt''', you can customize those entries without causing conflicts with other addons and the official campaigns. Simply copy the entries you would like to change to the per-map soundscript.
 
Soundscript entries can be found in the '''scripts/game_sounds_*.txt''' folder by opening '''pak01_dir.vpk''' with [[GCFScape]].
 
A lot of music entries rely on '''Map Properties, Post-Fix String''' and [[Nav_Mesh_Attributes_(L4D)|nav mesh attributes]]. For example, the Post-Fix String of the map c5m1_waterfront.bsp is "BigEasy" and it plays its style of intro music in-game, where the nav mesh is marked <code>PLAYER_START</code> and <code>CHECKPOINT</code>.
 
===Interesting Soundscripts===
They're all interesting, but here are a couple of them:
*game_sounds_music.txt provides great sample soundscript entries for music. Some entries string together different notes of the same instrument and are played randomly in succession.
*game_sounds_physics.txt has entries for sounds that play during in-game interactions, such as a walking on snow or shooting a concrete wall.
 
==Updating Your Custom Sounds==
When Valve ever adds or updates any of their sound files, may it be a change in the contents, length, loop position, etc, all they would have to do is include a new soundcache. This is not the case for custom add-ons.
 
The first time a custom sound is played in-game, '''/maps/soundcache/_master.cache''' is updated to include information about the sound file, such as the file location and a small portion of the sound file. Any changes to the sound file requires an update to the sound cache.
 
===During Development===
During development, the sound cache can be updated using a console command:
<pre>snd_updateaudiocache</pre>
The in-game menu will freeze up temporarily and will eventually output results regarding the sound cache update. Your patience will be rewarded!
 
===For Users===
It would be really inconvenient for users to update their sound cache by console command whenever an add-on shipped with updated sound files. One workaround would be changing the filenames and soundscript entries of updated sound files. You can devise a naming scheme that denotes an updated sound file.
{{Warning|Simply packing an updated [[Soundcache|'''maps/soundcache/_master.cache''']] file into a VPK is not an ideal solution and should not be done in any case. It causes conflicts with other add-ons that do the same thing and there are unpredictable consequences that will frustrate or inconvenience end-users. [[Valve]] is aware of the current situation with custom sounds, although there has been no estimated time that a solution will be patched into the game.}}
 
==Troubleshooting==
{{todo|troubleshooting common problems}}


==See also==
==See also==

Revision as of 15:20, 20 August 2010


Introduction

Note.pngNote:Due to the August 20, 2010 update, L4D2 now official supports custom sound caches packed within the VPK. Instructions provided by Valve are available in the L4D2 Campaign Add-on Tutorial article.
Todo: Re-do tutorial to reflect changes to the new soundcache system. This article may no longer be necessary.

See also