Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Is it possible to perform FFT with FilePlayer object? [Minim]

$
0
0

I'm trying to affect the playback speed of an mp3 based on the positions of the bars.

The "vanilla" code (from the analyzeSound.pde example) below works with an AudioPlayer object but when I try to combine it with the tickRate example, it says "the function 'bufferSize()' does not exist" and "the global variable 'mix' does not exist".

I don't understand Minim enough to know how to remedy this.

Is it possible to do it this way?

Thanks.

Vanilla:

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer player;
FFT fft;

float spectrumAvg;

void setup() {
  fullScreen();
  //size(512, 200);
  minim = new Minim(this);
  selectInput("Select an audio file:", "fileSelected");
}

void fileSelected(File selection) {
  String audioFileName = selection.getAbsolutePath();
  player = minim.loadFile(audioFileName);
  fft = new FFT(player.bufferSize(), player.sampleRate());
  player.play();
}

void draw()
{
  background(0);
  stroke(255);

  if (player != null) {
    if (fft != null) {
      fft.forward(player.mix);

      for (int i = 0; i < fft.specSize(); i++) {
        float lineStrength = height - fft.getBand(i)*height/2;
        spectrumAvg += lineStrength;
        line(i, height, i, lineStrength);
      }
      spectrumAvg = spectrumAvg / fft.specSize();
      println(spectrumAvg);
    }
  }
}

Combined with tickRate:

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.spi.*; // for AudioRecordingStream
import ddf.minim.ugens.*;


Minim minim;
FilePlayer player;
FFT fft;

float spectrumAvg;

void setup() {
  fullScreen();
  //size(512, 200);
  minim = new Minim(this);
  selectInput("Select an audio file:", "fileSelected");
}

void fileSelected(File selection) {
  String audioFileName = selection.getAbsolutePath();
  player = new FilePlayer(minim.loadFileStream(audioFileName));
  fft = new FFT(player.bufferSize(), player.sampleRate()); //error
  player.play();
}

void draw()
{
  background(0);
  stroke(255);

  if (player != null) {
    if (fft != null) {
      fft.forward(player.mix); //error

      for (int i = 0; i < fft.specSize(); i++) {
        float lineStrength = height - fft.getBand(i)*height/2;
        spectrumAvg += lineStrength;
        line(i, height, i, lineStrength);
      }
      spectrumAvg = spectrumAvg / fft.specSize();
      println(spectrumAvg);
    }
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles