Krister ESS - myFFT.getSpectrum(myInput) ArrayIndexOutOfBounds Exception: 4096
in
Contributed Library Questions
•
11 months ago
Hello, I tried to contact Krister directly but his email is not valid, so I am posting my issue here in the event that anyone has any ideas.
I am making a music visualizer using Krister's Ess library and his Input FFT class. Every so often, the program throws an error. I am pretty sure that the error being thrown in my patch comes from his end in the myFFT.getSpectrum(myInput) class. The error that the Processing throws is: ArrayIndexOutOfBounds Exception: 4096 . The code is copied below.
Thank you very much!
----------- BEGIN CODE--------------
class InputFFTAnalysis
{
FFT myFFT;
FFT levelFFT;
AudioInput myInput;
int bufferSize;
int steps;
float limitDiff;
int numAverages=32;
float myDamp=.1f;
float maxLimit,minLimit;
float wavesamples[];
float frequency[];
float frequencies;
float level;
float getDamp;
float sum_total;
float sum[];
float sum_16;
float sum_32;
float sum_48;
float sum_64;
float sum_80;
float sum_96;
InputFFTAnalysis()
{
// set up our AudioInput
bufferSize=512;
myInput=new AudioInput(bufferSize*4); //
// set up our FFT
myFFT=new FFT(bufferSize*2); // 512*2 = 1024
levelFFT=new FFT();
myFFT.equalizer(true);
wavesamples=new float[512];
frequency=new float[512];
frequencies = 0;
level = 0;
sum = new float[24];
// set up our FFT normalization/dampening // **** WHAT DOES THIS DO in actuality? ***
minLimit=.005;
maxLimit=.05;
myFFT.limits(minLimit,maxLimit);
myFFT.damp(myDamp); // .1f
myFFT.averages(numAverages); // 32
// get the number of bins per average
steps=bufferSize/numAverages; // 512/32 = 16
// get the distance of travel between minimum and maximum limits
limitDiff=maxLimit-minLimit; // .05 - .005
myInput.start();
}
void UpdateData()
{
// draw the waveform
// time it takes for music to start? / length of song? * 512?
int interp=(int)max(0,(((millis()-myInput.bufferStartTime)/(float)myInput.duration)*myInput.size)); // what does this translate to in actuality?
// Does this number change or is it instanitated one time only?
// for example 1 millli sec/ 180 million sec * 512 = .00284
for (int i=0;i<bufferSize;i++) { //for i up to 512
float wave=0;
if (i+interp+1<myInput.buffer2.length) {
wave-=myInput.buffer2[i+interp]*1000.0;
}
wavesamples[i]=wave;
}
myFFT.getSpectrum(myInput); //*******THIS IS WHERE THE ARRAY OUT OF BOUNDS COMES FROM!!
level = (myFFT.getLevel(myInput));
for(int i=0; i<24; i++) {
sum[i]=0;
}
int band=0;
int f=0;
for (int i=0; i<bufferSize; i++) {
frequency[i]=myFFT.spectrum[i]*150;
if(band<24)
{
sum[band]=sum[band]+frequency[i]/8;
f=f+1;
if(f>=8) {f=0;band=band+1;}
}
}
for(int i=0;i<24;i++)
sum[i]=myFFT.averages[i];
sum_total = 0;
for(int i=0; i<24; i++) {
sum_total=sum_total+sum[i];
}
sum[0]=sum[0]/sum_total;
for(int i=1; i<24; i++) {
sum[i]=sum[i-1]+sum[i]/sum_total;
}
}
public void audioInputData(AudioInput theInput) {
myFFT.getSpectrum(myInput);
for (int i=0; i<bufferSize; i++) {
frequency[i]=myFFT.spectrum[i]*150;
}
}
}
---------- END CODE----------------
1