VCAmp.cpp (2133B)
1 2 #include "VCAmp.hpp" 3 #include "mixer.hpp" 4 5 void VCAmp::sampleRateChange() { 6 float sampleRate = APP->engine->getSampleRate(); 7 for (int c = 0; c < maxChannels; ++c) { 8 _levelSL[c].setParams(sampleRate, MixerChannel::levelSlewTimeMS, maxDecibels - minDecibels); 9 _rms[c].setSampleRate(sampleRate); 10 } 11 } 12 13 void VCAmp::processAll(const ProcessArgs& args) { 14 if (inputs[IN_INPUT].isConnected()) { 15 int n = inputs[IN_INPUT].getChannels(); 16 outputs[OUT_OUTPUT].setChannels(n); 17 float rmsSum = 0.0f; 18 for (int c = 0; c < n; ++c) { 19 float level = params[LEVEL_PARAM].getValue(); 20 if (inputs[CV_INPUT].isConnected()) { 21 level *= clamp(inputs[CV_INPUT].getPolyVoltage(c), 0.0f, 10.0f) / 10.0f; 22 } 23 level *= maxDecibels - minDecibels; 24 level += minDecibels; 25 _amplifier[c].setLevel(_levelSL[c].next(level)); 26 float out = _saturator[c].next(_amplifier[c].next(inputs[IN_INPUT].getVoltage(c))); 27 outputs[OUT_OUTPUT].setVoltage(out, c); 28 rmsSum += _rms[c].next(out / 5.0f); 29 } 30 _rmsLevel = rmsSum / (float)n; 31 } 32 else { 33 _rmsLevel = 0.0f; 34 } 35 } 36 37 struct VCAmpWidget : BGModuleWidget { 38 static constexpr int hp = 3; 39 40 VCAmpWidget(VCAmp* module) { 41 setModule(module); 42 box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT); 43 setPanel(box.size, "VCAmp"); 44 createScrews(); 45 46 // generated by svg_widgets.rb 47 auto levelParamPosition = Vec(13.5, 20.5); 48 49 auto cvInputPosition = Vec(10.5, 213.0); 50 auto inInputPosition = Vec(10.5, 248.0); 51 52 auto outOutputPosition = Vec(10.5, 286.0); 53 // end generated by svg_widgets.rb 54 55 auto slider = createParam<VUSlider>(levelParamPosition, module, VCAmp::LEVEL_PARAM); 56 if (module) { 57 dynamic_cast<VUSlider*>(slider)->setVULevel(&(module->_rmsLevel)); 58 } 59 addParam(slider); 60 61 addInput(createInput<Port24>(cvInputPosition, module, VCAmp::CV_INPUT)); 62 addInput(createInput<Port24>(inInputPosition, module, VCAmp::IN_INPUT)); 63 64 addOutput(createOutput<Port24>(outOutputPosition, module, VCAmp::OUT_OUTPUT)); 65 } 66 }; 67 68 Model* modelVCAmp = bogaudio::createModel<VCAmp, VCAmpWidget>("Bogaudio-VCAmp", "VCAMP", "Voltage controlled amplifier with 12dB gain", "VCA", "Polyphonic");