I'm working on a audio Equalizer, and I'm not sure if the way I obtain the power per octave of my signal is good.
Here is the code I have :
(I use the third octave bands, which is initialized earlier in the program)
void Record::ProcessData(short* Buffer, size_t BufferSize)
{
/* BufferSize is usualy equal to 131072 */
/* Initialize the signal and the Hanning Window */
Aquila::SignalSource signal = Aquila::SignalSource(Buffer, BufferSize, 44100);
Aquila::HannWindow HannWindow(BufferSize);
/* FFT */
/* The library overload the + operator, so the signal is multiplied with the window */
auto fft = Aquila::FftFactory::getFft(BufferSize);
Aquila::SpectrumType spectrum = fft->fft((signal + HannWindow).toArray());
/* Set the imaginary part to 0 */
for (size_t i = 0; i < BufferSize; i++)
spectrum[i]._Val[1] = 0;
/* OctaveRange is a class with the minimum, center and maximum frequency of an octave band */
list<OctaveRange>::iterator it;
map<double, double> sumMap;
double db, f, key;
/* Initialize the map values to 0 */
for (it = thirdOctave.begin(); it != thirdOctave.end(); it++)
sumMap[(*it).getCtr()] = 0.0;
/* The calcul of the power per octave starts from here */
for (size_t i = 0; i < (BufferSize / 2); i++)
{
/* f = frequency at bin i */
f = (double(i * 44100) / BufferSize);
for (it = thirdOctave.begin(); it != thirdOctave.end(); it++)
{
key = (*it).getCtr();
if (f >= (*it).getMin() && f < (*it).getMax())
sumMap[key] += pow(spectrum[i].real(), 2) + pow(spectrum[i].imag(), 2);
}
}
for (it = thirdOctave.begin(); it != thirdOctave.end(); it++)
{
key = (*it).getCtr();
/* db is the power (in dB) per third octave. */
db = 20.0 * std::log10(sqrt(sumMap[key]);
}
}
When I record pink noise with this I obtain some believable values, but I'm still not sure if this is because the code is good, or if it's a happy coincidence.
So my question is simple :
Is this the good way to obtain the power per octave band of a signal ?
Feel free to ask if something is not clear enough.
Thanks for your time.