|
A RIFF/WAV file is build out of the same basic element every time. It consists of a collection of 'chunks'.
The basic chunk structure:
struct SChunk
{
DWORD dwID; // four character chunk identification.
DWORD dwSize; // size (in bytes) of the data in the chunk.
BYTE aData[dwSize]; // the data of the chunk.
};
At the start of a WAV file there is a chunk which identifies the file, its size and its content. This
chunk encapsulates a number of other chunks.
The top-level encapsulating structure:
struct SRIFFChunk
{
DWORD dwID; // identification "RIFF".
DWORD dwSize; // size of data = 4 + size of all encapsulated chunks.
DWORD dwFormat; // data format identification "WAVE"
};
The encapsulated chunks:
The format chunk specifies the audio format used in the audio data.
struct SFormatChunk
{
// standard chunk data.
DWORD dwID; // identification "fmt ".
DWORD dwSize; // size of data = 16 for PCM (WAVEFORMAT) or
// 18 + wExtraParamsSize for non-PCM (WAVEFORMATEX).
// wave format data.
WORD wAudioFormat; // 0x0001 = PCM, 0x0069 = Deus Ex 2 specific format.
WORD nNumChannels; // number of audio channels (1 = mono, 2 = stereo, etc).
DWORD nSampleRate; // sample rate (samples per second).
DWORD nAvgBytesPerSec; // (average) byte rate (bytes per second).
WORD nBlockAlign; // minimum size of an audio data block (bytes).
WORD nBitsPerSample; // bits per sample.
// optional data (for non-PCM).
WORD wExtraParamsSize; // size (in bytes) of the extra parameters.
BYTE aExtraParams[wExtraParamsSize];
};
The fact chunk only exists for non-PCM formats and provides some additional information about the sound.
Precise format for the fact chunk data is unclear at the moment, but also not important.
struct SFactChunk
{
DWORD dwID; // identification "fact".
DWORD dwSize; // size of data.
BYTE aData[dwSize]; // the fact data.
};
The data chunk contains the actual audio data. :)
struct SDataChunk
{
DWORD dwID; // identification "data".
DWORD dwSize; // size of data.
BYTE aData[dwSize]; // the audio data.
};
Note that other types of chunks are possible, but are not common. Always check the id when reading a chunk...
|