mirror of
https://codeberg.org/armin/gelyk.git
synced 2026-10-11 17:01:53 +02:00
74 lines
1.8 KiB
C++
74 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <JuceHeader.h>
|
|
|
|
namespace gelyk
|
|
{
|
|
|
|
// A single peaking/shelf filter band with smoothed coefficients.
|
|
struct FilterBand
|
|
{
|
|
enum class Type
|
|
{
|
|
lowShelf,
|
|
peak,
|
|
highShelf
|
|
};
|
|
|
|
Type type = Type::peak;
|
|
float gainDb = 0.0f; // target gain in dB
|
|
float freq = 1000.0f; // centre/corner frequency
|
|
float q = 1.0f;
|
|
|
|
void prepare(double sampleRate, int blockSize);
|
|
void reset();
|
|
void process(juce::dsp::AudioBlock<float>& block);
|
|
|
|
using Filter = juce::dsp::IIR::Filter<float>;
|
|
using Coeffs = juce::dsp::IIR::Coefficients<float>;
|
|
|
|
Filter left, right;
|
|
};
|
|
|
|
// Simple background "realtime" analyser: it keeps a circular ring buffer
|
|
// of the most recent input, computes an FFT magnitude spectrum periodically
|
|
// in a background thread, and exposes the result thread-safely for the UI.
|
|
class SpectrumAnalyser : public juce::Timer
|
|
{
|
|
public:
|
|
SpectrumAnalyser();
|
|
~SpectrumAnalyser() override = default;
|
|
|
|
void prepare(double sampleRate, int maxBlockSize);
|
|
void push(const float* const* channels, int numChannels, int numSamples);
|
|
|
|
void startBackground();
|
|
void stopBackground();
|
|
|
|
// Copies the latest spectrum into `dest` (size destSize) with equal
|
|
// log-spaced bands, returning the number of bins written.
|
|
int copySpectrum(juce::Array<float>& dest, juce::Array<float>& freqBins,
|
|
int maxBins) const;
|
|
|
|
void setEnabled(bool enabled);
|
|
|
|
private:
|
|
void timerCallback() override;
|
|
|
|
void runAnalysis();
|
|
|
|
mutable juce::CriticalSection spectrumLock;
|
|
juce::Array<float> readySpectrum; // magnitude per bin
|
|
|
|
juce::dsp::FFT fft;
|
|
std::vector<float> fftBuffer;
|
|
|
|
juce::AudioBuffer<float> ring;
|
|
int ringFill = 0;
|
|
int ringChannels = 0;
|
|
double sampleRate = 44100.0;
|
|
|
|
std::atomic<bool> enabled { true };
|
|
};
|
|
|
|
} // namespace gelyk
|