Newer
Older
music / app / src / main / cpp / effects / LowPass.cpp
@lukas lukas on 25 Aug 2022 527 bytes add low pass filter effect
#include "../Instrument.h"
#include <math.h>

// direct model of a RC-filter, R = 1 Ohm for convenience

void LowPass::update() {
    charge = 0;
    inverseCapacitance = 2 * M_PI * frequency * pow(2, parameter1);
    capacitance = 1 / inverseCapacitance;
    timeStep = 1 / (float) host->sampleRate;
}

void LowPass::doRender(uint32_t sampleCount) {
    for (uint32_t i = 0; i < sampleCount; i++) {
        charge += (input[i] - charge * inverseCapacitance) * timeStep;
        buffer[i] = charge * inverseCapacitance;
    }
}