reVeno/Source/Veno/Utils/FFT.cpp
2020-06-13 10:56:20 +02:00

36 lines
893 B
C++

//
// Created by versustune on 12.06.20.
//
#include "FFT.h"
void FFT::pushNextSampleIntoFifo(float sample) noexcept {
{
if (fifoIndex == fftSize) // [11]
{
if (!nextFFTBlockReady) // [12]
{
zeromem(fftData, sizeof(fftData));
memcpy(fftData, fifo, sizeof(fifo));
nextFFTBlockReady = true;
}
fifoIndex = 0;
}
fifo[fifoIndex++] = sample; // [12]
}
}
void FFT::drawNextFrameOfSpectrum() {
window.multiplyWithWindowingTable(fftData, fftSize); // [1]
fft.performFrequencyOnlyForwardTransform(fftData); // [2]
auto mindB = -80.0f;
auto maxdB = 0.0f;
for (int i = 0; i < scopeSize; ++i)
{
auto level = jmap(Decibels::gainToDecibels(fftData[i], mindB), mindB, maxdB, -1.0f, 1.0f);
scopeData[i] = level;
}
}