I. Various WAV file header formats

Source: Internet
Author: User

Wav files are also divided into several types, and the corresponding non-data information is stored in the file header section. Below are various WAV file header formats.

Table 1 wave File Header Format for 8 KHz sampling and 16-bit quantization of linear PCM speech signals (44 bytes in total)
Offset address byte data type content file header is defined
00 H 4 char "riff" char riff_id [4] = "riff"
04 H 4 long int file total length-8 long int size0 = total length-8
08 h 8 char "wavefmt" char wave_fmt [8]
10 H 4 long int 10 00 00 00 H (PCM) Long int size1 = 0x10
14 H 2 int 01 00 h int fmttag = 0x01
16 H 2 int channel = 1 or 2
18 H 4 long int sampling rate long int samplespersec
1ch 4 long int playback bytes per second long int bytepersec
20 H 2 int sampling number of occupied segments at a time int blockalign = number of channels * quantization number/8
22 h 2 int quantization number int bitpersamples = 8 or 16
24 h 4 char "data" char data_id = "data"
28 H 4 long int sample data bytes long int size2 = length-44
2 CH to end char sampling data


 

 

Table 2 8 KHz sampling, 8-Bit A-Law Quantization of PCM voice signal wave File Header Format table (58 bytes in total)


Offset address byte data type content file header is defined
00 H 4 char "riff" char riff_id [4] = "riff"
04 H 4 long int file total length-8 long int size0 = total length-8
08 h 8 char "wavefmt" char wave_fmt [8]
10 H 4 long int 12000000 H (alaw) Long int size1 = 0x12
14 H 2 int 06 00 h int fmttag = 0x06
16 H 2 int channels int channel = 1 or 2
18 H 4 long int sampling rate long int samplespersec
1ch 4 long int playback bytes per second long int bytepersec
20 H 2 int sampling number of characters at a time int blockalign = 0x01
22 h 4 long int quantization number long int bitpersamples = 8
26 H 4 char "fact" char wave_fact = "fact"
2ah 8 char 0400000000530700h fixed char temp
32 H 4 char "data" char wave_data = "data"
36 H 4 long int sample data bytes lont int size2 = length-58

 

 

Table 3. 8 KHz sampling and 8-bit U-Law Quantization of PCM voice signal wave File Header Format table (58 bytes in total)


Offset address byte data type content file header is defined
00 H 4 char "riff" char riff_id [4] = "riff"
04 H 4 long int file total length-8 long int size0 = total length-8
08 h 8 char "wavefmt" char wave_fmt [8]
10 H 4 long int 12000000 H (ulaw) Long int size1 = 0x12
14 H 2 int 07 00 h int fmttag = 0x07
16 H 2 int channels int channel = 1 or 2
18 H 4 long int sampling rate long int samplespersec
1ch 4 long int playback bytes per second long int bytepersec
20 H 2 int sampling number of characters at a time int blockalign = 0x01
22 h 4 long int quantization number long int bitpersamples = 8
26 H 4 char "fact" char wave_fact = "fact"
2ah 8 char 0400000000530700h fixed char temp
32 H 4 char "data" char wave_data = "data"
36 H 4 long int sample data bytes lont int size2 = length-58

 

 

Table 4 Wave File Header Format table after ADPCM Speech Encoding (90 bytes in total)

 

Offset address byte data type content file header is defined
00 H 4 char "riff" char riff_id [4] = "riff"
04 H 4 long int file total length-8 long int size0 = total length-8
08 h 8 char "wavefmt" char wave_fmt [8]
10 H 4 long int 32000000 H (ADPCM) Long int size1 = 0x32
14 H 2 int 02 00 h int fmttag = 0x02
16 H 2 int channels int channel = 1 or 2
18 H 4 long int sampling rate long int samplespersec
1ch 4 long int playback bytes per second long int bytepersec
20 H 2 int sampling number of occupied segments at a time int blockalign = number of channels * quantization number/8
22 h 2 int quantization number int bitpersamples = 4
24 h 34 char fixed byte char temp1
46 H 4 char "fact" char wave_fact = "fact"
4ah 8 char 0400000004930600h fixed char temp2
52 H 4 char "data" char wave_data = "data"
56 H 4 long int sampled data bytes lont int size2 = length-90
5ah-end sampling data


 

 

Table 5 formats of wave file headers after GSM Speech Encoding (60 bytes in total)

Offset address byte data type content file header is defined
00 H 4 char "riff" char riff_id [4] = "riff"
04 H 4 long int file total length-8 long int size0 = total length-8
08 h 8 char "wavefmt" char wave_fmt [8]
10 H 4 long int 14000000 H (GSM) Long int size1 = 0x14
14 H 2 int 31 00 h int fmttag = 0x31
16 H 2 int channels int channel = 1 or 2
18 H 4 long int sampling rate long int samplespersec
1ch 4 long int playback bytes per second long int bytepersec
20 h 8 char 400000002004001h set char temp1
28 h 8 char 66616374040020.h fixed char temp2
30 H 4 char 40 E2 05 00h fixed char temp3
34 H 4 char "data" char wave_data = "data"
38 H 4 long int sample data bytes lont int size2 = length-60
3 ch to end-to-end sampling data


 

 

Table 6 SBC audio-encoded wave File Header Format table (58 bytes in total)

Offset address byte data type content file header is defined
00 H 4 char "riff" char riff_id [4] = "riff"
04 H 4 long int file total length-8 long int size0 = total length-8
08 h 8 char "wavefmt" char wave_fmt [8]
10 H 4 long int 12000000 H (SBC) Long int size1 = 0x12
14 H 2 int 71 00 h int fmttag = 0x71
16 H 2 int channels int channel = 1 or 2
18 H 4 long int sampling rate long int samplespersec
1ch 4 long int playback bytes per second long int bytepersec
20 H 2 int sampling number of characters at a time int blockalign = 0x25
22 h 4 long int quantization number long int bitpersamples = 16
26 H 4 char "fact" char wave_fact = "fact"
2ah 8 char 040011676280400h set char temp
32 H 4 char "data" char wave_data = "data"
36 H 4 long int sampled data bytes lont int size2 = length-59


 

 

Table 7 wave File Header Format table after CELP Speech Encoding (58 bytes in total)

Offset address byte data type content file header is defined
00 H 4 char "riff" char riff_id [4] = "riff"
04 H 4 long int file total length-8 long int size0 = total length-8
08 h 8 char "wavefmt" char wave_fmt [8]
10 H 4 long int 12000000 H (CELP) Long int size1 = 0x12
14 H 2 int 70 00 h int fmttag = 0x70
16 H 2 int channels int channel = 1 or 2
18 H 4 long int sampling rate long int samplespersec
1ch 4 long int playback bytes per second long int bytepersec
20 H 2 int sampling number of characters at a time int blockalign = 0x0c
22 h 4 long int quantization number long int bitpersamples = 16
26 H 4 char "fact" char wave_fact = "fact"
2ah 8 char 040011660520700h fixed char temp
32 H 4 char "data" char wave_data = "data"
36 H 4 long int sample data bytes lont int size2 = length-58

 

Waveformatex

Typedef struct {word wformattag; Word nchannels; DWORD nsamplespersec; DWORD navgbytespersec; Word nblockalign; Word wbitspersample; Word cbsize;} waveformatex;

The specific parameters are described as follows:
Wformattag: the format of waveform data, defined in mmreg. h file
Nchannels: number of channels for waveform data: single channel or stereo
Nsamplespersec: sampling rate. For PCM format waveform data, the sampling rate is 8.0 kHz, 11.025 kHz, 22.05 kHz, 44.1 kHz, etc.
Navgbytespersec: data rate. For PCM waveform data, the data rate equals to the sampling rate multiplied by the number of bytes per sample.
Nblockalign: number of bytes per sample
Wbitspersample: Sampling Accuracy. For PCM format waveform data, the sampling accuracy is 8 or 16
Cbsize: size of the data block with additional format information
Concept 2. Define the device header Structure
Wavehdr defines the device header pointing to the waveform data buffer.

Wavehdr

Typedef struct {lpstr lpdata; DWORD dwbufferlength; DWORD dwbytesrecorded; DWORD dwuser; DWORD dwflags; DWORD dwloops; struct wavehdr_tag * lpnext; DWORD reserved;} wavehdr;

Lpdata: the buffer address of the waveform data
Dwbufferlength: the length of the buffer address of the waveform data
Dwbytesrecorded: indicates the length of the input data when the device is used for recording.
Dwuser: User Data
Dwflags: the buffer attribute of the waveform data
Dwloops: the number of playback cycles. It is only used for playback control.
Both lpnext and reserved are reserved values.
Note: The above struct and the "hwavein" and "hwaveout" struct used in the program all exist in the system. You only need to assign values to them.

 

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.