spectrogram: Drop the unnecessary sqrt

This commit is contained in:
Mike Walters
2016-06-04 14:50:27 +01:00
parent 45e2e7ef67
commit 22c81f52da

View File

@@ -143,14 +143,14 @@ 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);
const float dbMult = 5.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] * invFFTSize;
float mag = sqrt(s.real() * s.real() + s.imag() * s.imag());
float magdb = log2f(mag) * dbMult;
float power = s.real() * s.real() + s.imag() * s.imag();
float magdb = log2f(power) * dbMult;
*dest = magdb;
dest++;
}