How do I read an audio file (namely a .wav) into an array for DSP?
Thanks a lot.
How do I read an audio file (namely a .wav) into an array for DSP?
Thanks a lot.
www.wotsit.org
A WAV is a chunky file.
I believe this is how they start.
"R","I","F","F"
Length
Header information
...
...
"F","M","T"
Length
Header information about the WAV
...
...
"W","A",V"
Length
WAV data - compression depends on whether or not compression is indicated in the headers. I believe the RIFF header states this information.
Find "R" "I" "F" "F" Then you need to look for "F","M","T" and then "W","A","V" Each tag is followed by a length value which indicates the length of the chunk. There are more chunks in any WAV, but these are all you should need.
When you reach FMT, load the length of FMT into the WAVEFORMATEX structure. Then allocate a buffer of the correct data type (8,16-bit) and read the WAV data. You may have to decompress it depending on whether the data is compressed or not. Most are not.