LLFO.hpp (2733B)
1 #pragma once 2 3 #include "bogaudio.hpp" 4 #include "lfo_base.hpp" 5 6 using namespace bogaudio::dsp; 7 8 extern Model* modelLLFO; 9 10 namespace bogaudio { 11 12 struct LLFO : LFOBase { 13 enum ParamsIds { 14 FREQUENCY_PARAM, 15 SLOW_PARAM, 16 WAVE_PARAM, 17 OFFSET_PARAM, 18 SCALE_PARAM, 19 NUM_PARAMS 20 }; 21 22 enum InputsIds { 23 PITCH_INPUT, 24 RESET_INPUT, 25 NUM_INPUTS 26 }; 27 28 enum OutputsIds { 29 OUT_OUTPUT, 30 NUM_OUTPUTS 31 }; 32 33 enum LightsIds { 34 SINE_LIGHT, 35 RAMP_UP_LIGHT, 36 SQUARE_LIGHT, 37 TRIANGLE_LIGHT, 38 RAMP_DOWN_LIGHT, 39 PULSE_LIGHT, 40 STEPPED_LIGHT, 41 NUM_LIGHTS 42 }; 43 44 enum Wave { 45 UNINITIALIZED_WAVE, 46 SINE_WAVE, 47 TRIANGLE_WAVE, 48 RAMP_UP_WAVE, 49 RAMP_DOWN_WAVE, 50 SQUARE_WAVE, 51 PULSE_WAVE, 52 STEPPED_WAVE 53 }; 54 55 static constexpr float amplitude = 5.0f; 56 static constexpr float defaultSample = 0.0f; 57 static constexpr float defaultPulseWidth = -0.8510638; // 10% pulse. 58 static constexpr float defaultSmooth = 0.0f; 59 60 Wave _wave = UNINITIALIZED_WAVE; 61 float _offset = 0.0f; 62 float _scale = 0.0f; 63 float _sample = defaultSample; 64 float _pulseWidth = defaultPulseWidth; 65 float _smooth = defaultSmooth; 66 bool _resetOnWaveChange = false; 67 68 PositiveZeroCrossing _resetTrigger[maxChannels]; 69 Phasor _phasor[maxChannels]; 70 int _sampleSteps[maxChannels] {}; 71 int _sampleStep[maxChannels] {}; 72 float _currentSample[maxChannels] {}; 73 Smoother _smoother[maxChannels]; 74 75 SineTableOscillator _sine; 76 TriangleOscillator _triangle; 77 SawOscillator _ramp; 78 SquareOscillator _square; 79 SteppedRandomOscillator _stepped[maxChannels]; 80 bool _invert; 81 Phasor* _oscillator; 82 bool _samplingEnabled = false; 83 84 LLFO() 85 : LFOBase(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) 86 , _invert(false) 87 , _oscillator(&_sine) 88 { 89 configParam<LFOFrequencyParamQuantity>(FREQUENCY_PARAM, -5.0f, 8.0f, 0.0f, "Frequency", " Hz"); 90 configSwitch(WAVE_PARAM, 0.0f, 6.0f, 0.0f, "Waveform", {"Sine", "Triangle", "Ramp up", "Ramp down", "Square", "Pulse", "Stepped"}); 91 configButton(SLOW_PARAM, "Slow mode"); 92 configParam<OffsetParamQuantity>(OFFSET_PARAM, -1.0f, 1.0f, 0.0f, "Offset", " V", 0.0f, 5.0f); 93 configParam(SCALE_PARAM, 0.0f, 1.0f, 1.0f, "Scale", "%", 0.0f, 100.0f); 94 95 configInput(PITCH_INPUT, "Pitch (1V/octave)"); 96 configInput(RESET_INPUT, "Reset"); 97 98 configOutput(OUT_OUTPUT, "Signal"); 99 } 100 101 void reset() override; 102 void sampleRateChange() override; 103 json_t* saveToJson(json_t* root) override; 104 void loadFromJson(json_t* root) override; 105 bool active() override; 106 int channels() override; 107 void addChannel(int c) override; 108 void modulateAlways() override; 109 void modulate() override; 110 void modulateChannel(int c) override; 111 void processAlways(const ProcessArgs& args) override; 112 void processChannel(const ProcessArgs& args, int c) override; 113 }; 114 115 } // namespace bogaudio