Nsgt.hpp (2343B)
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* modelNsgt; 10 11 namespace bogaudio { 12 13 struct Nsgt : BGModule { 14 enum ParamsIds { 15 THRESHOLD_PARAM, 16 RATIO_PARAM, 17 KNEE_PARAM, 18 NUM_PARAMS 19 }; 20 21 enum InputsIds { 22 LEFT_INPUT, 23 RIGHT_INPUT, 24 THRESHOLD_INPUT, 25 RATIO_INPUT, 26 NUM_INPUTS 27 }; 28 29 enum OutputsIds { 30 LEFT_OUTPUT, 31 RIGHT_OUTPUT, 32 NUM_OUTPUTS 33 }; 34 35 struct Engine { 36 float thresholdDb = 0.0f; 37 float ratio = 0.0f; 38 float ratioKnob = -1.0f; 39 float lastEnv = 0.0f; 40 41 bogaudio::dsp::SlewLimiter attackSL; 42 bogaudio::dsp::SlewLimiter releaseSL; 43 RootMeanSquare detector; 44 NoiseGate noiseGate; 45 Amplifier amplifier; 46 Saturator saturator; 47 48 void sampleRateChange(); 49 }; 50 51 static constexpr float defaultAttackMs = 150.0f; 52 static constexpr float maxAttackMs = 500.0f; 53 static constexpr float defaultReleaseMs = 600.0f; 54 static constexpr float maxReleaseMs = 2000.0f; 55 56 Engine* _engines[maxChannels] {}; 57 bool _softKnee = true; 58 float _attackMs = defaultAttackMs; 59 float _releaseMs = defaultReleaseMs; 60 float _thresholdRange = 1.0f; 61 62 struct ThresholdParamQuantity : ParamQuantity { 63 float getDisplayValue() override; 64 void setDisplayValue(float v) override; 65 }; 66 67 Nsgt() { 68 config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS); 69 configParam<ThresholdParamQuantity>(THRESHOLD_PARAM, 0.0f, 1.0f, 0.8f, "Threshold", " dB"); 70 configParam<DynamicsRatioParamQuantity>(RATIO_PARAM, 0.0f, 1.0f, 0.55159f, "Ratio"); 71 configSwitch(KNEE_PARAM, 0.0f, 1.0f, 1.0f, "Knee", {"Hard", "Soft"}); 72 configBypass(LEFT_INPUT, LEFT_OUTPUT); 73 configBypass(RIGHT_INPUT, RIGHT_OUTPUT); 74 75 configInput(LEFT_INPUT, "Left signal"); 76 configInput(RIGHT_INPUT, "Right signal"); 77 configInput(THRESHOLD_INPUT, "Threshold CV"); 78 configInput(RATIO_INPUT, "Ratio CV"); 79 80 configOutput(LEFT_OUTPUT, "Left signal"); 81 configOutput(RIGHT_OUTPUT, "Right signal"); 82 } 83 84 void sampleRateChange() override; 85 json_t* saveToJson(json_t* root) override; 86 void loadFromJson(json_t* root) override; 87 bool active() override; 88 int channels() override; 89 void addChannel(int c) override; 90 void removeChannel(int c) override; 91 void modulate() override; 92 void modulateChannel(int c) override; 93 void processChannel(const ProcessArgs& args, int _c) override; 94 }; 95 96 } // namespace bogaudio