To implement support for a sound format, functions are needed to:
- Get info about the file AND load the file into memory. This should only require opening the file once to reduce load times
- Convert part or all of the file into PCM format.
I'd prefer not to use something that requires a DLL, and is portable.
If I have those three functions for a given filetype it *should* be possible to add support for it.A couple examples from the FS2 code's ACM converter code...note that all are run after the file to convert has been loaded into memory.
MusicThese three functions are used to convert ADPCM music files. stream_open opens a stream, getting everything ready to convert the file.
convert converts part of the data into PCM format.
stream_close closes the stream, cleaning everything up.
//Get ready to convert
int ACM_stream_open(WAVEFORMATEX *pwfxSrc, WAVEFORMATEX *pwfxDest, void **stream, int dest_bps)
//While we have music playing, convert part of it...boy, if only this did OGG too.
int ACM_convert(void *stream, ubyte *src, int src_len, ubyte *dest, int max_dest_bytes, unsigned int *dest_len, unsigned int *src_bytes_used)
//We're done!
int ACM_stream_close(void *stream)
Sound FX and maybe voiceThis function converts an entire ADPCM file into PCM format, which is later loaded into a DirectSound buffer.
// =============================================================================
// ACM_convert_ADPCM_to_PCM()
//
// Convert an ADPCM wave file to a PCM wave file using the Audio Compression Manager
//
// parameters: *pwfxSrc => address of WAVEFORMATEX structure describing the source wave
// *src => pointer to raw source wave data
// src_len => num bytes of source wave data
// **dest => pointer to pointer to dest buffer for wave data
// (mem is allocated in this function if *dest is NULL)
// max_dest_bytes => Maximum memory allocated to dest
// *dest_len => returns num bytes of wave data in converted form (OUTPUT PARAMETER)
// *src_bytes_used => returns num bytes of src actually used in the conversion
// dest_bps => bits per sample that data should be uncompressed to
//
// returns: 0 => success
// -1 => could not convert wav file
//
//
// NOTES:
// 1. Storage for the decompressed audio will be allocated in this function if *dest in NULL.
// The caller is responsible for freeing this memory later.
//
int ACM_convert_ADPCM_to_PCM(WAVEFORMATEX *pwfxSrc, ubyte *src, int src_len, ubyte **dest, int max_dest_bytes, int *dest_len, unsigned int *src_bytes_used, unsigned short dest_bps)