Welcome to PlagueFest.com! Log in or Sign up to interact with the Plague Fest community.
  1. Welcome Guest! to interact with the community and gain access to all the site's features.

Optimization: Using 1 entity to store all of your map's custom sounds

Discussion in Resources & Tutorials started by ZombieFurbie, Apr 10, 2013

  1. Feb 19, 2012
    Every ambient_generic used in your map is its own entity. So if your map has like 10 custom wav sound son it, thats like 10 entities right? Wouldn't it be great if you could somehow condense that down to 1 or 2 entities and use those other 8 for more useful things?

    I was on a mission. I had to reduce entity count somehow, and all these custom sounds weren't helping my cause at all. I did some digging, and some experimentation:

    NOTE: I'm creating this thread with the intention of having 1 custom sound play at a time, if you want more than one sound to play at a single time, you will need more entities obviously.

    So I want to add voiceovers and spoken dialogue to a map, right? Meaning I need tons of a soundfiles for those voices. This would mean, in an ordinary scenario, i would need 20 entities to play 20 voices. What the hell! Time to reduce dat shiz.

    I made an ambient_generic and called it "voiceover". Now, when i want to play any of the voices in my map, i do this via I/O:
    You get the idea.
    In-game, it gives me an error that essentially says "Sound must be pre-cached". FUCK.


    According to the source sdk wiki, anything must be precached in order to use. Sounds, Materials, etc. And this precache process happens at mapload. I'm assuming source sdk preloads stuff you put in your map automatically, for instance, if i had blah1.wav as its own ambient_Generic, that gets preloaded automatically.

    Essentially, in order to preload the sound for "addoutput message" to work, I have to have the sound somewhere in the map already. Meaning I need something that calls for that sound, well damn, making entities to preload the sounds would ruin the point of doing this in the first place, right?

    What if there was something you could do where 1 entity would load multiple sounds? Is there something like that?

    As I discovered, the answer is YES!, but the catch is, you can't find it in source sdk. You need a text editor.
    Are you familiar with manifests? Like particle manifests? Well turns out there's a sound manifest too:\
    game_sounds_manifest.txt, you'll find it in the scripts folder in GCFScape.

    What I did, was open up trusty notepad, and typed this: (http://pastebin.com/dTNGn4FZ)
    I saved it as: mymap_sounds.txt, and included it in the manifest, like so:

    Now, create 1 ambient_generic, its a dummy and won't be use at all in the map other than to tell source to precache your sounds, i called mine: precache_sounds.

    and set its soundname (message value) to whatever text is in in the quotes of the sound we created in our custom txt file, in my case, it was Custom.Voices, so i put Custom.Voices in that value. You're done. They will be precached, and using only 2 entities, i was able to save 8 entities to do pretty much the same thing.

    When pakratting your map, make sure to include the manifest, and consider the following from valve developer wiki:
    I hope this tutorial helped you as it's certainly going to help me. It honestly didn't take much experimentation for me to figure it out, i just had to wing it and find something that worked. I just so happened to strike gold.


    I have no idea, I haven't tested it with mp3s yet and that's my next objective. If it works with mp3s, your map's entire soundtrack can be condensed into a couple of entities.

    EDIT: Confirmed: Works with mp3s, just make sure to use the # correctly. (you don't need the #, but if you use it, the manifest has to have the # as well.)

    Did you discover this? HOW LONG HAVE YOU BEEN HOLDING OUT ON US?

    Relax, I discovered it just today on my own after a little experimentation, lol.
    • Informative Informative x 1
    • Useful Useful x 1
      ZombieFurbie, Apr 10, 2013 Last edited by ZombieFurbie, Apr 10, 2013
    • Feb 19, 2012
      Confirmed: Confirmed: Works with mp3s, just make sure to use the # correctly. (you don't need the #, but if you use it, the manifest has to have the # as well.)
      ZombieFurbie, Apr 10, 2013 Last edited by ZombieFurbie, Apr 10, 2013
    • May 14, 2011
      Because were all furious at you for telling us!

      Thanks. A useful trick to know.
    • May 14, 2011
      A command I have been seeing for a while is: snd_rebuildaudiocache

      This may be what you need, never used it, never tried to use it. Just thought I'd let people trying this out know of its existence. :shock:
    • Feb 19, 2012
      Isn't that a client command? Can't use client commands in maps. point_clientcommand does not really work. Even if it wasn't, i wouldn't rely on it since it's not needed.

      Also, it turns out you don't really need 2 seperate entities at all, just 1.
      I made an entity called: jukebox, that plays various mp3 files. It's an ambient_generic. I do volume 0 -> message 'new song' -> playsound -> volume whatever, to change mp3 tracks. It works fine.


      Custom.Music is defined in my textfile, and i can use all of the songs listed in it via simple message switching. So, to reiterate, for mappers looking to optimize, you no longer need more than 1 entity for all of your music needs. This is pretty huge and has tons of possibilties. And as far as i know, there is no limit I know of to the amount of songs you can use, I haven't hit any sort of limit yet in my experimentation, just keep in mind filesize and stuff.

      I use two generics, one for my voiceover wav files, and one for music mp3 files, titled voiceovers and jukebox respectively. I encounter no hitches.

      P.S: Just noticed this might be in the wrong forum, could this be moved to Resources & Tutorials instead? Sorry |D
      • Like Like x 1
      • Feb 19, 2012
        There was a problem where the custom sounds weren't working right with packers. It would fail to precache when packed.

        After researching extensively for a fix, I found one on my own, which caused me to facepalm because the answer was literally under my nose.


        Within the packer, you must remove the 'sound/' from the paths for it to be recognized by the game. Don't ask me why, but it works.

        So you'll have to remove sound/ from each sound you wish to use with this optimization system. Either that, or possibly defining 'sound/' within the _level_sounds.txt itself will work, but I haven't tested that.

        Also, this change also means creating a game_sounds_manifest is completely useless

        The only thing you need to have in your mymap_level_sounds.txt is this:
        You no longer need manifests at this point. Trash it, they're worthless.

        This sound entity optimization system now plays nicely with packers.

        Confirmed the fix with another mapper 'sgt_zuff' and myself. Happy mapping
        • Informative Informative x 2
        • Like Like x 1
        • Wizard! Wizard! x 1
        • Oct 18, 2012
          oh god your back.
          • Friendly Friendly x 2
          • Zing! Zing! x 1
          • Feb 27, 2012
            Oh god you're still here.
            • Funny Funny x 3
            • Jun 11, 2012

              Hey it's Furbie!
              • Friendly Friendly x 1
              • Apr 28, 2013
                This sgt_zuff is actually Zacade for all the ppl wondering but anyway, zacade first asked me if zombiefurbie was online then I had to contact zombiefurbie that zacade need to speak to him about mapping. Anywho, I might do this for my map.
              • May 31, 2012

                One of those things, huh! Thanks for coming around and sharing your experience. Hope to see you in game too!
                • Informative Informative x 1