If the usFormatTag field of the <fmt-ck> is set to WAVE_FORMAT_PCM, then the waveform data consists of samples represented in pulse code modulation (PCM) format. For PCM waveform data, the <format-specific-fields> is defined as follows:
<PCM-format-specific> struct { USHORT usBitsPerSample; /* Sample size */ }
The usBitsPerSample field specifies the number of bits of data used to represent each sample of each channel. If there are multiple channels, the sample size is the same for each channel.
For PCM data, the usAvgBytesPerSec field of the 'fmt' chunk should
be equal to the following formula rounded up to the next whole number: usChannels
x usBitsPerSample x ulSamplesPerSec x .125
The usBlockAlign field should be equal to the following formula,
rounded to the next whole number: usChannels x usBitsPerSample x .125
Data Packing for PCM WAVE Files
In a single-channel WAVE file, samples are stored consecutively. For stereo WAVE files, channel 0 represents the left channel, and channel 1 represents the right channel. The speaker position mapping for more than two channels is currently undefined. In multiple-channel WAVE files, samples are interleaved.
The following diagrams show the data packing for a 8-bit mono and stereo WAVE files:
Sample 1 Sample 2 Sample 3 Sample 4 ┌───────────────┬──────────────────┬───────────────────┬───────────────┐ │ Channel 0 │ Channel 0 │ Channel 0 │ Channel 0 │ │ │ │ │ │ └───────────────┴──────────────────┴───────────────────┴───────────────┘ Data Packing for 8-Bit Mono PCM Sample 1 Sample 2 ┌───────────────┬──────────────────┬───────────────────┬───────────────┐ │ Channel 0 │ Channel 1 │ Channel 0 │ Channel 1 │ │ (left) │ (right) │ (left) │ (right) │ │ │ │ │ │ └───────────────┴──────────────────┴───────────────────┴───────────────┘ Data Packing for 8-Bit Stereo PCM
The following diagrams show the data packing for 16-bit mono and stereo WAVE files:
Sample 1 Sample 2 ┌────────────────┬──────────────────┬──────────────────┬────────────────┐ │ Channel 0 │ Channel 0 │ Channel 0 │ Channel 0 │ │ │ │ │ │ │low-order byte │ high-order byte │ low-order byte │ high-order byte│ └────────────────┴──────────────────┴──────────────────┴────────────────┘ Data Packing for 16-Bit Mono PCM
Sample 1 Sample 2 ┌────────────────┬──────────────────┬──────────────────┬────────────────┐ │ Channel 0 │ Channel 0 │ Channel 1 │ Channel 1 │ │ (left) │ (left) │ (right) │ (right) │ │low-order byte │ high-order byte │ low-order byte │ high-order byte│ └────────────────┴──────────────────┴──────────────────┴────────────────┘ Data Packing for 16-Bit Stereo PCM
Data Format of the Samples
Each sample is contained in an integer i. The size of i is the smallest number of bytes required to contain the specified sample size. The least significant byte is stored first. The bits that represent the sample amplitude are stored in the most significant bits of i, and the remaining bits are set to zero.
For example, if the sample size (recorded in nBitsPerSample) is 12 bits, then each sample is stored in a two-byte integer. The least significant four bits of the first (least significant) byte is set to zero.
The data format and maximum and minimums values for PCM waveform samples of various sizes are as follows:
┌────────────────────┬────────────────────┬──────────┬──────────┐ │Sample Size │Data Format │Maximum │Minimum │ │ │ │Value │Value │ ├────────────────────┼────────────────────┼──────────┼──────────┤ │One to eight bits │Unsigned integer │255 (0xFF)│0 │ ├────────────────────┼────────────────────┼──────────┼──────────┤ │Nine or more bits │Signed integer i │Largest │Most │ │ │ │positive │negative │ │ │ │value of i│value of i│ └────────────────────┴────────────────────┴──────────┴──────────┘
For example, the maximum, minimum, and midpoint values for 8-bit and 16-bit PCM waveform data are as follows:
┌──────────┬────────────────────┬────────────────────┬──────────┐ │Format │Maximum Value │Minimum Value │Midpoint │ │ │ │ │Value │ ├──────────┼────────────────────┼────────────────────┼──────────┤ │8-bit PCM │255 (0xFF) │0 │128 (0x80)│ ├──────────┼────────────────────┼────────────────────┼──────────┤ │16-bit PCM│32767 (0x7FFF) │-32768 (-0x8000) │0 │ └──────────┴────────────────────┴────────────────────┴──────────┘
Examples of PCM WAVE Files
Example of a PCM WAVE file with 11.025 kHz sampling rate, mono, 8 bits per sample:
RIFF( 'WAVE' fmt(1, 1, 11025, 11025, 1, 8) data( <wave-data> ) )
Example of a PCM WAVE file with 22.05 kHz sampling rate, stereo, 8 bits per sample:
RIFF( 'WAVE' fmt(1, 2, 22050, 44100, 2, 8) data( <wave-data> ) )
Example of a PCM WAVE file with 44.1 kHz sampling rate, mono, 20 bits per sample:
RIFF( 'WAVE' INFO(INAM("O Canada"Z)) fmt(1, 1, 44100, 132300, 3, 20) data( <wave-data> ) )