BogaudioModules

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

Pressor.hpp (3561B)


      1 #pragma once
      2 
      3 #include "bogaudio.hpp"
      4 #include "dsp/filters/utility.hpp"
      5 #include "dsp/signal.hpp"
      6 
      7 using namespace bogaudio::dsp;
      8 
      9 extern Model* modelPressor;
     10 
     11 namespace bogaudio {
     12 
     13 struct Pressor : BGModule {
     14 	enum ParamsIds {
     15 		THRESHOLD_PARAM,
     16 		RATIO_PARAM,
     17 		ATTACK_PARAM,
     18 		RELEASE_PARAM,
     19 		OUTPUT_GAIN_PARAM,
     20 		INPUT_GAIN_PARAM,
     21 		DETECTOR_MIX_PARAM,
     22 		MODE_PARAM,
     23 		DECTECTOR_MODE_PARAM,
     24 		KNEE_PARAM,
     25 		NUM_PARAMS
     26 	};
     27 
     28 	enum InputsIds {
     29 		LEFT_INPUT,
     30 		SIDECHAIN_INPUT,
     31 		THRESHOLD_INPUT,
     32 		RATIO_INPUT,
     33 		RIGHT_INPUT,
     34 		ATTACK_INPUT,
     35 		RELEASE_INPUT,
     36 		INPUT_GAIN_INPUT,
     37 		OUTPUT_GAIN_INPUT,
     38 		NUM_INPUTS
     39 	};
     40 
     41 	enum OutputsIds {
     42 		ENVELOPE_OUTPUT,
     43 		LEFT_OUTPUT,
     44 		RIGHT_OUTPUT,
     45 		NUM_OUTPUTS
     46 	};
     47 
     48 	struct Engine {
     49 		float thresholdDb = 0.0f;
     50 		float ratio = 0.0f;
     51 		float ratioKnob = -1.0f;
     52 		float inGain = -1.0f;
     53 		float inLevel = 0.0f;
     54 		float outGain = -1.0f;
     55 		float outLevel = 0.0f;
     56 		float lastEnv = 0.0f;
     57 
     58 		bogaudio::dsp::SlewLimiter attackSL;
     59 		bogaudio::dsp::SlewLimiter releaseSL;
     60 		CrossFader detectorMix;
     61 		RootMeanSquare detectorRMS;
     62 		Compressor compressor;
     63 		NoiseGate noiseGate;
     64 		Amplifier amplifier;
     65 		Saturator saturator;
     66 
     67 		Engine() : detectorRMS(1000.0f, 1.0f, 50.0f) {}
     68 
     69 		void sampleRateChange();
     70 	};
     71 
     72 	Engine* _engines[maxChannels] {};
     73 	float _compressionDb = 0.0f;
     74 	bool _compressorMode = true;
     75 	bool _rmsDetector = true;
     76 	bool _softKnee = true;
     77 	float _thresholdRange = 1.0f;
     78 
     79 	struct ThresholdParamQuantity : ParamQuantity {
     80 		float getDisplayValue() override;
     81 		void setDisplayValue(float v) override;
     82 	};
     83 
     84 	Pressor() {
     85 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
     86 		configParam<ThresholdParamQuantity>(THRESHOLD_PARAM, 0.0f, 1.0f, 0.8f, "Threshold", " dB");
     87 		configParam<DynamicsRatioParamQuantity>(RATIO_PARAM, 0.0f, 1.0f, 0.55159f, "Ratio");
     88 		configParam<ScaledSquaringParamQuantity<500>>(ATTACK_PARAM, 0.0f, 1.0f, SQUARE_ROOT_ONE_TENTH, "Attack", " ms");
     89 		configParam<ScaledSquaringParamQuantity<2>>(RELEASE_PARAM, 0.0f, 1.0f, SQUARE_ROOT_ONE_TENTH, "Release", " s");
     90 		configParam(OUTPUT_GAIN_PARAM, 0.0f, 1.0f, 0.0f, "Output gain", " dB", 0.0f, 24.0f);
     91 		configParam(INPUT_GAIN_PARAM, -1.0f, 1.0f, 0.0f, "Input gain", " dB", 0.0f, 12.0f);
     92 		configParam(DETECTOR_MIX_PARAM, -1.0f, 1.0f, 0.0f, "Detector mix", "%", 0.0f, 100.0f);
     93 		configSwitch(MODE_PARAM, 0.0f, 1.0f, 1.0f, "Mode", {"Noise gate", "Compressor"});
     94 		configSwitch(DECTECTOR_MODE_PARAM, 0.0f, 1.0f, 1.0f, "Dectector mode", {"Peak", "RMS"});
     95 		configSwitch(KNEE_PARAM, 0.0f, 1.0f, 1.0f, "Knee", {"Hard", "Soft"});
     96 		configBypass(LEFT_INPUT, LEFT_OUTPUT);
     97 		configBypass(RIGHT_INPUT, RIGHT_OUTPUT);
     98 
     99 		configInput(LEFT_INPUT, "Left signal");
    100 		configInput(SIDECHAIN_INPUT, "Sidechain");
    101 		configInput(THRESHOLD_INPUT, "Threshold CV");
    102 		configInput(RATIO_INPUT, "Ratio CV");
    103 		configInput(RIGHT_INPUT, "Right signal");
    104 		configInput(ATTACK_INPUT, "Attack CV");
    105 		configInput(RELEASE_INPUT, "Release CV");
    106 		configInput(INPUT_GAIN_INPUT, "Input gain CV");
    107 		configInput(OUTPUT_GAIN_INPUT, "Output gain CV");
    108 
    109 		configOutput(ENVELOPE_OUTPUT, "Envelope");
    110 		configOutput(LEFT_OUTPUT, "Left signal");
    111 		configOutput(RIGHT_OUTPUT, "Right signal");
    112 	}
    113 
    114 	void sampleRateChange() override;
    115 	json_t* saveToJson(json_t* root) override;
    116 	void loadFromJson(json_t* root) override;
    117 	bool active() override;
    118 	int channels() override;
    119 	void addChannel(int c) override;
    120 	void removeChannel(int c) override;
    121 	void modulate() override;
    122 	void modulateChannel(int c) override;
    123 	void processChannel(const ProcessArgs& args, int c) override;
    124 };
    125 
    126 } // namespace bogaudio