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