Detailed description of the WAVE audio file format

Source: Internet
Author: User

Detailed description of the WAVE audio file format

Currently, the WAVE audio file format is the most direct file format for storing sound data in Windows. Most of the files involved in audio signal processing are directly operated on WAV files. It is necessary to clarify the file format of the audio files to be studied.

1 RIFF files and WAV Files in Windows, most multimedia files store information according to a structure, called the resource Interchange File Format (RIFF. For example, audio WAV Files, video AVI files, and animated MMM files are derived from this structure. To master the multimedia file format, you must first understand the RIFF structure.

RIFF is a tree structure with a basic unit of chunk (Block). Each chunk consists of an identification code, data size, and data, for example. It can be seen that the length of a chunk is the data size plus 8 bytes.
 

Generally, the chunk itself does not allow the chunk to be contained in it, but there are two exceptions: The chunk identified by "RIFF" and "UST. For the two chunks, RIFF cut 4 bytes from the original "Raw data" as the "format identification code", as shown in.
 

After learning about the tree structure of RIFF, you can know that it is equivalent to a root directory, and the format identification code is equivalent to a specific drive letter such as C:, D:, etc. in Windows, the formats of multimedia files are similar to what directories can only be stored on the hosts, and what types of data can be stored under these directories.

2. WAV file header

As the name suggests, WAV is a waveform audio file (which is a standard format used to digitize audio in windows. Its file extension name is .wav. It is a very simple RIFF file with the format identification code "Wave ". the whole WAV file is divided into two parts: the file header and data block. WAV files mainly have two types of file headers.

2.1 Standard 44-Byte File Header

This WAV format is the simplest RIFF format. It contains two chunks: <fmt-chunk> and <wave-data>. These two sub-blocks must be included in a WAV file.
 

Riff wave Chunk

Use 'riff' as the marker, followed by the size field. The size is the Size of the whole wav file minus the number of bytes occupied by ID and Size, that is, FileLen-8 = size. then the Type field, which is 'wave ', indicates 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

Marked with 'fmt. generally, the Size is 16, and no additional information is added at the end. If the Size is 18, two additional bytes are added at the end. these two bytes are contained in the wav format made mainly by some software.

 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; }; 
In order to generate a WAV file that can be correctly read, you must strictly pay attention to the specific relationship between the following components. Otherwise, the generated file cannot be played normally:
If the 2.2 58-byte file header is not a Windows Standard WAV file, but is processed by some software, it is usually a 58-Byte File Header, as shown in.

It has a fact sub-block more than 44 bytes. <fact-ck> stores important information about the WAV file content. The sub-block is defined as follows:

Fact Chunk

Fact Chunk is an optional field. Generally, when a wav file is converted by some software, it contains the Chunk. The structure is defined as follows:

 struct FACT_BLOCK {char  szFactID[4]; // 'f','a','c','t'DWORD  dwFactSize; };
3 "data" sub-block data arrangement

The "data" sub-block contains real sound data. unless other special software is installed, Windows currently only provides the WAVE_FORMAT_PCM data format, namely, Pulse Code Modulation ). for this scheme, the data storage format in the "data" sub-block in Windows is shown in. Four locations are arranged based on the number of channels and the number of sampling digits.
 

















The Data Chunk header structure is defined as follows:

struct DATA_BLOCK {char szDataID[4]; // 'd','a','t','a'DWORD dwDataSize; };
Note: In Windows, set the 16-bit value range to [-32768,32767]. in addition, 0 does not necessarily mean silent, but is determined by the intermediate value, that is, 128 for 8 bits, and 0 for l6 bits is silent. therefore, when you need to put silent data in programming, you must first recognize whether the sound format is l6 or 8 bits. normally, only the raw data is obtained after decompression, and the sound cannot be played normally. after learning about the WAV file format, you can compile a correct WAV file header before decoding the data in the Standard 44-byte format to make it a valid WAV file.
4 instance file analysis below we analyze a real WAVE file (http://download.csdn.net/detail/ce123/5771797 ).

As described above, it is very easy to understand the structure of this file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.