|
save_wav() is a good idea |
thematrixeatsyou
Member #6,183
September 2005
|
I haven't got source for Allegro 4.2.0 so I can't check if the load_wav() function has been perfected and not just skipping a bunch of bytes. Anyways, someone I know (who codes a lot of Assembler but does a lot of C nowadays) has given me the actual WAV header format. typedef struct WaveFile { char riffhead[4]; // Set this to "RIFF" unsigned long fsm8; // Set this to sample>len + 36 (24h) char wavefmthead[8]; // Set this to "WAVEfmt " unsigned long fmtheaderlen; // Set this to 16 (10h) unsigned short codecused; // Set this to 1 (PCM unencoded format) unsigned short channels; // Set this to sample->stereo + 1 unsigned long samplerate; // Set this to sample->frequency unsigned long byterate; // Set this to samplerate*channels*bits/8 unsigned short blockalign; // Set this to channels*bits/8 unsigned short bits; // Set this to sample->bits char datahead[4]; // Set this to "data" unsigned long datasize; // Set this to sample->len void *data; // Set this to sample->data } WaveFile; As you see, I'm really anal when it comes to signed and unsigned numbers. good food is t3h pwn <-- if anyone can find out how old this sig is they win an ascii penguin |
Thomas Fjellstrom
Member #476
June 2000
|
Why would load_wav need to read data it doesn't use? Though if you want to handle any riff format, give my libriff a shot. It might not handle aiff/iff files correctly, as for some reason the one file I tried stored the offsets and lengths in the wrong endian layout. example:
This is a somewhat useless example, but hey, it shows how to read and write a riff file, so I thought it was better than just showing the others. it provides a "FILE" like interface to the individual chunks in a given riff file, reading, writing, seeking, and you can't seek, read or write past the end or before the start of a chunk, so its a little safe there. Though I have to admit, the riff_file_copy function might need to be renamed, it only coppies the metadata, ie: the structs, and chunk structs, and not the actual data stored in the chunks. -- |
thematrixeatsyou
Member #6,183
September 2005
|
Well most of the players load these values to perform checks.
good food is t3h pwn <-- if anyone can find out how old this sig is they win an ascii penguin |
Ron Novy
Member #6,982
March 2006
|
Don't think allegro really needs to save waves but a simple save_wav might be cool for utilities or debugging. If you're looking for a lib, I've written several libraries that can read/write PCM format wave files and the most recent ('My_Audio' library) can handle all bit depths of PCM .wav (8 to 32 bit integer, float type3, double type3, and the non-standard CoolEdit 16.8) and all integer format .aif files. (can also read and write .mid files) It handles all unsupported chunks in a way that allows them to be saved back to the file and supports a lot of chunks common to the pro-audio scene including the 'smpl' chunk (sampler info), 'cue ' and 'plst' and even the 'bext' chunk (EBU extensions). It's not on the net yet but will be soon. You might want to check out libsndfile too. Libsndfile handles all kinds of audio file formats. ---- |
Elias
Member #358
May 2000
|
The best way would probably be an addon, which would use the save_sample and register_sample_file_type functions. I also should have a very simple function lying around somewhere which can be registered for saving to wav. -- |
GullRaDriel
Member #3,861
September 2003
|
Quote: I also should have a very simple function lying around somewhere So do not let it lying around, Let it be a part of allegro ;-) "Code is like shit - it only smells if it is not yours" |
|