BogaudioModules

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

FourFO.hpp (3958B)


      1 #pragma once
      2 
      3 #include "bogaudio.hpp"
      4 #include "lfo_base.hpp"
      5 
      6 using namespace bogaudio::dsp;
      7 
      8 extern Model* modelFourFO;
      9 
     10 namespace bogaudio {
     11 
     12 struct FourFO : LFOBase {
     13 	enum ParamsIds {
     14 		FREQUENCY_PARAM,
     15 		WAVE_PARAM,
     16 		SLOW_PARAM,
     17 		SAMPLE_PWM_PARAM,
     18 		SMOOTH_PARAM,
     19 		OFFSET_PARAM,
     20 		SCALE_PARAM,
     21 		PHASE0_PARAM,
     22 		PHASE1_PARAM,
     23 		PHASE2_PARAM,
     24 		PHASE3_PARAM,
     25 		NUM_PARAMS
     26 	};
     27 
     28 	enum InputsIds {
     29 		SAMPLE_PWM_INPUT,
     30 		SMOOTH_INPUT,
     31 		OFFSET_INPUT,
     32 		SCALE_INPUT,
     33 		PITCH_INPUT,
     34 		RESET_INPUT,
     35 		PHASE0_INPUT,
     36 		PHASE1_INPUT,
     37 		PHASE2_INPUT,
     38 		PHASE3_INPUT,
     39 		NUM_INPUTS
     40 	};
     41 
     42 	enum OutputsIds {
     43 		PHASE0_OUTPUT,
     44 		PHASE1_OUTPUT,
     45 		PHASE2_OUTPUT,
     46 		PHASE3_OUTPUT,
     47 		NUM_OUTPUTS
     48 	};
     49 
     50 	enum Wave {
     51 		NO_WAVE,
     52 		RAMP_UP_WAVE,
     53 		RAMP_DOWN_WAVE,
     54 		SINE_WAVE,
     55 		TRIANGLE_WAVE,
     56 		SQUARE_WAVE,
     57 		STEPPED_WAVE
     58 	};
     59 
     60 	struct Engine {
     61 		int sampleSteps = 1;
     62 		int sampleStep = 0;
     63 		float offset = 0.0f;
     64 		float scale = 0.0f;
     65 		PositiveZeroCrossing resetTrigger;
     66 
     67 		Phasor phasor;
     68 		SineTableOscillator sine;
     69 		TriangleOscillator triangle;
     70 		SawOscillator ramp;
     71 		SquareOscillator square;
     72 		SteppedRandomOscillator stepped;
     73 
     74 		Phasor::phase_delta_t phase3Offset = 0.0f;
     75 		Phasor::phase_delta_t phase2Offset = 0.0f;
     76 		Phasor::phase_delta_t phase1Offset = 0.0f;
     77 		Phasor::phase_delta_t phase0Offset = 0.0f;
     78 
     79 		float phase3Sample = 0.0f;
     80 		float phase2Sample = 0.0f;
     81 		float phase1Sample = 0.0f;
     82 		float phase0Sample = 0.0f;
     83 
     84 		bool phase3Active = false;
     85 		bool phase2Active = false;
     86 		bool phase1Active = false;
     87 		bool phase0Active = false;
     88 
     89 		Smoother phase3Smoother;
     90 		Smoother phase2Smoother;
     91 		Smoother phase1Smoother;
     92 		Smoother phase0Smoother;
     93 
     94 		void reset();
     95 		void sampleRateChange();
     96 	};
     97 
     98 	const float amplitude = 5.0f;
     99 	Wave _wave = NO_WAVE;
    100 	Engine* _engines[maxChannels] {};
    101 
    102 	FourFO() : LFOBase(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {
    103 		configParam<LFOFrequencyParamQuantity>(FREQUENCY_PARAM, -5.0f, 8.0f, 0.0, "Frequency", " Hz");
    104 		configSwitch(WAVE_PARAM, 1.0, 6.0, 3.0, "Waveform", {"Ramp up", "Ramp down", "Sine", "Triangle", "Square", "Stepped"});
    105 		paramQuantities[WAVE_PARAM]->snapEnabled = true;
    106 		configButton(SLOW_PARAM, "Slow");
    107 		configParam(SAMPLE_PWM_PARAM, -1.0, 1.0, 0.0, "Width", "%", 0.0f, 100.0f);
    108 		configParam(SMOOTH_PARAM, 0.0f, 1.0f, 0.0f, "Smoothing", "%", 0.0f, 100.0f);
    109 		configParam<OffsetParamQuantity>(OFFSET_PARAM, -1.0, 1.0, 0.0, "Offset", " V", 0.0f, 5.0f);
    110 		configParam(SCALE_PARAM, 0.0, 1.0, 1.0, "Scale", "%", 0.0f, 100.0f);
    111 		configParam(PHASE3_PARAM, -1.0, 1.0, 0.0, "Phase 270", "º", 0.0f, 180.0f);
    112 		configParam(PHASE2_PARAM, -1.0, 1.0, 0.0, "Phase 180", "º", 0.0f, 180.0f);
    113 		configParam(PHASE1_PARAM, -1.0, 1.0, 0.0, "Phase 90", "º", 0.0f, 180.0f);
    114 		configParam(PHASE0_PARAM, -1.0, 1.0, 0.0f, "Phase 0", "º", 0.0f, 180.0f);
    115 
    116 		configInput(SAMPLE_PWM_INPUT, "Sample/PWM CV");
    117 		configInput(SMOOTH_INPUT, "Smoothing CV");
    118 		configInput(OFFSET_INPUT, "Offset CV");
    119 		configInput(SCALE_INPUT, "Scale CV");
    120 		configInput(PITCH_INPUT, "Pitch (1V/octave)");
    121 		configInput(RESET_INPUT, "Reset");
    122 		configInput(PHASE0_INPUT, "Phase 0 CV");
    123 		configInput(PHASE1_INPUT, "Phase 1 CV");
    124 		configInput(PHASE2_INPUT, "Phase 2 CV");
    125 		configInput(PHASE3_INPUT, "Phase 3 CV");
    126 
    127 		configOutput(PHASE0_OUTPUT, "Phase 0");
    128 		configOutput(PHASE1_OUTPUT, "Phase 1");
    129 		configOutput(PHASE2_OUTPUT, "Phase 2");
    130 		configOutput(PHASE3_OUTPUT, "Phase 3");
    131 	}
    132 
    133 	void reset() override;
    134 	void sampleRateChange() override;
    135 	bool active() override;
    136 	int channels() override;
    137 	void addChannel(int c) override;
    138 	void removeChannel(int c) override;
    139 	void modulate() override;
    140 	void modulateChannel(int c) override;
    141 	void processChannel(const ProcessArgs& args, int c) override;
    142 	Phasor::phase_delta_t phaseOffset(int c, Param& p, Input& i, Phasor::phase_delta_t baseOffset);
    143 	void updateOutput(int c, bool useSample, Output& output, Phasor::phase_delta_t& offset, float& sample, bool& active, Smoother& smoother);
    144 };
    145 
    146 } // namespace bogaudio