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.

142 lines
3.4KB

  1. #include "Bidoo.hpp"
  2. #include "BidooComponents.hpp"
  3. #include "dsp/digital.hpp"
  4. #include "dsp/ringbuffer.hpp"
  5. #include "dep/filters/pitchshifter.h"
  6. #include "dsp/fir.hpp"
  7. #define BUFF_SIZE 256
  8. #define OVERLAP 4
  9. using namespace std;
  10. namespace rack_plugin_Bidoo {
  11. struct CURT : Module {
  12. enum ParamIds {
  13. PITCH_PARAM,
  14. MODE_PARAM,
  15. NUM_PARAMS
  16. };
  17. enum InputIds {
  18. INPUT,
  19. PITCH_INPUT,
  20. NUM_INPUTS
  21. };
  22. enum OutputIds {
  23. OUTPUT,
  24. NUM_OUTPUTS
  25. };
  26. enum LightIds {
  27. NUM_LIGHTS
  28. };
  29. DoubleRingBuffer<float,BUFF_SIZE> in_Buffer;
  30. DoubleRingBuffer<float, 2*BUFF_SIZE> out_Buffer;
  31. float bins[OVERLAP][BUFF_SIZE];
  32. int index=-1;
  33. int readSteps=0;
  34. int writeSteps=0;
  35. SchmittTrigger modeTrigger;
  36. bool mode=0;
  37. CURT() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
  38. for(int i=0; i<OVERLAP; i++) {
  39. memset(bins[i], 0, sizeof(bins[i]));
  40. }
  41. for(int i=0; i<BUFF_SIZE; i++) {
  42. in_Buffer.push(0.0f);
  43. }
  44. for(int i=0; i<2*BUFF_SIZE; i++) {
  45. out_Buffer.push(0.0f);
  46. }
  47. }
  48. ~CURT() {
  49. }
  50. json_t *toJson() override {
  51. json_t *rootJ = json_object();
  52. json_object_set_new(rootJ, "mode", json_boolean(mode));
  53. return rootJ;
  54. }
  55. void fromJson(json_t *rootJ) override {
  56. json_t *modeJ = json_object_get(rootJ, "mode");
  57. if (modeJ)
  58. mode = json_is_true(modeJ);
  59. }
  60. void step() override;
  61. };
  62. void CURT::step() {
  63. if (modeTrigger.process(params[MODE_PARAM].value)) {
  64. mode = !mode;
  65. }
  66. in_Buffer.startIncr(1);
  67. in_Buffer.push(inputs[INPUT].value);
  68. readSteps++;
  69. if (readSteps>=(BUFF_SIZE/OVERLAP)) {
  70. index=(index+1)%OVERLAP;
  71. for(int i=0; i<BUFF_SIZE; i++) {
  72. bins[index][i]=*(in_Buffer.startData()+i);
  73. }
  74. blackmanHarrisWindow(bins[index],BUFF_SIZE);
  75. readSteps = 0;
  76. }
  77. writeSteps++;
  78. if ((writeSteps>=((float)BUFF_SIZE*params[PITCH_PARAM].value/(float)OVERLAP))) {
  79. if ((index%2==0) || (mode)) {
  80. for(int i=0; i<BUFF_SIZE; i++) {
  81. out_Buffer.data[out_Buffer.mask(out_Buffer.end-BUFF_SIZE+i)] += bins[index][i];
  82. }
  83. }
  84. else
  85. {
  86. for(int i=0; i<BUFF_SIZE; i++) {
  87. out_Buffer.data[out_Buffer.mask(out_Buffer.end-BUFF_SIZE+i)] += bins[index][BUFF_SIZE-i-1];
  88. }
  89. }
  90. writeSteps = 0;
  91. }
  92. outputs[OUTPUT].value = *out_Buffer.startData();
  93. out_Buffer.startIncr(1);
  94. out_Buffer.push(0.0f);
  95. }
  96. struct CURTWidget : ModuleWidget {
  97. CURTWidget(CURT *module) : ModuleWidget(module) {
  98. setPanel(SVG::load(assetPlugin(plugin, "res/CURT.svg")));
  99. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  100. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  101. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  102. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  103. addParam(ParamWidget::create<BidooBlueKnob>(Vec(8, 100), module, CURT::PITCH_PARAM, 0.2f, 2.0f, 1.0f));
  104. addInput(Port::create<PJ301MPort>(Vec(10, 150.0f), Port::INPUT, module, CURT::PITCH_INPUT));
  105. addParam(ParamWidget::create<BlueCKD6>(Vec(8, 190.0f), module, CURT::MODE_PARAM, 0.0f, 1.0f, 0.0f));
  106. addInput(Port::create<PJ301MPort>(Vec(10, 242.66f), Port::INPUT, module, CURT::INPUT));
  107. addOutput(Port::create<PJ301MPort>(Vec(10, 299), Port::OUTPUT, module, CURT::OUTPUT));
  108. }
  109. };
  110. } // namespace rack_plugin_Bidoo
  111. using namespace rack_plugin_Bidoo;
  112. RACK_PLUGIN_MODEL_INIT(Bidoo, CURT) {
  113. Model *modelCURT = Model::create<CURT, CURTWidget>("Bidoo", "cuRt", "cuRt .......", EFFECT_TAG);
  114. return modelCURT;
  115. }