BogaudioModules

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

EQS.cpp (2586B)


      1 
      2 #include "EQS.hpp"
      3 
      4 bool EQS::active() {
      5 	return outputs[LEFT_OUTPUT].isConnected() || outputs[RIGHT_OUTPUT].isConnected();
      6 }
      7 
      8 int EQS::channels() {
      9 	return inputs[LEFT_INPUT].getChannels();
     10 }
     11 
     12 void EQS::addChannel(int c) {
     13 	_engines[c] = new Engine();
     14 }
     15 
     16 void EQS::removeChannel(int c) {
     17 	delete _engines[c];
     18 	_engines[c] = NULL;
     19 }
     20 
     21 float EQS::knobToDb(Param& p) {
     22 	float v = clamp(p.getValue(), -1.0f, 1.0f);
     23 	if (v < 0.0f) {
     24 		return -v * bogaudio::dsp::Equalizer::cutDb;
     25 	}
     26 	return v * bogaudio::dsp::Equalizer::gainDb;
     27 }
     28 
     29 void EQS::modulate() {
     30 	_lowDb = knobToDb(params[LOW_PARAM]);
     31 	_midDb = knobToDb(params[MID_PARAM]);
     32 	_highDb = knobToDb(params[HIGH_PARAM]);
     33 }
     34 
     35 void EQS::modulateChannel(int c) {
     36 	float sr = APP->engine->getSampleRate();
     37 	_engines[c]->_left.setParams(
     38 		sr,
     39 		_lowDb,
     40 		_midDb,
     41 		_highDb
     42 	);
     43 	_engines[c]->_right.setParams(
     44 		sr,
     45 		_lowDb,
     46 		_midDb,
     47 		_highDb
     48 	);
     49 }
     50 
     51 void EQS::processAll(const ProcessArgs& args) {
     52 	outputs[LEFT_OUTPUT].setChannels(_channels);
     53 	outputs[RIGHT_OUTPUT].setChannels(_channels);
     54 }
     55 
     56 void EQS::processChannel(const ProcessArgs& args, int c) {
     57 	outputs[LEFT_OUTPUT].setVoltage(_engines[c]->_left.next(inputs[LEFT_INPUT].getVoltage(c)), c);
     58 	outputs[RIGHT_OUTPUT].setVoltage(_engines[c]->_right.next(inputs[RIGHT_INPUT].getVoltage(c)), c);
     59 }
     60 
     61 struct EQSWidget : BGModuleWidget {
     62 	static constexpr int hp = 6;
     63 
     64 	EQSWidget(EQS* module) {
     65 		setModule(module);
     66 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
     67 		setPanel(box.size, "EQS");
     68 		createScrews();
     69 
     70 		// generated by svg_widgets.rb
     71 		auto lowParamPosition = Vec(26.0, 53.0);
     72 		auto midParamPosition = Vec(26.0, 135.0);
     73 		auto highParamPosition = Vec(26.0, 217.0);
     74 
     75 		auto leftInputPosition = Vec(16.0, 279.0);
     76 		auto rightInputPosition = Vec(50.0, 279.0);
     77 
     78 		auto leftOutputPosition = Vec(16.0, 320.0);
     79 		auto rightOutputPosition = Vec(50.0, 320.0);
     80 		// end generated by svg_widgets.rb
     81 
     82 		addParam(createParam<Knob38>(lowParamPosition, module, EQS::LOW_PARAM));
     83 		addParam(createParam<Knob38>(midParamPosition, module, EQS::MID_PARAM));
     84 		addParam(createParam<Knob38>(highParamPosition, module, EQS::HIGH_PARAM));
     85 
     86 		addInput(createInput<Port24>(leftInputPosition, module, EQS::LEFT_INPUT));
     87 		addInput(createInput<Port24>(rightInputPosition, module, EQS::RIGHT_INPUT));
     88 
     89 		addOutput(createOutput<Port24>(leftOutputPosition, module, EQS::LEFT_OUTPUT));
     90 		addOutput(createOutput<Port24>(rightOutputPosition, module, EQS::RIGHT_OUTPUT));
     91 	}
     92 };
     93 
     94 Model* modelEQS = createModel<EQS, EQSWidget>("Bogaudio-EQS", "EQS", "Stereo 3-band equalizer", "Equalizer", "Polyphonic");