spectrogram: Pull some constants out of the loop

This commit is contained in:
Mike Walters
2016-06-04 14:46:28 +01:00
parent 1d33e70a1f
commit 45e2e7ef67

View File

@@ -142,13 +142,15 @@ void SpectrogramPlot::getLine(float *dest, off_t sample)
}
fft->process(buffer.get(), buffer.get());
const float invFFTSize = 1.0f / fftSize;
const float dbMult = 10.0f / log2f(10.0f);
for (int i = 0; i < fftSize; i++) {
// Start from the middle of the FFTW array and wrap
// to rearrange the data
int k = (i + fftSize / 2) & (fftSize - 1);
auto s = buffer[k] / (float)fftSize;
auto s = buffer[k] * invFFTSize;
float mag = sqrt(s.real() * s.real() + s.imag() * s.imag());
float magdb = 10 * log2f(mag) / log2f(10);
float magdb = log2f(mag) * dbMult;
*dest = magdb;
dest++;
}