• entries
743
1924
• views
579170

# Sound buffer improvements

78 views

Previously, I had a command line program that would take a bunch of .WAV files, convert them into DirectSound buffers of a specific frequency and bitrate and so on, then dump them all into one file, called a .sfx file.

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:

"boing" boing.wav"ding"  bell.wavsave "\projects\udo\resource\effects.dsb"

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 that records the index of each named buffer in the vector.

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.

There are no comments to display.

## Create an account

Register a new account