Hello, I am extremely new to coding so apologies if my formatting or knowledge is off.
I am trying to analyze a sound file using the Sound Library and display a visualization of it using the Fast Fourier Transform (FFT) analyzer. However, I am getting this NullPointerException when trying to run it.
Mar 06, 2023 2:02:22 PM com.jsyn.devices.javasound.JavaSoundAudioDevice <init>
INFO: JSyn: default output latency set to 80 msec for Windows 11
NullPointerException
This is the highlighted line
fft.analyze();
This is the entire code
//sound
import processing.sound.*;
SoundFile soundfile;
FFT fft;
int bands = 32; //(8,16,32,64,128,256,512,1024)
float margin = 100;
float stepNum;
float stepPlus;
void setup(){
background(0);
size(1200,1200);
frameRate(8);
//sound
soundfile = new SoundFile(this, "sample.wav"); //(60*8)
soundfile.play();
//analyze
fft.analyze();
stepNum = (width-margin*2)/bands;
stepPlus = (width-margin*2)/(60*8); //second framecount
}
void draw(){
//background(0);
//noStroke();
//fill(0,30);
//rect(0,0,width,height);
stroke(255,70);
smooth();
noFill();
fft.analyze();
if (stepNum < width - margin*2){
for(int i=0; i < bands; ++i){
strokeWeight(fft.spectrum[i]*50+1);
for (float j = 0; j < 10; ++j) {
float ali = random(360);
float ran = (fft.spectrum[i]*width/5+1) * (1 - random(random(random(1))));
point(cos(ali)*ran+stepNum+margin, sin(ali)*ran+i*(height-margin*2)/float(bands)+margin);
}
}
}
stepNum += stepPlus;
}
Thank you!