PCM encapsulation in WAV format

Source: Internet
Author: User

From: http://blog.csdn.net/dahan_wangtao/archive/2010/03/10/5365014.aspx

Recently, we have to re-integrate the IPTV framework. There is a section in the middle that needs to package PCM into a WAV file. Let's take a look at the wav encapsulation instructions and record the key points, hope to help others:

The WAV format mainly includes the following frameworks:

Unsigned char ucwavheader [] =

{

// Riff wave chunk

0x52, 0x49, 0x46, 0x46, // "Riff"

0x30, 0x00, 0x00, 0x00, // = Total file length-8

0x57, 0x41, 0x56, 0x45, // "Wave"

// Format chunk

0x66, 0x6d, 0x74, 0x20, // "FMT"

0x10, 0x00, 0x00, 0x00, // Chunk length, value unchanged

0x01, 0x00, // The encoding method is generally 1 (PCM)

0x01, 0x00, // Number of audio channels

0x80, 0x3e, 0x00, 0x00, // Sampling frequency

0x00, 0x7d, 0x00, 0x00, // Required bytes per second = sampling frequency * block alignment bytes

0x02, 0x00, // Data Alignment bytes = number of bytes (byte) at each sampling point * Number of Audio Channels

0x10, 0x00, // Bit occupied by each sampling point

// Fact chunk

0x66, 0x61, 0x63, 0x74, // The chunk "fact" does not move

0x04, 0x00, 0x00, 0x00, // Block Length

0x00, 0xbe, 0x00, 0x00,

 

// Data chunk

0x64, 0x61, 0x74, 0x61, // "Data"

0x00, 0x00, 0x00, 0x00, // Block length = actual PCM Data Length

}

After reading the above structure, it is not difficult to understand the WAV format! When PCM is encapsulated into WAV, you need to understand the following points:

1: channels. How many channels does PCM data have?

2: sampling frequency. What is the sampling frequency of PCM Data? Generally 44.1 K 16000 8000, etc.

3: How many places each sampling point occupies

With the above data, it can be encapsulated into WAV format.

1: First, write the ucwavheaderdata into the .wav file header,

2: Enter PCM Data

3: Move the file pointer to the position of File Header + 4 and modify the value of the current size again.

After completing the above steps, the PCM data is encapsulated in WAV format!

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.