# Understanding the Audio FFT Example

Hi,

I am new to OF and Audio Analysis and I have a question in regards of the FFT Example:

In the OF example you can find the following in the setup:

``````// the fft needs to be smoothed out, so we create an array of floats
// for that purpose:
fftSmoothed = new float;
for (int i = 0; i < 8192; i++){
fftSmoothed[i] = 0;
}

nBandsToGet = 128;
``````

This array is initialized with 0 for the 8192 elements for the purpose of smoothing the FFT. Next we set the bands that we want to request from the FFT each update() which is 128 or 1/64 of 8192.

Later we have the following loop to do so

``````    // (5) grab the FFT, and put in into a "smoothed" array,
// by taking maximums, as peaks and then smoothing downward
float * val = ofSoundGetSpectrum(nBandsToGet);		// request 128 values for fft
for (int i = 0;i < nBandsToGet; i++){

// let the smoothed calue sink to zero:
fftSmoothed[i] *= 0.96f;

// take the max, either the smoothed or the incoming:
if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];

}
``````

I don´t know what I am overlooking but why do we init 8192 Elements in the setup, but always cycle only through the first 128 (nBandsToGet)? The smoothing happens basically in the loop of the 128 bands but how are the 8192 used or used for smoothing?

Many thanks.

i think it’s initialized to 8192 in case someone would like to increase the number of bands to display so they didn’t have to change the size but other than that they are never used. a better implementation would be something like:

``````// the fft needs to be smoothed out, so we create an array of floats
// for that purpose:
nBandsToGet = 128;
fftSmoothed = new float[nBandsToGet];
for (int i = 0; i < nBandsToGet; i++){
fftSmoothed[i] = 0;
}

``````

Thanks, I see. I assumed that the 8192 are used to somehow interpolate or average between bands to smooth them.

If I read the manual correctly the maximum number of bands returned by ofSoundGetSpectrum is 512?
So may be the example could be changed to max 512?

i’ve just changed it to use the same number of bands that are used to display

1 Like