You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.5KB

  1. #include "Clpr.hpp"
  2. void Clpr::onReset() {
  3. _modulationStep = modulationSteps;
  4. }
  5. void Clpr::step() {
  6. if (!(outputs[LEFT_OUTPUT].active || outputs[RIGHT_OUTPUT].active)) {
  7. return;
  8. }
  9. ++_modulationStep;
  10. if (_modulationStep >= modulationSteps) {
  11. _modulationStep = 0;
  12. _thresholdDb = params[THRESHOLD_PARAM].value;
  13. if (inputs[THRESHOLD_INPUT].active) {
  14. _thresholdDb *= clamp(inputs[THRESHOLD_INPUT].value / 10.0f, 0.0f, 1.0f);
  15. }
  16. _thresholdDb *= 30.0f;
  17. _thresholdDb -= 24.0f;
  18. float outGain = params[OUTPUT_GAIN_PARAM].value;
  19. if (inputs[OUTPUT_GAIN_INPUT].active) {
  20. outGain = clamp(outGain + inputs[OUTPUT_GAIN_INPUT].value / 5.0f, 0.0f, 1.0f);
  21. }
  22. outGain *= 24.0f;
  23. if (_outGain != outGain) {
  24. _outGain = outGain;
  25. _outLevel = decibelsToAmplitude(_outGain);
  26. }
  27. _softKnee = params[KNEE_PARAM].value > 0.97f;
  28. }
  29. float leftInput = inputs[LEFT_INPUT].value;
  30. float rightInput = inputs[RIGHT_INPUT].value;
  31. float env = fabsf(leftInput + rightInput);
  32. float detectorDb = amplitudeToDecibels(env / 5.0f);
  33. float compressionDb = _compressor.compressionDb(detectorDb, _thresholdDb, Compressor::maxEffectiveRatio, _softKnee);
  34. _amplifier.setLevel(-compressionDb);
  35. if (outputs[LEFT_OUTPUT].active) {
  36. outputs[LEFT_OUTPUT].value = _saturator.next(_amplifier.next(leftInput) * _outLevel);
  37. }
  38. if (outputs[RIGHT_OUTPUT].active) {
  39. outputs[RIGHT_OUTPUT].value = _saturator.next(_amplifier.next(rightInput) * _outLevel);
  40. }
  41. }
  42. struct ClprWidget : ModuleWidget {
  43. static constexpr int hp = 6;
  44. ClprWidget(Clpr* module) : ModuleWidget(module) {
  45. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  46. {
  47. SVGPanel *panel = new SVGPanel();
  48. panel->box.size = box.size;
  49. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Clpr.svg")));
  50. addChild(panel);
  51. }
  52. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  53. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  54. // generated by svg_widgets.rb
  55. auto thresholdParamPosition = Vec(26.0, 52.0);
  56. auto outputGainParamPosition = Vec(26.0, 134.0);
  57. auto kneeParamPosition = Vec(39.5, 199.5);
  58. auto leftInputPosition = Vec(16.0, 244.0);
  59. auto rightInputPosition = Vec(50.0, 244.0);
  60. auto thresholdInputPosition = Vec(16.0, 280.0);
  61. auto outputGainInputPosition = Vec(50.0, 280.0);
  62. auto leftOutputPosition = Vec(16.0, 320.0);
  63. auto rightOutputPosition = Vec(50.0, 320.0);
  64. // end generated by svg_widgets.rb
  65. addParam(ParamWidget::create<Knob38>(thresholdParamPosition, module, Clpr::THRESHOLD_PARAM, 0.0, 1.0, 0.8));
  66. addParam(ParamWidget::create<Knob38>(outputGainParamPosition, module, Clpr::OUTPUT_GAIN_PARAM, 0.0, 1.0, 0.0));
  67. addParam(ParamWidget::create<SliderSwitch2State14>(kneeParamPosition, module, Clpr::KNEE_PARAM, 0.95, 1.0, 0.0));
  68. addInput(Port::create<Port24>(leftInputPosition, Port::INPUT, module, Clpr::LEFT_INPUT));
  69. addInput(Port::create<Port24>(rightInputPosition, Port::INPUT, module, Clpr::RIGHT_INPUT));
  70. addInput(Port::create<Port24>(thresholdInputPosition, Port::INPUT, module, Clpr::THRESHOLD_INPUT));
  71. addInput(Port::create<Port24>(outputGainInputPosition, Port::INPUT, module, Clpr::OUTPUT_GAIN_INPUT));
  72. addOutput(Port::create<Port24>(leftOutputPosition, Port::OUTPUT, module, Clpr::LEFT_OUTPUT));
  73. addOutput(Port::create<Port24>(rightOutputPosition, Port::OUTPUT, module, Clpr::RIGHT_OUTPUT));
  74. }
  75. };
  76. RACK_PLUGIN_MODEL_INIT(Bogaudio, Clpr) {
  77. Model *modelClpr = createModel<Clpr, ClprWidget>("Bogaudio-Clpr", "CLPR", "clipper", DYNAMICS_TAG, DISTORTION_TAG);
  78. return modelClpr;
  79. }