#include "CMLSEqualizer.h"

CMLSEqualizer::CMLSEqualizer() {}

void CMLSEqualizer::prepare(const juce::dsp::ProcessSpec& spec) {
    sampleRate = spec.sampleRate;

    lowBand.prepare(spec);
    highBand.prepare(spec);

    lowBand.reset();
    highBand.reset();

    setEqLowGain(0.0f);
    setEqHighGain(0.0f);
}

void CMLSEqualizer::reset() {
    lowBand.reset();
    highBand.reset();
}

void CMLSEqualizer::process(const juce::dsp::ProcessContextReplacing<float>& context) {
    lowBand.process(context);
    highBand.process(context);
}

void CMLSEqualizer::setEqLowGain(float gain) {
    *lowBand.state = *juce::dsp::IIR::Coefficients<float>::makeLowShelf(
        sampleRate, 200.0f, 0.7f, juce::Decibels::decibelsToGain(gain));
}

void CMLSEqualizer::setEqHighGain(float gain) {
    *highBand.state = *juce::dsp::IIR::Coefficients<float>::makeHighShelf(
        sampleRate, 5000.0f, 0.7f, juce::Decibels::decibelsToGain(gain));
}