Difference between revisions of "Soundcache"

From Valve Developer Community
Jump to: navigation, search
Line 3: Line 3:
  
 
Each soundcache has an accompanying .manifest, which contains a list of files needed by the map.
 
Each soundcache has an accompanying .manifest, which contains a list of files needed by the map.
 +
 +
==Re-building the .manifest Files==
 +
 +
These instructions apply to MODs trying to generate the best possible .cache files:
 +
 +
1. Create a text file called maplist.txt and place it into your game directory. For example, in the case of Counter-Strike, it would live in the \cstrike directory.
 +
2. Add in all of the map names to maplist.txt. Just add the map name without .bsp on the end of them (e.g. d1_trainstation_01, not d1_trainstation_01.bsp). Seperate each map name with a carriage return.
 +
3. Create a new .bat file and copy in this line:
 +
Steam.exe -applaunch nnn -w 640 -sw -console -condebug -nocrashdialog -makereslists -usereslistfile maplist.txt +mat_picmip 2 +r_lod 3 -autoconfig %1 %2 %3 %4 %5
 +
where nnn is the appropriate steam App Id for the game which you are modding.
 +
4. Save and run the batch file.  Running this process can take a very long time and if the engine crashes at any point then the data will not be valid.  The engine must make it through the entire maplist.txt file cleanly to generate valid .cache files.
 +
 +
This will run the engine and start each map, wait a few seconds for things to settle, and write out a reslist to the \<gamedir>\reslists folder.  These reslists are then used to build the actual sound .cache files.  At exit, after running with the above command line, the engine should rebuild the meta-cache files and all map specific cache files based on the maplist.txt file.
  
 
==Extraction==
 
==Extraction==
Line 9: Line 22:
  
 
==Caches==
 
==Caches==
*<code>_sharedprecache.cache</code>: contains data for sounds common to over 50% of maps.
+
*<code>_sharedprecache.cache</code>: contains data for precached sounds (see the Precaching assets section for info about precaching) common to over 50% of maps (e.g., sounds referenced by the response system which can occor in any map are always precached).
*<code>_other.cache</code>: contains the file header, but no data, for any sound files that were not encountered in any other precache lists. Sounds in this cache do not cause I/O-related hitches as they play back fully asynchronously, that is, only once the sound is completely loaded.
+
*<code>_other.cache</code>: contains the file header, but no preload data, for any sound files that were not encountered in any other precache lists. Sounds in this cache will never cause I/O-related blocking as they play back fully asynchronously, that is, they only begin to mix data to the sound hardware after the sound data has completed asynchronous loading.
*<code><mapname>.cache</code>: Contains the remaining files that are precached but not already a part of <code>_sharedprecache.cache</code>.
+
*<code><mapname>.cache</code>: Contains the remaining files that were Precached by the engine for the specified .bsp, but are not already a part of <code>_sharedprecache.cache</code>.
 
 
==Creation==
 
Sound caches are created automatically if they do not already exist before a map is loaded. A manifest is first written listing every file used, then each cache is created using the rules above, with the first second of each file written to the relavant cache.
 
  
 +
==Console Commands==
 
*<code>snd_writemanifest</code>
 
*<code>snd_writemanifest</code>
:Writes the .manifest file. Buggy.
+
:Writes the .manifest file. Possibly buggy and probably not necessary based on using the above-described command line to automatically rebuild the .cache files.
 
*<code>snd_rebuildaudiocache</code>
 
*<code>snd_rebuildaudiocache</code>
 
:Writes the .cache file, containing soundfile snippets. Appears to have no effect.
 
:Writes the .cache file, containing soundfile snippets. Appears to have no effect.
 +
 
==Limitations & Bugs==
 
==Limitations & Bugs==
There is no known way to manually select the contents of each cache.
+
The contents of the .cache files could be biased by hand-editing the .manifest files and requesting the engine to <code>snd_rebuildaudiocache</code>.  However, this is generally not advised.
  
 
[[Category:Sound System]]
 
[[Category:Sound System]]
 
[[Category:Technical]]
 
[[Category:Technical]]

Revision as of 18:36, 5 December 2005

Outline

A Soundcache is a file with contains the first .125 seconds (125 milliseconds) of each sound required in a map. At level load, the Source engine loads certain sound .cache files instead of the full .wavs themselves in order to save memory and load time. During gameplay when a sound is requested, the sound begins to play immediately (consuming the 125 milliseconds of preload data in the .cache files) while the full sound is asynchronously loaded from the hard drive. In most cases, there is enough data loaded by the time the sound preload data such that the async i/o never needs to "block" to finish loading. If the async layer, however, does need to block, then a noticeable framerate hitch often occurs.

Each soundcache has an accompanying .manifest, which contains a list of files needed by the map.

Re-building the .manifest Files

These instructions apply to MODs trying to generate the best possible .cache files:

1. Create a text file called maplist.txt and place it into your game directory. For example, in the case of Counter-Strike, it would live in the \cstrike directory. 2. Add in all of the map names to maplist.txt. Just add the map name without .bsp on the end of them (e.g. d1_trainstation_01, not d1_trainstation_01.bsp). Seperate each map name with a carriage return. 3. Create a new .bat file and copy in this line: Steam.exe -applaunch nnn -w 640 -sw -console -condebug -nocrashdialog -makereslists -usereslistfile maplist.txt +mat_picmip 2 +r_lod 3 -autoconfig %1 %2 %3 %4 %5 where nnn is the appropriate steam App Id for the game which you are modding. 4. Save and run the batch file. Running this process can take a very long time and if the engine crashes at any point then the data will not be valid. The engine must make it through the entire maplist.txt file cleanly to generate valid .cache files.

This will run the engine and start each map, wait a few seconds for things to settle, and write out a reslist to the \<gamedir>\reslists folder. These reslists are then used to build the actual sound .cache files. At exit, after running with the above command line, the engine should rebuild the meta-cache files and all map specific cache files based on the maplist.txt file.

Extraction

  • .cache files can be viewed with Game Extractor [1]
  • .manifest files can be viewed with any text editor

Caches

  • _sharedprecache.cache: contains data for precached sounds (see the Precaching assets section for info about precaching) common to over 50% of maps (e.g., sounds referenced by the response system which can occor in any map are always precached).
  • _other.cache: contains the file header, but no preload data, for any sound files that were not encountered in any other precache lists. Sounds in this cache will never cause I/O-related blocking as they play back fully asynchronously, that is, they only begin to mix data to the sound hardware after the sound data has completed asynchronous loading.
  • <mapname>.cache: Contains the remaining files that were Precached by the engine for the specified .bsp, but are not already a part of _sharedprecache.cache.

Console Commands

  • snd_writemanifest
Writes the .manifest file. Possibly buggy and probably not necessary based on using the above-described command line to automatically rebuild the .cache files.
  • snd_rebuildaudiocache
Writes the .cache file, containing soundfile snippets. Appears to have no effect.

Limitations & Bugs

The contents of the .cache files could be biased by hand-editing the .manifest files and requesting the engine to snd_rebuildaudiocache. However, this is generally not advised.