#include "FFTDisplayComponent.h" FFTDisplayComponent::FFTDisplayComponent (FFTDisplayProcessor& processor, float bs, float ys) : bottonScale (bs), heightScale (ys), fftDisplayProcessor (processor), buffer (processor.getNumChannels(), processor.getNumSamples()) { fftDisplayProcessor.setEnable (true); setFramesPerSecond (90); setPaintingIsUnclipped (true); setOpaque (false); } FFTDisplayComponent::~FFTDisplayComponent() { fftDisplayProcessor.setEnable (false); } void FFTDisplayComponent::update() { if (fftDisplayProcessor.readBufferFromResult (buffer) != 0) newBuffer = true; } void FFTDisplayComponent::paint (Graphics &g) { if (! newBuffer) return; newBuffer = false; Path fftPath; const float xScale = (float) getWidth(); const float yScale = (float) getHeight() / bottonScale; for (int ch = 0; ch < buffer.getNumChannels(); ++ch) { fftPath.startNewSubPath (0.f, 2.f * yScale); for (int i = 0; i < buffer.getNumSamples(); ++i) { const float ratio = 0.999f * ((float) i / (float) buffer.getNumSamples()) + 0.001; const float logRatio = log10f (1000.f * ratio) / log10f (1000); float sample; sample = isnan (buffer.getSample(ch, i)) ? std::numeric_limits::min() : buffer.getSample(ch, i); sample = sample == 0.f ? std::numeric_limits::min() : sample; sample = sample < 0.f ? -sample : sample; const float mag = 20.f * log10f (sample); fftPath.lineTo (logRatio * xScale, yScale - heightScale * mag); } g.setColour (ch == 0 ? Colours::red : Colours::darkred); g.strokePath (fftPath, PathStrokeType (1.5f)); } }