Sound Library FFT analysis

Brand new to Processing.

Attempting to create an Audio analysis object.

The following constructors show the error "the construction ~~~~~ does not exist"

fft = new FFT(this, bands);
in = new AudioIn(this, 0);

I am restructuring the code from the Processing Libraries reference page. LINK

When running that code, the sketch crashes.

My code is as follows. import processing.sound.*;

class Audio {
  FFT fft;
  AudioIn in; //grabs audio input from soundcard
  int bands;
  float[] spectrum;

  Audio() {
    bands = 512;
    spectrum = new float[bands];

    fft = new FFT(this, bands);
    in = new AudioIn(this, 0);
  }

  void run() {
    in.start();

    fft.input(in);
  }
}

void setup() {
  audio = new Audio();
  audio.run();
}

void draw() {
  background(255);
  audio.fft.analyze(audio.spectrum);

  for (int i = 0; i < audio.bands; i++) {
    // The result of the FFT is normalized
    // draw the line for frequency band i scaling it up by 5 to get more amplitude.
    line( i, height, i, height - audio.spectrum[i]*height*5 );
  }
}

Audio audio;

Has anyone worked this out and can shed any light on the situation?

Cheers,

Nousernames2

Tagged:

Answers

  • Answer ✓

    Lines 11 and 12 this refers to your audio class. It's expecting a papplet, I guess. The example will be calling out from the main sketch class, not a Sub class.

    Change your Audio constructor to take a papplet and store it. Use that as the first argument to the calls in lines 11 and 12.

  • Of course it does! Thanks for your help.

Sign In or Register to comment.