BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

LVCF.hpp (2484B)


      1 #pragma once
      2 
      3 #include "bogaudio.hpp"
      4 #include "dsp/filters/multimode.hpp"
      5 
      6 using namespace bogaudio::dsp;
      7 
      8 extern Model* modelLVCF;
      9 
     10 namespace bogaudio {
     11 
     12 struct LVCF : BGModule {
     13 	enum ParamsIds {
     14 		FREQUENCY_PARAM,
     15 		FREQUENCY_CV_PARAM,
     16 		Q_PARAM,
     17 		MODE_PARAM,
     18 		NUM_PARAMS
     19 	};
     20 
     21 	enum InputsIds {
     22 		IN_INPUT,
     23 		FREQUENCY_CV_INPUT,
     24 		NUM_INPUTS
     25 	};
     26 
     27 	enum OutputsIds {
     28 		OUT_OUTPUT,
     29 		NUM_OUTPUTS
     30 	};
     31 
     32 	enum LightsIds {
     33 		LOWPASS_LIGHT,
     34 		BANDPASS_LIGHT,
     35 		HIGHPASS_LIGHT,
     36 		BANDREJECT_LIGHT,
     37 		NUM_LIGHTS
     38 	};
     39 
     40 	struct Engine {
     41 		MultimodeFilter16 _filter;
     42 		float _sampleRate;
     43 		bogaudio::dsp::SlewLimiter _frequencySL;
     44 		MultimodeFilter4 _finalHP;
     45 
     46 		Engine() {
     47 			sampleRateChange();
     48 		}
     49 
     50 		void setParams(
     51 			int poles,
     52 			MultimodeFilter::Mode mode,
     53 			float frequency,
     54 			float qbw,
     55 			MultimodeFilter::BandwidthMode bwm
     56 		);
     57 		void sampleRateChange();
     58 		void reset();
     59 		float next(float sample);
     60 	};
     61 
     62 	static constexpr float maxFrequency = 20000.0f;
     63 	static constexpr float minFrequency = MultimodeFilter::minFrequency;
     64 	MultimodeFilter::Mode _mode = MultimodeFilter::UNKNOWN_MODE;
     65 	int _polesSetting = 4;
     66 	int _poles = 0;
     67 	float _q = 0.0f;
     68 	MultimodeFilter::BandwidthMode _bandwidthMode = MultimodeFilter::PITCH_BANDWIDTH_MODE;
     69 	Engine* _engines[maxChannels];
     70 
     71 	LVCF() {
     72 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
     73 		configParam<ScaledSquaringParamQuantity<(int)maxFrequency>>(FREQUENCY_PARAM, 0.0f, 1.0f, 0.22361f, "Center/cutoff frequency", " HZ");
     74 		configParam(FREQUENCY_CV_PARAM, -1.0f, 1.0f, 0.0f, "Frequency CV attenuation", "%", 0.0f, 100.0f);
     75 		configParam(Q_PARAM, 0.0f, 1.0f, 0.0f, "Resonance / bandwidth", "%", 0.0f, 100.0f);
     76 		configSwitch(MODE_PARAM, 0.0f, 3.0f, 0.0f, "Mode", {"Lowpass", "Highpass", "Bandpass", "Band reject"});
     77 		configBypass(IN_INPUT, OUT_OUTPUT);
     78 
     79 		configInput(IN_INPUT, "Signal");
     80 		configInput(FREQUENCY_CV_INPUT, "Cutoff CV");
     81 
     82 		configOutput(OUT_OUTPUT, "Signal");
     83 	}
     84 
     85 	json_t* saveToJson(json_t* root) override;
     86 	void loadFromJson(json_t* root) override;
     87 	void sampleRateChange() override;
     88 	bool active() override;
     89 	int channels() override;
     90 	void addChannel(int c) override;
     91 	void removeChannel(int c) override;
     92 	MultimodeFilter::Mode modeParamValue();
     93 	void modulate() override;
     94 	void modulateChannel(int c) override;
     95 	void processAlways(const ProcessArgs& args) override;
     96 	void processAll(const ProcessArgs& args) override;
     97 	void processChannel(const ProcessArgs& args, int c) override;
     98 };
     99 
    100 } // namespace bogaudio