mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-02 22:44:18 +01:00
spectrogram: Pull some constants out of the loop
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user