Wav File Format Made Simple Here's a simple table explaining the format of a WAV file. All two-byte and four-byte values are stored small byte to large byte ("little-endian"). All numbers are written to the file in unsigned binary format. +------------------------------------------------------------------------------+ | RIFF file header -- 12 bytes | |------------------------------------------------------------------------------| | | | This is a tag identifying the file | | 4 bytes | the string "RIFF" | (stands for Resource Interchange File | | | | Format, the format of a WAV file. | |--------------+-----------------------+---------------------------------------| | | | This is the length of the file | | | File length (measured | beginning after the string | | 4 bytes | in bytes) | "WAVEfmt ". In PCM format this is 36 | | | | more than the data length (discussed | | | | below). | |--------------+-----------------------+---------------------------------------| | 4 bytes | the string "WAVE" | This tag further identifies it as a | | | | WAV format file. | |------------------------------------------------------------------------------| | Format information -- 24 bytes | |------------------------------------------------------------------------------| | | the string "fmt " | This is a tag identifying the format | | 4 bytes | (with the space | section of the file. | | | included) | | |--------------+-----------------------+---------------------------------------| | | | This is the length, in bytes, of this | | | length of format | part of the file (beginning after | | 4 bytes | information | this number and ending right before | | | | the string "data"). In PCM format, | | | | this number is 16 decimal, 10 Hex. | |--------------+-----------------------+---------------------------------------| | | | This identifies the format (PCM, | | 2 bytes | the format code | A-Law, mu-Law, etc.) For PCM, the | | | | value is 1. | |--------------+-----------------------+---------------------------------------| | 2 bytes | number of channels | This is 1 for monoral, 2 for stereo, | | | | etc. | |--------------+-----------------------+---------------------------------------| | | | This is measured in samples per | | 4 bytes | Sampling rate | second or Herz. Examples are 8000, | | | | 11025, 22050, and 44100. | |--------------+-----------------------+---------------------------------------| | | | This is an average value of the bytes | | 4 bytes | Bytes per Second | that are processed every second | | | | (calculated by Sampling Rate * Bits | | | | per Sample * Channels / 8). | |--------------+-----------------------+---------------------------------------| | | | This is the actual sample size in | | | | bytes, rounded up to the next whole | | 2 bytes | Bytes per sample | byte for 4-bit and 20-bit formats | | | | (Calculated by bits per sample * | | | | channels / 8). | |--------------+-----------------------+---------------------------------------| | | | This is the size in bits of a single | | 2 bytes | Bits per sample | channel's sample. For 8-bit formats, | | | | for example, stereo or mono, this | | | | number would be 8. | |------------------------------------------------------------------------------| | Data area -- variable length | |------------------------------------------------------------------------------| | 4 bytes | the string "data" | This is the tag that identifies the | | | | data area. | |--------------+-----------------------+---------------------------------------| | | | This is the length of the actual | | 4 bytes | Length of data | digital sound data (immediately | | | (measured in bytes) | following this number to the end of | | | | the file) in bytes. | |--------------+-----------------------+---------------------------------------| | | | Now we finally get what we came for! | | | | For each sample of a 16-bit | | unknown size | sound data | recording, put the low byte first. | | | | For stereo, put the left channel | | | | first. Happy encoding! | +------------------------------------------------------------------------------+