3
votes

I have a wav file and can't figure out how to extract the data I need from it to put it into an Fast Fourier Transform (FFT) for further analysis...

I've done lots of googling and searching but haven't found something specific...

The FFT algorithm code:

    public class ShortTimeFourierTransform {
        public static double[][] magnitudeSpectrum(double[] signal, int windowSize, int hopSize) { ... }  
...}

Takes in a double[] for the signal so I assumed that I had to figure out how to parse the wav file and get a double[t] where "t" is the time, and double[t] would be the amplitude of the wav file at time t.

I have no idea how to proceed. Most solutions seem to export the wav into bytes and the parsing of wav files by bytes seems to be a lot more complicated manually according to (https://ccrma.stanford.edu/courses/422/projects/WaveFormat/)

Thank you so much!

1
I have the same problem today. Dammit... xkcd.com/979 - Gaspa79

1 Answers

1
votes

The .wav format is just a wrapper format around an audio encoding. You'll need to:

  • Parse the .wav file, get the encoded audio
  • Decode the audio, get raw PCM audio bytes (PCM is also an encoding but easy to work with)
  • Convert the audio into whatever format you requires. (some doubles?)

There's no real way around this- unless you can change the format of the file.

If you can change the file format, I suggest using a program (like Audacity) to open the wav file, and save its raw PCM encoded bytes. That'll keep you from having to worry about the .wav format.

A good 3rd party library can help you with this. I have no suggestions though.