Custom Sounds and Scenes

Avatar
PrejudicedNanobot
39 Posts
Posted Jun 17, 2011
I've been looking into using custom sounds and scenes in a Portal 2 map I'm working on. I've got them to work at a basic level, but I'm wondering how I should include them when I (eventually) distribute the map. I'm also rather unclear on how/where to add new soundscripts.

Just to briefly cover what I've done so far: I made a WAV, put it in portal 2/portal 2/sound, and ran snd_rebuildaudiocache from the console. I then made a simple VCD that uses the sound, saved it in portal 2/portal 2/scenes, and rebuilt scenes.image from Face Poser. I currently have a test map that runs the VCD and it works properly.

However, when I finish the map, how should I distribute it such that the custom content (sounds and VCDs) works properly? From what I've read, using a VPK file is the best option, but will someone who downloads my VPK need to rebuild their sound cache and scenes.image file in order for the custom content to work? Is this done automatically when the update_addon_paths command is run?

Also, regarding soundscripts, I gather I'm supposed to create a text file in portal 2/portal 2/scripts containing something like this:

intercom.hello
{
   channel      CHAN_VOICE
   volume      VOL_NORM
   pitch      PITCH_NORM
   soundlevel   SNDLVL_NORM
   wave      hello.wav
}

However, is it also necessary to modify game_sounds_manifest.txt? The VDC soundscript article seems to imply that this is required in order for new soundscripts to be loaded.

Any input regarding this would be appreciated!

Advertisement
Registered users don’t see ads! Register now!
Avatar
PrejudicedNanobot
39 Posts
Posted Jun 18, 2011
Replied 23 hours later
Sorry about the double post, but I've been doing some further testing and the results are fairly informative (if not particularly helpful at this stage).

A soundscript will be loaded properly if a precache command for it (e.g., "precache_file" "maps/nameoflevel_level_sounds.txt") is added to game_sounds_manifest.txt (located in portal 2/portal 2/scripts for those not familiar with it). Unfortunately, any file named game_sounds_manifest.txt in a VPK file placed in the addons directly (this directory needs to be manually created) overrides the original game_sounds_manifest.txt, so unless it contains all the entries for the original Portal 2 soundscripts in addition to those for custom soundscripts it will cause problems (i.e., Portal 2 will crash when loading a map). Accordingly, this method of using custom soundscripts isn't feasible since it's not extensible.

As of yet, I haven't been able to figure out any alternate, addon VPK-compatible way to load custom soundscripts. In a few places on the VDC wiki (notably here and here), it seems to indicate that soundscripts can also be loaded for a specific map by placing a soundscript txt file called <name of level>_level_sounds.txt in the portal 2/portal 2/maps folder. In particular, the second of the two pages linked above states:

As with any source game, a soundscript found as maps/<mapname>_level_sounds.txt can override official soundscript entries without affecting other campaigns.

However, from the testing I've done, simply placing soundscript entries for a level in a file called nameoflevel_level_sounds.txt does not cause the entries to be loaded (when the map is run or otherwise) unless a corresponding precache command is included in game_sounds_manifest.txt. (I should mention that the actual WAV files can be played in-game without any problems using the console command snd_playsounds, ambient_generic entities, or VCDs; it's just the soundscripts associated with the sounds that aren't being loaded.)

I've also been looking into the soundcache issue as well. Apparently L4D2 has a command called snd_buildsoundcachefordirectory specifically for making caches of only the sounds present in a given directory (see this page), which is useful for distributing caches of custom sounds alone. Unfortunately, Portal 2 doesn't have this function, which seems a bit odd.

I'm going to keep plugging away at this to see if I can find a solution; any suggestions would be appreciated.

Avatar
Kasc
77 Posts
Posted Jun 18, 2011
Replied 1 hour later
I am also planning to include custom sounds in the future, why is it better to control sounds without a soundscript? I've noticed all NPC sounds seem to be run via scripts and won't play within hammer.
Avatar
PrejudicedNanobot
39 Posts
Posted Jun 18, 2011
Replied 1 hour later
Well, I wouldn't say it's better to use sounds without an accompanying soundscript, but it's certainly possible. I'm trying to get soundscripts to work because of their associated benefits (volume control, specifying the origin of a sound, etc.), but currently it seems there's no way to load them without overriding the original copy of game_sounds_manifest.txt (which isn't a good idea since if multiple custom VPKs include copies of game_sounds_manifest.txt only one of them will be used and custom soundscripts for the other VPKs won't load).

As far as I can tell, every sound used in Portal 2 has an associated soundscript that uses it (some of these soundscripts won't play in Hammer because of format issues, but this doesn't affect their usage), so I think it's desirable to use soundscripts for custom sounds as well. It's just a matter of getting them to load from an addon VPK without overriding the precaching of the original soundscripts or other custom soundscripts (e.g., from someone else's addon VPK).

Avatar
Omnicoder
299 Posts
Posted Jun 18, 2011
Replied 21 minutes later
The only way to use custom sounds is to embed the waves in the bsp. And there is simply no way to use custom VCDs.
Avatar
PrejudicedNanobot
39 Posts
Posted Jun 19, 2011
Replied 10 hours later

Omnicoder wrote:
The only way to use custom sounds is to embed the waves in the bsp. And there is simply no way to use custom VCDs.

I've actually got both custom sounds and VCDs to work when they're in a VPK in the addons folder (i.e., they can be used by ambient_generics and logic_choreographed_scene entities in a map). However, I rebuilt scenes.image in Face Poser before moving the VCD into the VPK (which is a potential problem for the distribution of custom VCDs), and unfortunately it's still necessary to rebuild the (entire) audio cache in order for custom sounds to work.

I'll try to put together a simple VPK to demonstrate what I've managed to get working; perhaps it might help illuminate the soundscripts/cache problems as well.

Avatar
Kasc
77 Posts
Posted Jun 19, 2011
Replied 1 hour later
Perhaps what you need to do isn't hard, or perhaps you DON'T need to rebuild to sound cache, but the COLOURS map has a lot of custom sounds.
Avatar
PrejudicedNanobot
39 Posts
Posted Jun 19, 2011
Replied 21 minutes later
I actually downloaded two of the Colours maps yesterday, but I haven't had a chance to take a look them in-game. They appear to use the method Omnicoder mentioned where WAVs are embedded in the BSP itself, which (I assume) does not require the sound cache to be rebuilt. (I should probably test that assumption!)

I'd prefer to use VCDs rather than raw WAVs, as I'm planning on some custom narration with triggers fired at particular times and, although a similar result could probably be accomplished solely within Hammer, using a VCD would be a lot less messy. I've also found that delays in the source engine can sometimes be less than precise (e.g., see here) and I plan to have triggers fired in sync with musical cues and dialogue so even slight variations in trigger timing could make the final result feel a bit off.

However, that said, I may have to forget about VCDs and go with the BSP-embedding method if VPKs require a) the soundcache to be rebuilt and b) scenes.image to be rebuilt (not to mention the issues with soundscripts). It's unfortunate that Portal 2 lacks some of the infrastructure that apparently exists in L4D2 to handle custom content in VPKs.

Avatar
Kasc
77 Posts
Posted Jun 19, 2011
Replied 5 minutes later
Can you still not use scripts to control the sound even if it's embedded into the .bsp? Or am I totally misunderstanding what you're trying to achieve :p
Avatar
Kasc
77 Posts
Posted Jun 19, 2011
Replied 49 minutes later
Do you have to rebuild the sound cache if you include the sounds in the .bsp, all of the guides/tutorials I've looked at give mismatched info, i.e. some say you need to rebuild the sound cache and some just don't even mention that.

In COLOURS there is a .cache file the soundcache folder, are these necessary, and if so - how do you make them?

Avatar
PrejudicedNanobot
39 Posts
Posted Jun 19, 2011
Replied 24 minutes later
I don't know if it's necessary to rebuild the sound cache when the sounds are embedded in a BSP; I'll give it a shot soon and find out.

Kasc wrote:
In COLOURS there is a .cache file the soundcache folder, are these necessary, and if so - how do you make them?

Where is this soundcache folder? Is it inside the Colours BSP? I haven't tried anything relating to Pakrat or embedding resources in BSPs yet, so I don't know how to open these "special" BSPs (assuming it's possible to do so).

Regarding making individual soundcaches, I didn't think it was possible to do this in Portal 2 since it doesn't include the snd_buildsoundcachefordirectory console command (it only has snd_rebuildaudiocache, which rebuilds one sound cache for all the audio files, original and custom). Perhaps Pakrat is able to extract the part of the sound cache that's relevant for a given map.

Also, I've discovered that VCDs in VPKs only work if they're registered in the scenes.image file already, which basically rules out using VCDs in content you eventually want to distribute (since distributing a new copy of scenes.image isn't a realistic option). I suppose I'll focus on including sounds without the user needing to rebuild their sound cache to hear them; since the Colours maps do it, it must be possible.

Avatar
Kasc
77 Posts
Posted Jun 19, 2011
Replied 2 minutes later
I used map analyst and exported the custom data, which creates a zip:

sound -> all his custom sounds used.
materials -> all his custom materials used.
maps -> soundcache -> mp_coop_coulours.cache

Avatar
PrejudicedNanobot
39 Posts
Posted Jun 19, 2011
Replied 2 hours later
Hmm, that's odd; I took a look at one of the Colours BSP files in Pakrat and, although the sound and materials folders were present, I didn't see a soundcache folder.

At any rate, I did a quick test and embedded a WAV in a BSP using Pakrat, and it works fine (at least for me) without building/rebuilding any sound caches. If anyone wants to give it a quick test to check that it works for them, I'd appreciate it (I've attached it below).

It's unfortunate that VCDs only seem to work with a scenes.image file that's modified to include them, but I suppose I'll just have to work around that.

Attachments
test_embedded_sound.bsp
0.22 MB 57 downloads
Avatar
Kasc
77 Posts
Posted Jun 19, 2011
Replied 42 minutes later
it works :smile:
Avatar
PrejudicedNanobot
39 Posts
Posted Jun 19, 2011
Replied 1 hour later
Thanks for testing it, Kasc. Evidently when sounds are embedded in a BSP no sound cache files are required, which certainly beats using VPKs and requiring the user to rebuild their sound cache.
Avatar
Kasc
77 Posts
Posted Jun 20, 2011
Replied 13 hours later
Well if everything is loaded within the .bsp, maybe the sounds are too?
Avatar
AniCator
13 Posts
Posted Jun 20, 2011
Replied 1 hour later
I was very glad when I discovered this command.

snd_updateaudiocache

You can update the cache instead of having to rebuild it entirely.
I've only tested it with raw files though.
If only it was easier to add new soundscripts to your addons and maps.

Avatar
PrejudicedNanobot
39 Posts
Posted Jun 20, 2011
Replied 11 hours later
It appears that, when sounds are embedded in a BSP, any issues relating to the sound cache are handled automatically.

That snd_updateaudiocache command does sound like quite a time-saver when testing sounds in VPKs. I still find it strange, however, that there doesn't appear to be a way to generate a sound cache for only a subset of sounds in Portal 2 while such functionality (according to the VDC wiki) does exist in L4D2. Without this functionality, including sounds in a VPK requires the user to run either snd_rebuildaudiocache or (as AniCator points out) snd_updateaudiocache in order for the sounds to play, which is decidedly inferior to simply embedding them in the BSP, which requires no additional effort on the part of the user.

For now, I'm just going to go with embedding the sounds in the BSP and using triggers, but I hope that the use of soundscripts and VCDs is possible in the future (using VCDs would certainly beat using a trigger possessing a bunch of outputs with different delays that play various sounds).

Avatar
Kasc
77 Posts
Posted Jun 20, 2011
Replied 1 hour later
Why can't you use vscripts to trigger sounds within a map?
Advertisement
Registered users don’t see ads! Register now!
Avatar
PrejudicedNanobot
39 Posts
Posted Jun 21, 2011
Replied 23 hours later
Hmm, I didn't think of that (I've only briefly read about vscripts and haven't used them yet). Is there a good reference for writing vscripts? Information about them and their capabilities on the VDC wiki seems rather sparse. Are they capable of playing sounds and firing triggers ala VCDs?