#pragma once #include 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& block); using Filter = juce::dsp::IIR::Filter; using Coeffs = juce::dsp::IIR::Coefficients; Filter left, right; }; // Computes the total summed magnitude response (in dB) of a series filter chain // at `numBins` log-spaced frequencies from 20 Hz to 20 kHz. Uses the current // gains, frequencies and Q values and the same coefficient maths as the audio path, // so it exactly matches what is heard. void computeEQResponse(const FilterBand::Type* types, const float* gains, const float* freqs, const float* qs, int numBands, double sampleRate, float* outDb, int numBins); // 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& dest, juce::Array& freqBins, int maxBins) const; void setEnabled(bool enabled); private: void timerCallback() override; void runAnalysis(); mutable juce::CriticalSection spectrumLock; juce::Array readySpectrum; // magnitude per bin juce::dsp::FFT fft; std::vector fftBuffer; juce::AudioBuffer ring; int ringFill = 0; int ringChannels = 0; double sampleRate = 44100.0; std::atomic enabled { true }; }; } // namespace gelyk