I. Summary
As one of the acoustic file formats used in multimedia, the wave file is in the riff format as the standard.
Riff is the abbreviation of resource interchange file format. The first four
The byte is "riff ".
A wave file is composed of several chunks. According to the location where the file appears, including: Riff Wave
Chunk, format chunk, fact chunk (optional), data chunk. For details, see:
------------------------------------------------
| Riff wave chunk |
| Id = 'riff' |
| Rifftype = 'wave '|
------------------------------------------------
| Format chunk |
| Id = 'fmt' |
------------------------------------------------
| Fact chunk (optional) |
| Id = 'fact' |
------------------------------------------------
| Data chunk |
| Id = 'data' |
------------------------------------------------
Figure 1 example of chunk in WAV format
Three other chunks except fact chunk are required. Each chunk has its own ID, bit
At the beginning of the chunk, which is used as an identifier and is 4 bytes long. And Chunk is next to the ID.
Small (the remaining number of other bytes after removing the number of bytes occupied by ID and size), 4 bytes, low bytes
Indicates the low value, and the high byte indicates the high value. The following describes the content of each chunk.
PS:
All values indicate low bytes, and high bytes indicate high.
Ii. Details
Riff wave chunk
========================================
| Bytes | specific content |
========================================
| ID | 4 bytes | 'riff' |
----------------------------------
| Size | 4 bytes |
----------------------------------
| Type | 4 bytes | 'wave '|
----------------------------------
Figure 2 riff wave chunk
Use '0000f' as the marker, followed by the size field. The size is the size of the entire WAV file minus the ID.
And the number of bytes occupied by size, that is, filelen-8 = size. Then the type field, which is 'wave ', table
Shows a WAV file.
The structure is defined as follows:
Struct riff_header
{
Char szriffid [4]; // 'R', 'I', 'F', 'F'
DWORD dwriffsize;
Char szriffformat [4]; // 'w', 'A', 'V', 'E'
};
Format chunk
========================================================== ======================================
| Number of bytes | specific content |
========================================================== ======================================
| ID | 4 bytes | 'fmt' |
--------------------------------------------------------------------
| Size | 4 bytes | if the value is 16 or 18, the last information is appended. |
------------------------------------------------------------------------
| Formattag | 2 bytes | encoding method, generally 0x0001 |
-------------------------------------------------------------------- |
| Channels | 2 bytes | Number of audio channels; values: 1 (Single Channel) and 2 (dual channel) |
-------------------------------------------------------------------- |
| Samplespersec | 4 bytes | sampling frequency |
-------------------------------------------------------------------- |
| Avgbytespersec | 4 bytes | number of required bytes per second ||==> wave_format
-------------------------------------------------------------------- |
| Blockalign | 2 bytes | data block alignment unit (the number of bytes required for each sample) |
-------------------------------------------------------------------- |
| Bitspersample | 2 bytes | Number of BITs required for each sample |
-------------------------------------------------------------------- |
| 2 bytes | additional information (optional, which can be determined by size) |
------------------------------------------------------------------------
Figure 3 Format chunk
Use 'fmt' as the flag. Generally, the size is 16, and the last additional information does not exist. If the size is 18
Then, two additional bytes are added. These two bytes are contained in the WAV format made mainly by some software.
Additional information.
The structure is defined as follows:
Struct wave_format
{
Word wformattag;
Word wchannels;
DWORD dwsamplespersec;
DWORD dwavgbytespersec;
Word wblockalign;
Word wbitspersample;
};
Struct fmt_block
{
Char szfmtid [4]; // 'F', 'M','t ',''
DWORD dwfmtsize;
Wave_format wavformat;
};
Fact chunk
========================================
| Bytes | specific content |
========================================
| ID | 4 bytes | 'fact' |
----------------------------------
| Size | 4 bytes | the value is 4. |
----------------------------------
| Data | 4 bytes |
----------------------------------
Figure 4 fact chunk
Fact Chunk is an optional field. Generally, when a WAV file is converted from some software, it contains the chunk.
The structure is defined as follows:
Struct fact_block
{
Char szfactid [4]; // 'F', 'A', 'C', 'T'
DWORD dwfactsize;
};
Data chunk
========================================
| Bytes | specific content |
========================================
| ID | 4 bytes | 'data' |
----------------------------------
| Size | 4 bytes |
----------------------------------
| Data |
----------------------------------
Figure 5 Data chunk
The data Chunk is the place where the wav data is actually stored. 'data' is used as the chunk identifier. Then
Data size. Followed by WAV data. Based on the number of channels in the format Chunk and the number of sampling bits,
The bit location of Wav data can be divided into the following forms:
---------------------------------------------------------------------
| Mono | sampling 1 | sampling 2 | sampling 3 | sampling 4 |
| --------------------------------------------------------
| 8-bit quantization | channel 0 | channel 0 | channel 0 | channel 0 |
---------------------------------------------------------------------
| Dual-channel | sampling 1 | sampling 2 |
| --------------------------------------------------------
| 8-bit quantization | channel 0 (left) | channel 1 (right) | channel 0 (left) | channel 1 (right) |
---------------------------------------------------------------------
| Sampling 1 | sampling 2 |
| Single channel | --------------------------------------------------------
| 16-bit quantization | channel 0 | channel 0 | channel 0 | channel 0 |
| (Low byte) | (high byte) |
---------------------------------------------------------------------
| Sample 1 |
| Dual-channel | --------------------------------------------------------
| 16-bit quantization | channel 0 (left) | channel 0 (left) | channel 1 (right) | channel 1 (right) |
| (Low byte) | (high byte) |
---------------------------------------------------------------------
Figure 6 bit location arrangement of Wav data
The data chunk header structure is defined as follows:
Struct data_block
{
Char szdataid [4]; // 'D', 'A', 't', 'A'
DWORD dwdatasize;
};
References
1. Li Min, the conversion of the audio file format wave, computer knowledge and technology (Academic Exchange), 2005.
2. http://www.codeguru.com/cpp/g-m/multimedia/audio/article.php/c8935__1/
3, http://www.smth.org/pc/pcshowcom.php? Cid = 129276