Marco
Marco

Reputation: 644

Non-realtime FFT analysis on audio file

I'm trying to run an spectrum analysis on a file. Since the file that I'd like to analyse can be quite long (40 min or so), analysing this in real time is not really an option for me.

I'm currently using Minin's FFT class, but it looks like I can only run a song that's already playing. I've also looked at the ess library, but I understood that also is limited to having a realtime stream.

Is there a way to just iterate through an audio file in small chunks and then run the fft on that data?

Here's a simplified version of what I have now:

void setup()
{
  minim = new Minim(this);
  frameRate(30);

  song = minim.loadFile("../shortfile.mp3", 1024);
  song.loop();
  fft = new FFT(song.bufferSize(), song.sampleRate());
  background(#ffffff);  
}

void draw()
{
  fft.forward(song.mix);

  for(int i = 0; i < height/2; i++)
  {     
    intensity = constrain((log(fft.getBand(i)*1.4) / log(1.15)), 0, 40);
    intensity = int(map(intensity, 0 , 40, 0, 255));
    stroke(strokeColour(int(intensity)));

    point(framecount, i);
  }
}

Upvotes: 2

Views: 1652

Answers (2)

Daan
Daan

Reputation: 1879

This example from the official GitHub depot might help you; they call it offline analysis.

Upvotes: 3

Mikhail
Mikhail

Reputation: 8028

You want to read part of the file using standard io commands and then use FFTW. See http://www.fftw.org/fftw2_doc/fftw_2.html

Alternatively you can write your own FFT code from snippets on line. This will be quicker then learning how to use FFTW. Take a look at this page http://cnx.org/content/m12016/latest/ It appears to have a C FFT implementation. If you strip out the imaginary parts you will get an easy to understand 1D FFT scheme.

Upvotes: 1

Related Questions