reVeno/Source/Veno/Utils/FFT.cpp

37 lines
902 B
C++
Raw Normal View History

2020-06-13 10:56:20 +02:00
//
// Created by versustune on 12.06.20.
//
#include "FFT.h"
void FFT::pushNextSampleIntoFifo (float sample) noexcept
{
2020-06-13 10:56:20 +02:00
{
if (fifoIndex == fftSize) // [11]
{
if (!nextFFTBlockReady) // [12]
{
zeromem (fftData, sizeof (fftData));
memcpy (fftData, fifo, sizeof (fifo));
2020-06-13 10:56:20 +02:00
nextFFTBlockReady = true;
}
fifoIndex = 0;
}
fifo[fifoIndex++] = sample; // [12]
}
}
void FFT::drawNextFrameOfSpectrum ()
{
window.multiplyWithWindowingTable (fftData, fftSize); // [1]
fft.performFrequencyOnlyForwardTransform (fftData); // [2]
2020-06-13 10:56:20 +02:00
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);
2020-06-13 10:56:20 +02:00
scopeData[i] = level;
}
}