BogaudioModules

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

commit 375929b34d98e99720a78dc5701083b1e25b8953
parent e683255d304140ee39cb1e2d19ef7ee2d93a865b
Author: Matt Demanett <matt@demanett.net>
Date:   Fri, 13 Sep 2019 23:00:20 -0400

Poly: VCA, VCAMP.

Diffstat:
Msrc/Pan.cpp | 4++--
Msrc/Pan.hpp | 4++--
Msrc/VCA.cpp | 30++++++++++++++++++++----------
Msrc/VCA.hpp | 12++++++------
Msrc/VCAmp.cpp | 36+++++++++++++++++++++++-------------
Msrc/VCAmp.hpp | 14++++++++------
6 files changed, 61 insertions(+), 39 deletions(-)

diff --git a/src/Pan.cpp b/src/Pan.cpp @@ -35,9 +35,9 @@ void Pan::processChannel(const ProcessArgs& args, int c) { float l2 = 0.0f, r2 = 0.0f; _panner2[c].next(inputs[IN2_INPUT].getPolyVoltage(c), l2, r2); outputs[L_OUTPUT].setChannels(_channels); - outputs[L_OUTPUT].setVoltage(_saturatorLeft.next(l1 + l2), c); + outputs[L_OUTPUT].setVoltage(_saturatorLeft[c].next(l1 + l2), c); outputs[R_OUTPUT].setChannels(_channels); - outputs[R_OUTPUT].setVoltage(_saturatorRight.next(r1 + r2), c); + outputs[R_OUTPUT].setVoltage(_saturatorRight[c].next(r1 + r2), c); } struct PanWidget : ModuleWidget { diff --git a/src/Pan.hpp b/src/Pan.hpp @@ -38,8 +38,8 @@ struct Pan : BGModule { Panner _panner2[maxChannels]; bogaudio::dsp::SlewLimiter _slew1[maxChannels]; bogaudio::dsp::SlewLimiter _slew2[maxChannels]; - Saturator _saturatorLeft; - Saturator _saturatorRight; + Saturator _saturatorLeft[maxChannels]; + Saturator _saturatorRight[maxChannels]; Pan() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); diff --git a/src/VCA.cpp b/src/VCA.cpp @@ -7,32 +7,42 @@ bool VCA::LevelParamQuantity::isLinear() { void VCA::sampleRateChange() { float sampleRate = APP->engine->getSampleRate(); - _levelSL1.setParams(sampleRate, 5.0f, 1.0f); - _levelSL2.setParams(sampleRate, 5.0f, 1.0f); + for (int c = 0; c < maxChannels; ++c) { + _levelSL1[c].setParams(sampleRate, 5.0f, 1.0f); + _levelSL2[c].setParams(sampleRate, 5.0f, 1.0f); + } } -void VCA::processChannel(const ProcessArgs& args, int _c) { +void VCA::processChannel(const ProcessArgs& args, int c) { + assert(c == 0); + bool linear = isLinear(); lights[LINEAR_LIGHT].value = linear; channelStep(inputs[IN1_INPUT], outputs[OUT1_OUTPUT], params[LEVEL1_PARAM], inputs[CV1_INPUT], _amplifier1, _levelSL1, linear); channelStep(inputs[IN2_INPUT], outputs[OUT2_OUTPUT], params[LEVEL2_PARAM], inputs[CV2_INPUT], _amplifier2, _levelSL2, linear); } -void VCA::channelStep(Input& input, Output& output, Param& knob, Input& cv, Amplifier& amplifier, bogaudio::dsp::SlewLimiter& levelSL, bool linear) { - if (input.isConnected() && output.isConnected()) { +void VCA::channelStep(Input& input, Output& output, Param& knob, Input& cv, Amplifier* amplifier, bogaudio::dsp::SlewLimiter* levelSL, bool linear) { + if (!(input.isConnected() && output.isConnected())) { + return; + } + + int n = input.getChannels(); + output.setChannels(n); + for (int c = 0; c < n; ++c) { float level = knob.getValue(); if (cv.isConnected()) { - level *= clamp(cv.getVoltage() / 10.0f, 0.0f, 1.0f); + level *= clamp(cv.getPolyVoltage(c) / 10.0f, 0.0f, 1.0f); } - level = levelSL.next(level); + level = levelSL[c].next(level); if (linear) { - output.setVoltage(level * input.getVoltageSum()); + output.setVoltage(level * input.getVoltage(c), c); } else { level = 1.0f - level; level *= Amplifier::minDecibels; - amplifier.setLevel(level); - output.setVoltage(amplifier.next(input.getVoltageSum())); + amplifier[c].setLevel(level); + output.setVoltage(amplifier[c].next(input.getVoltage(c)), c); } } } diff --git a/src/VCA.hpp b/src/VCA.hpp @@ -36,10 +36,10 @@ struct VCA : BGModule { NUM_LIGHTS }; - Amplifier _amplifier1; - bogaudio::dsp::SlewLimiter _levelSL1; - Amplifier _amplifier2; - bogaudio::dsp::SlewLimiter _levelSL2; + Amplifier _amplifier1[maxChannels]; + bogaudio::dsp::SlewLimiter _levelSL1[maxChannels]; + Amplifier _amplifier2[maxChannels]; + bogaudio::dsp::SlewLimiter _levelSL2[maxChannels]; struct LevelParamQuantity : AmpliferParamQuantity { bool isLinear() override; @@ -56,8 +56,8 @@ struct VCA : BGModule { inline bool isLinear() { return params[LINEAR_PARAM].getValue() > 0.5f; } void sampleRateChange() override; - void processChannel(const ProcessArgs& args, int _c) override; - void channelStep(Input& input, Output& output, Param& knob, Input& cv, Amplifier& amplifier, bogaudio::dsp::SlewLimiter& levelSL, bool linear); + void processChannel(const ProcessArgs& args, int c) override; + void channelStep(Input& input, Output& output, Param& knob, Input& cv, Amplifier* amplifier, bogaudio::dsp::SlewLimiter* levelSL, bool linear); }; } // namespace bogaudio diff --git a/src/VCAmp.cpp b/src/VCAmp.cpp @@ -4,25 +4,35 @@ void VCAmp::sampleRateChange() { float sampleRate = APP->engine->getSampleRate(); - _levelSL.setParams(sampleRate, MixerChannel::levelSlewTimeMS, maxDecibels - minDecibels); - _rms.setSampleRate(sampleRate); + for (int c = 0; c < maxChannels; ++c) { + _levelSL[c].setParams(sampleRate, MixerChannel::levelSlewTimeMS, maxDecibels - minDecibels); + _rms[c].setSampleRate(sampleRate); + } } -void VCAmp::processChannel(const ProcessArgs& args, int _c) { +void VCAmp::processChannel(const ProcessArgs& args, int c) { + assert(c == 0); + if (inputs[IN_INPUT].isConnected()) { - float level = params[LEVEL_PARAM].getValue(); - if (inputs[CV_INPUT].isConnected()) { - level *= clamp(inputs[CV_INPUT].getVoltage(), 0.0f, 10.0f) / 10.0f; + int n = inputs[IN_INPUT].getChannels(); + outputs[OUT_OUTPUT].setChannels(n); + float rmsSum = 0.0f; + for (; c < n; ++c) { + float level = params[LEVEL_PARAM].getValue(); + if (inputs[CV_INPUT].isConnected()) { + level *= clamp(inputs[CV_INPUT].getPolyVoltage(c), 0.0f, 10.0f) / 10.0f; + } + level *= maxDecibels - minDecibels; + level += minDecibels; + _amplifier[c].setLevel(_levelSL[c].next(level)); + float out = _saturator[c].next(_amplifier[c].next(inputs[IN_INPUT].getVoltage(c))); + outputs[OUT_OUTPUT].setVoltage(out, c); + rmsSum += _rms[c].next(out / 5.0f); } - level *= maxDecibels - minDecibels; - level += minDecibels; - _amplifier.setLevel(_levelSL.next(level)); - float out = _saturator.next(_amplifier.next(inputs[IN_INPUT].getVoltageSum())); - outputs[OUT_OUTPUT].setVoltage(out); - _rmsLevel = _rms.next(out / 5.0f); + _rmsLevel = rmsSum / (float)n; } else { - _rmsLevel = _rms.next(0.0f); + _rmsLevel = 0.0f; } } diff --git a/src/VCAmp.hpp b/src/VCAmp.hpp @@ -32,10 +32,10 @@ struct VCAmp : BGModule { const float maxDecibels = 12.0f; const float minDecibels = Amplifier::minDecibels; - Amplifier _amplifier; - bogaudio::dsp::SlewLimiter _levelSL; - Saturator _saturator; - RootMeanSquare _rms; + Amplifier _amplifier[maxChannels]; + bogaudio::dsp::SlewLimiter _levelSL[maxChannels]; + Saturator _saturator[maxChannels]; + RootMeanSquare _rms[maxChannels]; float _rmsLevel = 0.0f; VCAmp() { @@ -43,11 +43,13 @@ struct VCAmp : BGModule { configParam(LEVEL_PARAM, 0.0f, 1.0f, fabs(minDecibels) / (maxDecibels - minDecibels), "Level", " dB", 0.0f, maxDecibels - minDecibels, minDecibels); sampleRateChange(); - _rms.setSensitivity(0.05f); + for (int c = 0; c < maxChannels; ++c) { + _rms[c].setSensitivity(0.05f); + } } void sampleRateChange() override; - void processChannel(const ProcessArgs& args, int _c) override; + void processChannel(const ProcessArgs& args, int c) override; }; } // namespace bogaudio