My game then loaded a single .sfx file into multiple CSoundBuffers (from my DirectSound wrapper). All good.
I got a bit fed up though since I had to specify indicies into a vector of CSoundBuffers to play sounds, which was a bit rubbish.
So I've just invented .dsb (DirectSound Buffer) format files that tag each buffer data in the file with a string name, specified via the command line DSB utility. You create a little script like:
and compile it with DSB.EXE.
My sound wrapper now loads DSB as well as SFX files. When you use the LoadDSBFile() method, you also pass in a std::map
It is then pretty trivial in the game to write a function that takes a string argument, searches the map for the string as a key, then plays the appropriate sound buffer if it exists.
And to add a new sound, I just add it to the dsb script, compile the script and then specify the string anywhere in the game code, without having to recompile anything else or worry about remembering which index is which, or accidentally specify an index that causes an out of range index in the CSoundBuffer vector.
I know that this is not optimally efficient, but I'm relying on std::map to implement some kind of intelligent internal structure and as long as there are not thousands of elements, I can't see it ever causing a significant bottleneck.
It is dead flexible though, so I'm quite pleased.