WAVE file format + decoder (and BMP!)

After I recently got sound working (somewhat) in my platform layer using ALSA, I figured I should actually output something besides the sine wave test pattern.

I remembered that the WAVE file format is basically the set of samples we would want to return, with some additional headers describing the format, so I set out to write a WAVE decoder.

From http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html you can very easily use the Handmade Hero code and Casey's videos to write your own. Memory map a file (like was done for the replay state files), create structs from the file format specification, and use casts with those structs and pointers to get to the sample data, and then return the samples in batches in the GetSoundSamples function (and loop when you get to the end).

If you're interested, my hack job is at:

https://github.com/nxsy/xcb_handmade/blob/master/src/alternate/

* wav.h for the structs
* wav.cpp for loading into memory
* alternate.cpp's GameGetSoundSamples to return the samples to the platform layer

(Yes, I do play a 44100Hz file at 48000Hz. Why do you ask?)

Edited by Neil Blakey-Milner on
And BMP is basically the equivalent to WAVE in the image world - it has some headers, and then a big chunk of stuff in essentially the correct format (will need a little work to get it into exactly the right format if the assets are in a different one).

I used http://dragonwins.com/domains/getteched/bmp/bmpfileformat.htm for the structs, and then inspiration from Casey's DrawRectangle for the drawing parts.

My bmp hack job is at:

https://github.com/nxsy/xcb_handmade/tree/master/src/alternate

* bmp.h is the structs
* bmp.cpp for loading the bmp into memory
* alternate.cpp's draw_bmp() function for drawing