2

I'm working on an audio visualization project that is based off of Minim. For part of this project, I need an array of frequency amps (I'll use this array to determine heights for the monitor bars). I have never used Minim before, so I apologize for my limited knowledge on this subject in advance. The audio source is the input from a virtual audio cable that is returning any output sound from my PC.

The issue I'm having is that my amp[] (made of floats) is filled with 0.0 's; in other words, it isn't filling with the amplitudes of the various frequencies (despite my blasting of Zedd music!).

Here is my code (written in Eclipse):

import processing.core.*;
import java.awt.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

public class MinimTest2 extends PApplet {

Minim minim;
FFT fft;
AudioInput in;
float[] amp = new float[2000];

public void settings() {
  size(800, 600);
}

   public MinimTest2()
  {
   minim = new Minim(this);
   in = minim.getLineIn(Minim.STEREO, 2048); 
   fft = new FFT(in.bufferSize(), in.sampleRate()); 
   fft.logAverages(30, 5); 
  }

   public float[] getAmps(){
    int index = 0;
    for (int k=0; k<20000; k+=10){
        amp[index]=fft.getFreq(k);
        index++;
    }
    return amp;
   }

}

When the client class calls/prints getAmps(), 0.0's are printed. I believe the highest sound a human can hear is 20kHz (hence the condition in the for loop). The array should have amp samples every 10Hz, so amp[7] would have the amp value at 70Hz. Am I using the wrong method, potentially? I've been reading the documentation for Minim here, with the getFreq() FFT method I am using documented here.

Thanks for your patience and guidance! It's my first time with stack overflow.

UPDATE! I have a working audio visualizer now (at least, while you drag the mouse (placeholder while I work on other pieces). See answer for code.

1 Answers1

0

This works.

MinimTest2:

    import processing.core.*;
    import java.awt.*;
    import ddf.minim.signals.*;
    import ddf.minim.*;
    import ddf.minim.analysis.*;
    import ddf.minim.effects.*;

public class MinimTest2 extends PApplet {

Minim minim;
FFT fft;
AudioInput in;
float[] amp = new float[430];
float[] temp;

public void settings() {
      size(800, 600);
    }

   public MinimTest2()
  {
       minim = new Minim(this);
       in = minim.getLineIn();                    
       fft = new FFT(in.bufferSize(), in.sampleRate());               
  }

   public float[] getAmps(){
        fft.forward(in.left);
        amp = new float[430];
        temp = new float[fft.specSize()];
        int index = 0;
        for (int k=0; k<fft.specSize(); k++){
            temp[index]=fft.getBand(k);
            index++;
        }
        for (int i=0; i<amp.length; i++)
                amp[i]=temp[i];
        return amp;
   }
   public int getFFTSize(){
       return fft.specSize();
   }


}

Client (Work in progress):

import objectdraw.*;
import java.awt.*;

public class Client extends WindowController{
    MinimTest2 listener = new MinimTest2();
    float[] amps = new float[430];
    FilledRect[] bars = new FilledRect[430];

    public void begin(){
        resize(430,430);
            System.out.println(canvas.getWidth());
        System.out.println(canvas.getHeight());
}

public void onMouseDrag(Location point){
    canvas.clear();
    graphAmps();
    listAmps();
}

public void ampUp(){
    amps=listener.getAmps();
}

public void listAmps(){
    ampUp();
    for (int k=0; k<amps.length; k++)
        System.out.println(amps[k]);
}

public void graphAmps(){
    ampUp();
    double xPos =0;
    double rectWidth = canvas.getWidth()/430;
    for (int k=0; k<430; k++){
        bars[k] = new FilledRect (xPos, (canvas.getHeight()-(amps[k])*5) , rectWidth, (amps[k])*5, canvas);
        xPos+=rectWidth;
        bars[k].setColor(Color.BLUE);
    }
}

}