How to decode WAV/RIFF audio data?

3.9k views Asked by At

I'm trying to create a program to generate random audio which can be written to a WAV/RIFF file. I'm able to understand the header easily thanks to this, and I've found how to write byte data to a WAV/RIFF file here but what I can't find is anything which specifies how WAV/RIFF audio data is encoded in those bytes.

So what I'm trying to do is analyze the data (not trying to get this handed to me ;) ) to know what's going on in the bytes, thus allowing me to write my program properly. So is there anything out there that explains how to decode the audio chunk of the WAV/RIFF file to understand what's taking place in each byte (amplitude, frequencies, etc)? I understand I may be missing something here, maybe each byte isn't what I should be looking for, but again there seems to be only sparse data that I've been able to find on the topic out there.

Will be using Java for this at the moment, so if there are any implementation specific options there please let me know.

NOTE

I also found this and this which seem to be in the general area of what I'm looking for, but they still don't get there. So what I'm looking for is a specification or example that will show me how to analyze the individual bytes to see what's going on so I can learn how to write them.

EDIT

A friend suggested that I might be overthinking this, and that there may be a Java library that would make analyzing raw audio data easier in Java than doing it by byte. If so, any suggestions on this or where to look?

1

There are 1 answers

0
Kelsey Francis On

Each sample in a WAV file -- each 16-bit pair of bytes after the header -- represents an amplitude. If you want to discover the frequencies present in the raw audio signal, you'll probably want to run an FFT on the signal.

I did a project a while ago in Java that involved reading in WAV files and pulling out the frequencies (using an FFT library called JTransforms). Feel free to study/use the code.

Minim is a library for doing this sort of thing that also includes sound generation features.