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.

93 lines
2.4KB

  1. #include "Template.hpp"
  2. namespace rack_plugin_PG_Instruments {
  3. #define BUFFER_SIZE 65536 * 2
  4. #define BUFFER_MASK (BUFFER_SIZE - 1)
  5. struct PGEcho : Module
  6. {
  7. enum ParamIds
  8. {
  9. TIME_PARAM,
  10. FEEDBACK_PARAM,
  11. NUM_PARAMS
  12. };
  13. enum InputIds
  14. {
  15. INPUT,
  16. NUM_INPUTS
  17. };
  18. enum OutputIds
  19. {
  20. OUTPUT,
  21. NUM_OUTPUTS
  22. };
  23. int reader;
  24. int writer;
  25. int offset;
  26. float buffer[BUFFER_SIZE];
  27. PGEcho() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, 0)
  28. {
  29. reader = 0;
  30. offset = BUFFER_SIZE >> 1;
  31. writer = offset;
  32. for(int i = 0; i < BUFFER_SIZE; i++)
  33. buffer[i] = 0.0f;
  34. }
  35. void step() override
  36. {
  37. int echoOffset = (int)(params[TIME_PARAM].value * BUFFER_SIZE);
  38. if (echoOffset != offset)
  39. {
  40. offset = echoOffset;
  41. writer = (reader - offset) & BUFFER_MASK;
  42. }
  43. float input = inputs[INPUT].value;
  44. outputs[OUTPUT].value = input + buffer[reader];
  45. buffer[writer] = input + buffer[writer] * params[FEEDBACK_PARAM].value;
  46. reader++;
  47. writer++;
  48. reader &= BUFFER_MASK;
  49. writer &= BUFFER_MASK;
  50. }
  51. };
  52. struct PGEchoWidget : ModuleWidget
  53. {
  54. PGEchoWidget(PGEcho *module) : ModuleWidget(module)
  55. {
  56. setPanel(SVG::load(assetPlugin(plugin, "res/PGEcho.svg")));
  57. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  58. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 0)));
  59. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  60. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 365)));
  61. addInput(Port::create<PJ301MPort>(Vec(30, 100), Port::INPUT, module, PGEcho::INPUT));
  62. addParam(ParamWidget::create<RoundBlackKnob>(Vec(70, 100), module, PGEcho::TIME_PARAM, 0.0f, 1.0f, 0.5f));
  63. addParam(ParamWidget::create<RoundBlackKnob>(Vec(110, 100), module, PGEcho::FEEDBACK_PARAM, 0.0f, 1.0f, 0.5f));
  64. addOutput(Port::create<PJ301MPort>(Vec(150, 100), Port::OUTPUT, module, PGEcho::OUTPUT));
  65. }
  66. };
  67. } // namespace rack_plugin_PG_Instruments
  68. using namespace rack_plugin_PG_Instruments;
  69. RACK_PLUGIN_MODEL_INIT(PG_Instruments, PGEcho) {
  70. Model *modelPGEcho = Model::create<PGEcho, PGEchoWidget>("PG-Instruments", "PGEcho", "PG Echo", DELAY_TAG);
  71. return modelPGEcho;
  72. }