Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Streaming sounds

Streaming sounds

Aardvajk
Aardvajk
Journal of Aardvajk · · 2 min read
465 2
Blimey, ages since I posted here last. I've been quite busy but not really felt like journalling for a while for some reason.

Latest craze has been downloading Psycle and putting together sequences using freeware VSTs so that I can create proper music for my game.

Here's a quick little tune I threw together in a few minutes for experimental purposes. Reminds me a bit of the original Deus Ex theme [smile].

Next step from there was to start to look at streaming long WAV files into short DirectSound buffers. Man alive, trying to get my head around the play and write cursors, and where to actually write the data, and dealing with WAVs that wrap seamlessly at the end nearly made my brain fall out of my ears, but I got there in the end.



This is a little test program that is looping the above track in a 2 second long buffer. The bright red line represents the position of the play cursor and the dark red line is the buffer's write cursor (i.e. the area ahead of the play cursor that has already been committed).

The blue line is the distance between the play cursor's previous and current positions since the last time the buffer was updated. The space between this and the play cursor is the area it is safe to write new buffer data to.

It's a headf*ck because while it is operating like a circular buffer, obviously all the values are just expressed in a linear offset from the start of the buffer so the various cases where the different values wrap around to the start, not to mention the case where a pull from the WAV data wraps around to the start of the track again, complicate things to say the least.

Works pretty seamlessly with a buffer length of 2 seconds and an update rate of around 0.5 seconds.

So now I can stream data into a DS buffer, I can look at either Ogg decoding or maybe a simpler custom compression to try to get the size of the WAV files down in memory.

Discussion

Loading comments...