BogaudioModules

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

SampleHold.hpp (2430B)


      1 #pragma once
      2 
      3 #include "bogaudio.hpp"
      4 #include "dsp/noise.hpp"
      5 
      6 using namespace bogaudio::dsp;
      7 
      8 extern Model* modelSampleHold;
      9 
     10 namespace bogaudio {
     11 
     12 struct SampleHold : BGModule {
     13 	enum ParamIds {
     14 		TRIGGER1_PARAM,
     15 		TRIGGER2_PARAM,
     16 		TRACK1_PARAM,
     17 		TRACK2_PARAM,
     18 		INVERT1_PARAM,
     19 		INVERT2_PARAM,
     20 		NUM_PARAMS
     21 	};
     22 
     23 	enum InputsIds {
     24 		TRIGGER1_INPUT,
     25 		IN1_INPUT,
     26 		TRIGGER2_INPUT,
     27 		IN2_INPUT,
     28 		NUM_INPUTS
     29 	};
     30 
     31 	enum OutputIds {
     32 		OUT1_OUTPUT,
     33 		OUT2_OUTPUT,
     34 		NUM_OUTPUTS
     35 	};
     36 
     37 	enum NoiseType {
     38 		WHITE_NOISE_TYPE,
     39 		BLUE_NOISE_TYPE,
     40 		PINK_NOISE_TYPE,
     41 		RED_NOISE_TYPE
     42 	};
     43 
     44 	static constexpr float maxSmoothMS = 10000.0f;
     45 
     46 	Trigger _trigger1[maxChannels];
     47 	Trigger _trigger2[maxChannels];
     48 	float _value1[maxChannels] {};
     49 	float _value2[maxChannels] {};
     50 	BlueNoiseGenerator _blue;
     51 	WhiteNoiseGenerator _white;
     52 	PinkNoiseGenerator _pink;
     53 	RedNoiseGenerator _red;
     54 	NoiseType _noiseType = WHITE_NOISE_TYPE;
     55 	float _rangeOffset = 1.0f;
     56 	float _rangeScale = 5.0f;
     57 	int _polyInputID = TRIGGER1_INPUT;
     58 	float _smoothMS = 0.0f;
     59 	SlewLimiter _outputSL1[maxChannels];
     60 	SlewLimiter _outputSL2[maxChannels];
     61 
     62 	SampleHold() {
     63 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
     64 		configButton(TRIGGER1_PARAM, "Trigger 1");
     65 		configButton(TRIGGER2_PARAM, "Trigger 2");
     66 		configSwitch(TRACK1_PARAM, 0.0f, 1.0f, 0.0f, "Track 1", {"Disabled", "Enabled"});
     67 		configSwitch(TRACK2_PARAM, 0.0f, 1.0f, 0.0f, "Track 2", {"Disabled", "Enabled"});
     68 		configSwitch(INVERT1_PARAM, 0.0f, 1.0f, 0.0f, "Invert 1", {"Disabled", "Enabled"});
     69 		configSwitch(INVERT2_PARAM, 0.0f, 1.0f, 0.0f, "Invert 2", {"Disabled", "Enabled"});
     70 
     71 		configInput(TRIGGER1_INPUT, "Trigger 1");
     72 		configInput(IN1_INPUT, "Signal 1");
     73 		configInput(TRIGGER2_INPUT, "Trigger 2");
     74 		configInput(IN2_INPUT, "Signal 2");
     75 	}
     76 
     77 	void reset() override;
     78 	json_t* saveToJson(json_t* root) override;
     79 	void loadFromJson(json_t* root) override;
     80 	void modulate() override;
     81 	void processAll(const ProcessArgs& args) override;
     82 	int sectionChannels(
     83 		Input& triggerInput,
     84 		Input* altTriggerInput,
     85 		Input& in
     86 	);
     87 	void modulateSection(
     88 		Input& triggerInput,
     89 		Input* altTriggerInput,
     90 		Input& in,
     91 		SlewLimiter* _outputSL
     92 	);
     93 	void processSection(
     94 		Param& trackParam,
     95 		Param& invertParam,
     96 		Trigger* trigger,
     97 		Param& triggerParam,
     98 		Input& triggerInput,
     99 		Input* altTriggerInput,
    100 		Input& in,
    101 		float* value,
    102 		SlewLimiter* _outputSL,
    103 		Output& out
    104 	);
    105 	float noise();
    106 };
    107 
    108 } // namespace bogaudio