In PHP I can use the pack function to format a integer value to a 16 bit wav channel chunk. It gets the endianness right and it works. How would one go about creating raw wav data in c?
function cram ($integer, $type = 's', $length = '*')
{
return pack($type.$length, $integer);
}
I'm currently using SDL_mixer and this rough function gets me a playable sawtooth-like sound:
Mix_Chunk *make_wav () {
sample_buffer.allocated = 1;
sample_buffer.alen = 80000;
sample_buffer.volume = 128;
sample_buffer.abuf = malloc(sample_buffer.alen);
int i, up, v, min, max, incr;
up = 1;
v = 1;
min = 0;
max = 30000;
incr = 100;
for (i = 0;i < sample_buffer.alen;i++) {
if (up)
v = v + incr;
else
v = v - incr;
if (v > max) {
up = 0;
v = max;
}
if (v < min) {
up = 1;
v = min;
}
sample_buffer.abuf[i] = v;
printf("%d\n", v);
}
return &sample_buffer;
}
However, as you can see I'm just throwing values into the data buffer and I'm getting property packed stereo wav samples. I can't find information on the Internet for WAV programming in C. Any help would be GREATLY appreciated. I'm lost here.