We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! I am trying to create an audio visualizer. I am using live sound. The problem I keep coming into is the nullpointer exception error. Please take a look at this code and give me some tips on how to fix this! Thank you.
import ddf.minim.analysis.*; import ddf.minim.*;
Minim minim; AudioPlayer jingle; AudioInput input; FFT fft; int[][] colo = new int[100][10];
float color1 = 35;> float color2 = 45; float color3 = 65; float color4 = 75;
void setup() { size(512, 400); background(0); colorMode(HSB,100,100,100,100);
minim = new Minim(this);
input = minim.getLineIn();
fft = new FFT(input.bufferSize(), input.sampleRate());
}
void draw() { background(0); noStroke(); fill(0, 5); rect(0, 0, width, height); pushMatrix(); translate(width/2, height/2); rotate(radians(frameCount % 360 * 2));
fft.forward(input.mix);
for(int i = 0; i < fft.specSize(); i++) {
if(jingle.mix.get(i)*200 > fft.specSize()) {
stroke(color1,100,100);
}
else {
stroke(color2,100,100);
}
line(cos(i)*50, sin(i)*50, cos(i)*abs(jingle.left.get(i))*200 + cos(i)*50, sin(i)*abs(jingle.right.get(i))*200 + sin(i)*50);
}
for(int j = fft.specSize(); j > 0; j--) {
if(jingle.mix.get(j)*200 > fft.specSize()) {
stroke(color3,100,100);
}
else {
stroke(color4,100,100);
}
line(cos(j)*50, sin((j))*50, cos(j)*abs(jingle.right.get(j))*200 + cos(j)*50, sin(j)*abs(jingle.left.get(j))*200 + sin(j)*50);
}
popMatrix(); }
void keyPressed() {
if(key == 'r') { color1 = 0; color2 = 5; color3 = 90; color4 = 95; }
if(key == 'g') { color1 = 35; color2 = 45; color3 = 65; color4 = 75; } }
Answers
step 1 - code almost unchanged but better formatted
How could I change this into a 3D environment based on the FFT - I want to make a 3D spectral analysis graph of the audio.
there is a 3D version of line with xyz to xyz - see reference
use another property of fft to use as Z-Value
I realize that the property would be inserted here:
line(i, height, ____, height - fft.getBand(i)*8);
I am wondering what the property would be?