PEQ.cpp (6126B)
1 2 #include "PEQ.hpp" 3 4 void PEQ::sampleRateChange() { 5 float sr = APP->engine->getSampleRate(); 6 for (int c = 0; c < _channels; ++c) { 7 _engines[c]->setSampleRate(sr); 8 } 9 } 10 11 bool PEQ::active() { 12 return outputs[OUT_OUTPUT].isConnected(); 13 } 14 15 int PEQ::channels() { 16 return inputs[IN_INPUT].getChannels(); 17 } 18 19 void PEQ::addChannel(int c) { 20 const int n = 3; 21 _engines[c] = new PEQEngine(n); 22 for (int i = 0; i < n; ++i) { 23 _engines[c]->configChannel( 24 i, 25 c, 26 params[A_LEVEL_PARAM + i*4], 27 params[A_FREQUENCY_PARAM + i*4], 28 params[A_CV_PARAM + i*4], 29 NULL, 30 params[A_BANDWIDTH_PARAM + i*4], 31 inputs[A_LEVEL_INPUT + i], 32 inputs[A_FREQUENCY_INPUT + i], 33 inputs[ALL_CV_INPUT], 34 &inputs[A_BANDWIDTH_INPUT + i] 35 ); 36 } 37 _engines[c]->setSampleRate(APP->engine->getSampleRate()); 38 } 39 40 void PEQ::removeChannel(int c) { 41 delete _engines[c]; 42 _engines[c] = NULL; 43 } 44 45 void PEQ::modulate() { 46 auto lowMode = params[A_MODE_PARAM].getValue() > 0.5f ? MultimodeFilter::LOWPASS_MODE : MultimodeFilter::BANDPASS_MODE; 47 auto highMode = params[C_MODE_PARAM].getValue() > 0.5f ? MultimodeFilter::HIGHPASS_MODE : MultimodeFilter::BANDPASS_MODE; 48 for (int c = 0; c < _channels; ++c) { 49 PEQEngine& e = *_engines[c]; 50 e.setLowFilterMode(lowMode); 51 e.setHighFilterMode(highMode); 52 e.modulate(); 53 } 54 } 55 56 void PEQ::processAlways(const ProcessArgs& args) { 57 outputs[OUT_OUTPUT].setChannels(_channels); 58 std::fill(_rmsSums, _rmsSums + 3, 0.0f); 59 } 60 61 void PEQ::processChannel(const ProcessArgs& args, int c) { 62 outputs[OUT_OUTPUT].setVoltage(_engines[c]->next(inputs[IN_INPUT].getVoltage(c), _rmsSums), c); 63 } 64 65 void PEQ::postProcessAlways(const ProcessArgs& args) { 66 lights[A_LIGHT].value = _rmsSums[0] * _inverseChannels; 67 lights[B_LIGHT].value = _rmsSums[1] * _inverseChannels; 68 lights[C_LIGHT].value = _rmsSums[2] * _inverseChannels; 69 } 70 71 struct PEQWidget : BGModuleWidget { 72 static constexpr int hp = 10; 73 74 PEQWidget(PEQ* module) { 75 setModule(module); 76 box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT); 77 setPanel(box.size, "PEQ"); 78 createScrews(); 79 80 // generated by svg_widgets.rb 81 auto aLevelParamPosition = Vec(21.0, 36.5); 82 auto aFrequencyParamPosition = Vec(67.0, 36.5); 83 auto aBandwidthParamPosition = Vec(122.0, 29.0); 84 auto aCvParamPosition = Vec(122.0, 67.0); 85 auto aModeParamPosition = Vec(131.5, 50.5); 86 auto bLevelParamPosition = Vec(21.0, 104.5); 87 auto bFrequencyParamPosition = Vec(67.0, 104.5); 88 auto bBandwidthParamPosition = Vec(122.0, 100.0); 89 auto bCvParamPosition = Vec(122.0, 133.0); 90 auto cLevelParamPosition = Vec(21.0, 170.5); 91 auto cFrequencyParamPosition = Vec(67.0, 170.5); 92 auto cBandwidthParamPosition = Vec(122.0, 163.0); 93 auto cCvParamPosition = Vec(122.0, 201.0); 94 auto cModeParamPosition = Vec(131.5, 184.5); 95 96 auto aLevelInputPosition = Vec(15.0, 231.0); 97 auto bLevelInputPosition = Vec(47.0, 231.0); 98 auto cLevelInputPosition = Vec(79.0, 231.0); 99 auto allCvInputPosition = Vec(111.0, 231.0); 100 auto aFrequencyInputPosition = Vec(15.0, 275.0); 101 auto bFrequencyInputPosition = Vec(47.0, 275.0); 102 auto cFrequencyInputPosition = Vec(79.0, 275.0); 103 auto inInputPosition = Vec(111.0, 275.0); 104 auto aBandwidthInputPosition = Vec(15.0, 319.0); 105 auto bBandwidthInputPosition = Vec(47.0, 319.0); 106 auto cBandwidthInputPosition = Vec(79.0, 319.0); 107 108 auto outOutputPosition = Vec(111.0, 319.0); 109 110 auto aLightPosition = Vec(5.5, 43.0); 111 auto bLightPosition = Vec(5.5, 111.0); 112 auto cLightPosition = Vec(5.5, 177.0); 113 // end generated by svg_widgets.rb 114 115 addParam(createParam<Knob29>(aLevelParamPosition, module, PEQ::A_LEVEL_PARAM)); 116 addParam(createParam<Knob29>(aFrequencyParamPosition, module, PEQ::A_FREQUENCY_PARAM)); 117 addParam(createParam<Knob16>(aBandwidthParamPosition, module, PEQ::A_BANDWIDTH_PARAM)); 118 addParam(createParam<Knob16>(aCvParamPosition, module, PEQ::A_CV_PARAM)); 119 addParam(createParam<IndicatorButtonGreen9>(aModeParamPosition, module, PEQ::A_MODE_PARAM)); 120 addParam(createParam<Knob29>(bLevelParamPosition, module, PEQ::B_LEVEL_PARAM)); 121 addParam(createParam<Knob29>(bFrequencyParamPosition, module, PEQ::B_FREQUENCY_PARAM)); 122 addParam(createParam<Knob16>(bBandwidthParamPosition, module, PEQ::B_BANDWIDTH_PARAM)); 123 addParam(createParam<Knob16>(bCvParamPosition, module, PEQ::B_CV_PARAM)); 124 addParam(createParam<Knob29>(cLevelParamPosition, module, PEQ::C_LEVEL_PARAM)); 125 addParam(createParam<Knob29>(cFrequencyParamPosition, module, PEQ::C_FREQUENCY_PARAM)); 126 addParam(createParam<Knob16>(cBandwidthParamPosition, module, PEQ::C_BANDWIDTH_PARAM)); 127 addParam(createParam<Knob16>(cCvParamPosition, module, PEQ::C_CV_PARAM)); 128 addParam(createParam<IndicatorButtonGreen9>(cModeParamPosition, module, PEQ::C_MODE_PARAM)); 129 130 addInput(createInput<Port24>(aLevelInputPosition, module, PEQ::A_LEVEL_INPUT)); 131 addInput(createInput<Port24>(bLevelInputPosition, module, PEQ::B_LEVEL_INPUT)); 132 addInput(createInput<Port24>(cLevelInputPosition, module, PEQ::C_LEVEL_INPUT)); 133 addInput(createInput<Port24>(allCvInputPosition, module, PEQ::ALL_CV_INPUT)); 134 addInput(createInput<Port24>(aFrequencyInputPosition, module, PEQ::A_FREQUENCY_INPUT)); 135 addInput(createInput<Port24>(bFrequencyInputPosition, module, PEQ::B_FREQUENCY_INPUT)); 136 addInput(createInput<Port24>(cFrequencyInputPosition, module, PEQ::C_FREQUENCY_INPUT)); 137 addInput(createInput<Port24>(inInputPosition, module, PEQ::IN_INPUT)); 138 addInput(createInput<Port24>(aBandwidthInputPosition, module, PEQ::A_BANDWIDTH_INPUT)); 139 addInput(createInput<Port24>(bBandwidthInputPosition, module, PEQ::B_BANDWIDTH_INPUT)); 140 addInput(createInput<Port24>(cBandwidthInputPosition, module, PEQ::C_BANDWIDTH_INPUT)); 141 142 addOutput(createOutput<Port24>(outOutputPosition, module, PEQ::OUT_OUTPUT)); 143 144 addChild(createLight<BGSmallLight<GreenLight>>(aLightPosition, module, PEQ::A_LIGHT)); 145 addChild(createLight<BGSmallLight<GreenLight>>(bLightPosition, module, PEQ::B_LIGHT)); 146 addChild(createLight<BGSmallLight<GreenLight>>(cLightPosition, module, PEQ::C_LIGHT)); 147 } 148 }; 149 150 Model* modelPEQ = createModel<PEQ, PEQWidget>("Bogaudio-PEQ", "PEQ", "3-channel parametric equalizer", "Filter", "Polyphonic");