PCM Audio and Wave Files
来源:互联网 发布:python爬微博数据 编辑:程序博客网 时间:2024/05/21 09:30
PCM Audio and Wave Files
In Brief, What Is PCM?
In the digital domain, PCM (Pulse CodeModulation) is the most straightforward mechanism to store audio. The analog audio is sampled in accordance with theNyquest theorem and the individual samples are stored sequentially in binary format.
The wave file is the most common format for storing PCM data. But, before you dig into the internals of wave files, it would help to get some insights to theInterchange Format Files that form the basis for the wave file format.
Interchange Format Files (IFF)
It is a "Meta" file format developed by a company named Electronic Arts. The full name of this format is ElectronicArts Interchange File Format 1985 (EAIFF 85). IFF lays down a top-level protocol on what the structure of IFF compliant files should look like. It targets issues such as versioning, compatibility, portability, and so forth. It helps specify standardized file formats that aren't tied to a particular product.
For the purpose of explaining wave files, it would surmise to say that the wave file format is based on the generic IFF format. If you are interested in digging deeper into IFF, here is a wonderful link:
http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/IFF.txt.
The WAVE File Format
The WAVE File Format supports a variety of bit resolutions, sample rates, and channels of audio. I would say that this is the most popular format for storing PCM audio on the PC and has become synonymous with the term "raw digital audio."
The WAVE file format is based on Microsoft's version of the Electronic Arts Interchange File Format method for storing data. In keeping with the dictums ofIFF, data in a Wave file is stored in many different "chunks." So, if a vendor wants to store additional information in a Wave file, he just adds info to new chunks instead of trying to tweak the base file format or come up with his own proprietary file format. That is the primary goal of the IFF.
As mentioned earlier, a WAVE file is a collection of a number of different types of chunks. But, there arethree chunks that are required to be present in a valid wave file:
- 'RIFF', 'WAVE' chunk
- "fmt" chunk
- 'data' chunk
All other chunks are optional. The Riff wave chunk is the identifier chunk that tells us that this is a wave file. The "fmt" chunk contains important parameters describing the waveform, such as itssample rate, bits per sample, and so forth. The Data chunk contains the actual waveform data.
An application that uses a WAVE file must be able to read the three required chunks although it can ignore the optional chunks. But, all applications that perform a copy operation on wave filesshould copy all of the chunks in the WAVE.
The Riff chunk is always the first chunk. The fmt chunk should be present before the data chunk. Apart from this, there are no restrictions upon the order of the chunks within a WAVE file.
Here is an example of the layout for a minimal WAVE file. It consists of a single WAVE containing the three required chunks.
While interpreting WAVE files, the unit of measurement used is a "sample." Literally, it is what it says. A sample represents data captured during a single sampling cycle. So, if you are sampling at 44 KHz, you will have 44 K samples. Each sample could be represented as 8 bits, 16 bits, 24 bits, or 32 bits. (There is no restriction on how many bits you use for a sample except that it has to be a multiple of 8.) To some extent, the more the number of bits in a sample, the better the quality of the audio.
One annoying detail to note is that 8-bit samples are represented as "unsigned" values whereas 16-bit and higher are represented by "signed" values. I don't know why this discrepancy exists; that's just the way it is.
The data bits for each sample should be left-justified and padded with 0s. For example, consider the case of a 10-bit sample (as samples must be multiples of 8, we need to represent it as 16 bits). The 10 bits should be left-justified so that they become bits 6 to 15 inclusive, and bits 0 to 5 should be set to zero.
As an example, here is a 10-bit sample with a value of 0100001111 left-justified as a 16-bit word.
The image kind of got blurred during conversion from BMP to a GIF, but I hope it is legible enough. The MSB ends in 15. That's what I drew, but it kind of looks like a 16, doesnt it? Pardon me for that.
Given the fact that the WAVE format uses Intel's little endian byte order, the LSB is stored first, as shown here:
The analogy I have provided is for mono audio, meaning that you have just one "channel." When you deal with stereo audio, 3D audio, and so forth, you are in effect dealing withmultiple channels, meaning you have multiple samples describing the audio in any given moment in time. For example, for stereo audio, at any given point in time you need to know what the audio signal was for theleft channel as well as the right channel. So, you will have to read and write two samples at a time.
Say you sample at 44 KHz for stereo audio; then effectively, you will have 44 K * 2 samples. If you are using 16 bits per sample, then given the duration of audio, you can calculate the total size of the wave file as:
Size in bytes = sampling rate * number of channels * (bits per sample / 8) * duration in seconds
Number of samples per second = sampling rate * number of channels
When you are dealing with such multi-channel sounds, single sample points from each channel areinterleaved. Instead of storing all of the sample points for the left channel first, and then storing all of the sample points for the right channel next, you "interleave" the two channels' samples together. You would store the first sample of the left channel. Then, you would store the first sample of the right channel, and so on.
- PCM Audio and Wave Files
- PCM Audio and Wave Files
- PCM Audio and Wave Files 2
- Audio PCM
- Audio PCM
- Wave Files
- 音频编解码·格式篇(1)Wave PCM audio format(WAV)
- 音频编解码·格式篇(1)Wave PCM audio format(WAV)
- 音频编解码·格式篇(1)Wave PCM audio format(WAV)
- 音频编解码·格式篇(1)Wave PCM audio format(WAV)
- 解决can't play not PCM-coded WAVE-files的问题
- WAVE PCM 声音文件格式
- WAVE PCM soundfile format
- WAVE PCM 声音文件格式
- WAVE PCM soundfile format
- WAVE PCM 文件剖析
- WAVE PCM 声音文件格式
- WAVE PCM soundfile format
- C# 最小化其他应用程序
- SQL Server常用管理命令小结
- 《Effective STL》读书笔记
- 再说指针
- 解决ScrollView滑动过程中ScrollTo()方法不起作用的问题
- PCM Audio and Wave Files
- 测试领域的发展和学习
- Magento Paypal Web Payment Standard(paypal标准)付款如何设置
- Sqlite 主键自动创建
- yum 命令配置及使用
- 手游爆发“平台战”启幕
- PCM Audio and Wave Files 2
- 划分算法(快速排序的根基)
- 任务处理——最优化问题