WAV File format

Table of contents
  • Source

If you ever need to output a WAV file, here's the format:

  • the string "RIFF"
  • file length minus 8 bytes (4 bytes)
  • the string "WAVEfmt " (remember the ending whitespace!)
  • the number 16 (4 bytes)
  • the number 1, to represent linear quantization (2 bytes)
  • the number of channels. Either 1 or 2, just to be safe (2 bytes)
  • the sample rate. Standard sample rates are 44100, 88200, 96000, 192000 (4 bytes)
  • the byte rate. Absolutely has to be sample rate times number of channels time bits per sample all divided by 8 (4 bytes)
  • block align, which is the byte rate without the sample rate (2 bytes)
  • bits per sample, which is either 8, 16, 24, 32, etc. (2 bytes)
  • the string "data"
  • the length of the actual data (which doesn't include the header length)

You can look at an example implementation here: gist.github.com/shovo...b059ca


Want to make your own site like this? Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My second brain, by Sal Rahman.