#pragma once #include "BiquadParams.h" #include "BiquadState.h" #include "BiquadFilter.h" #include "ObjectCache.h" class IIRUpsampler { public: void process(float * outputBuffer, float input) { input *= oversample; for (int i = 0; i < oversample; ++i) { outputBuffer[i] = BiquadFilter::run(input, state, *params); input = 0; // just filter a delta - don't average the whole signal } } /** * cutoff is normalized freq (.5 = nyquist). * typically cutoff will be < (.5 / FACTOR), * if not, the filters wouldn't work. */ #if 0 void setCutoff(float cutoff) { assert(cutoff > 0 && cutoff < .5f); // ButterworthFilterDesigner::designSixPoleLowpass(params, cutoff); params = ObjectCache::get6PLPParams(cutoff); } #endif /** * Will set the oversample factor, and set the filter cutoff. * NOrmalized cutoff is fixed at 1 / 4 * oversample, for a one * octave passband */ void setup(int oversampleFactor) { assert(oversampleFactor == 4 || oversampleFactor == 16); oversample = oversampleFactor; params = ObjectCache::get6PLPParams(1.f / (4.0f * oversample)); } private: std::shared_ptr> params; BiquadState state; int oversample = 16; };