Wave file format specification

It seems very simple to write WAV files by yourself, but when it comes to be implemented... So, here is Microsoft Wave file format header:
Field name Size and format Meaning
File description header 4 bytes (DWord) The ASCII text string "RIFF" The procedure converiting 4-symbol string into dword is included in unit Wave
Size of file 4 bytes (DWord) The file size not including the "RIFF" description (4 bytes) and file description (4 bytes). This is file size - 8.
WAV description header 4 bytes (DWord) The ASCII text string "WAVE"
Format description header 4 bytes (DWord) The ASCII text string "fmt "(The space is also included)
Size of WAVE section chunck 4 bytes (DWord) The size of the WAVE type format (2 bytes) + mono/stereo flag (2 bytes) + sample rate (4 bytes) + bytes per sec (4 bytes) + block alignment (2 bytes) + bits per sample (2 bytes). This is usually 16.
WAVE type format 2 bytes (Word) Type of WAVE format. This is a PCM header = $01 (linear quntization). Other values indicates some forms of compression.
Number of channels 2 bytes (Word) mono ($01) or stereo ($02). You may try more channels...
Samples per second 4 bytes (DWord) The frequency of quantization (usually 44100 Hz, 22050 Hz, ...)
Bytes per second 4 bytes (DWord) Speed of data stream = Number_of_channels*Samples_per_second*Bits_per_Sample/8
Block alignment 2 bytes (Word) Number of bytes in elementary quantization = Number_of_channels*Bits_per_Sample/8
Bits per sample 2 bytes (Word) Digits of quantization (usually 32, 24, 16, 8). I wonder if this is, for example, 5 ..?
Data description header 4 bytes (DWord) The ASCII text string "data".
Size of data 4 bytes (DWord) Number of bytes of data is included in the data section.
Data -?- Wave stream data itself. Be careful with format of stereo (see below)

Notes.

  1. Do not worry about number formats. Everything is OK in Delphi. Remember to place the second word in list first while packing two words into DWord.
    { Example: if A1 and A2 is words, then dword B=(A1 and A2) is (A2 shl 16) + A1 }
  2. Note the order of samples in stereo wave file.
    Sample 1 - Left Sample 1 - Right Sample 2 - Left Sample 2 - Right Sample 3 - Left ...

    It's more convenient and also faster to write files in DWords, so left (AL) and right (AR) samples in most popular 16-digit quantzation is packed into DWord as D = (AR shl 16) + AL First and second samples in DWord in case of mono file is packed into DWord as
    D = (A2 shl 16) + A1
  3. In case of 8 - bit quantization the sample is unsigned byte (0..255),
    in case of 16 - bit - signed integer (-32767..32767)
Delphi unit, which contains basic I/O routines for WAV files Wave.pas

©2002-2003, Veter      English  Беларуская  Русский
Сайт создан в системе uCoz