Zz wav file header

Source: Internet
Author: User
The format of the wave file in the wav file header: 00 h 4 char "riff" flag
04 H 4 long int file length
08 H 4 char "wave" flag
0ch 4 char "FMT" flag
10 H 4 transition byte (optional)
14 H 2 int format category (10 h is PCM sound data)
16 h, 2 int channels, 1 single channel, 2 dual channels
18 h 2 int sampling rate (number of samples per second), indicating the playback speed of each channel,
1ch 4 long int waveform audio data transmission rate. The value is the number of channels × number of data digits per second × per sample
The number of bits/8. The playback software can use this value to estimate the buffer size.
Adjust the number of 20 H 2 int data blocks (calculated in bytes). The value is the number of channels × data bit per sample.
Value/8. The playback software needs to process multiple bytes of data of this value at a time
The value is used to adjust the buffer.
22 h 2 indicates the number of data digits of each sample in each channel. If there are many
Channels. The sample size is the same for each channel.
24 h 4 char data tag "data"
28 H 4 long int Voice Data Length

In my post, the length of the file header is 42 bytes, but the actual length is 44 bytes (use ultraedit to open a wave file and you will know it in a few minutes ). If a struct is used to define the wave file header, it should be:
Struct wavefileheader
{
Char 0000ff [4];
DWORD dwrifflen;
Char chwave [4];
Char chfmt [4];
DWORD dwfmtlen;
Pcmwaveformat PWF;
Char chdata [4];
DWORD dwdatalen;
};

However, in actual tests, not all wave file headers are the same. Which of the following is the wav recorded by the recorder that comes with windows, with 58 bytes in the file header. Therefore, it is better to read n long characters, for example 60, and then search for the keyword "data ", after "data", a DWORD is the length of the actual audio data. After obtaining the LEN Length, you can read the LEN byte from the DWORD to read the end of the file. If it is a dual-channel, data is stored alternately; if it is a 16-bit sampling, each two bytes will store an ad value in a small-end manner. In this way, you can smoothly read audio data.

One problem is that it is not rigorous to directly read 60 bytes without knowing how long the file header is. If it is in the standard WAV format, the file header is only 44 bytes, there is a possibility that the entire file is not 60 bytes long. In practice, it is unlikely, but it should be strictly considered that 36 bytes should be read first, starting from 37, and four should be read to determine whether there is a "data" keyword, the actual length of the file header is obtained.

Now I think of this, and I will write it down for the moment.

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.