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.

111 lines
2.7KB

  1. #pragma once
  2. #include "AudioMath.h"
  3. #include "FractionalDelay.h"
  4. #include "ObjectCache.h"
  5. template <class TBase>
  6. class Daveguide : public TBase
  7. {
  8. public:
  9. Daveguide(struct Module * module) : TBase(module), delay(44100)
  10. {
  11. // init();
  12. }
  13. Daveguide() : TBase(), delay(44100)
  14. {
  15. // init();
  16. }
  17. enum ParamIds
  18. {
  19. OCTAVE_PARAM,
  20. TUNE_PARAM,
  21. DECAY_PARAM,
  22. FC_PARAM,
  23. NUM_PARAMS
  24. };
  25. enum InputIds
  26. {
  27. AUDIO_INPUT,
  28. CV_INPUT,
  29. NUM_INPUTS
  30. };
  31. enum OutputIds
  32. {
  33. AUDIO_OUTPUT,
  34. NUM_OUTPUTS
  35. };
  36. enum LightIds
  37. {
  38. NUM_LIGHTS
  39. };
  40. /**
  41. * Main processing entry point. Called every sample
  42. */
  43. void step() override;
  44. float _freq = 0;
  45. private:
  46. RecirculatingFractionalDelay delay;
  47. //static std::function<double(double)> makeFunc_Exp(double xMin, double xMax, double yMin, double yMax);
  48. // std::function<double(double)> delayScale = AudioMath::makeFunc_Exp(-5, 5, 1, 500);
  49. // AudioMath::ScaleFun<float> feedbackScale = AudioMath::makeLinearScaler(0.f, 1.f);
  50. std::function<float(float)> expLookup = ObjectCache<float>::getExp2Ex();
  51. };
  52. template <class TBase>
  53. void Daveguide<TBase>::step()
  54. {
  55. #if 0
  56. // make delay knob to from 1 ms. to 1000
  57. double delayMS = delayScale(TBase::params[PARAM_DELAY].value);
  58. double feedback = feedbackScale(0, (TBase::params[PARAM_FEEDBACK].value), 1);
  59. double delaySeconds = delayMS * .001;
  60. double delaySamples = delaySeconds * TBase::engineGetSampleRate();
  61. delay.setDelay((float) delaySamples);
  62. delay.setFeedback((float) feedback);
  63. const float input = TBase::inputs[INPUT_AUDIO].value;
  64. const float output = delay.run(input);
  65. TBase::outputs[OUTPUT_AUDIO].value = output;
  66. #endif
  67. float pitch = 1.0f + roundf(TBase::params[OCTAVE_PARAM].value) + TBase::params[TUNE_PARAM].value / 12.0f;
  68. pitch += TBase::inputs[CV_INPUT].value;
  69. //pitch += .25f * TBase::inputs[PITCH_MOD_INPUT].value *
  70. // taper(TBase::params[PARAM_PITCH_MOD_TRIM].value);
  71. const float q = float(log2(261.626)); // move up to pitch range of even vco
  72. pitch += q;
  73. _freq = expLookup(pitch);
  74. const float delaySeconds = 1.0f / _freq;
  75. float delaySamples = delaySeconds * TBase::engineGetSampleRate();
  76. delay.setDelay(delaySamples);
  77. delay.setFeedback(.999f);
  78. // printf("set delay to %f samples (%f sec)\n", delaySamples, delaySeconds);
  79. // fflush(stdout);
  80. const float input = TBase::inputs[AUDIO_INPUT].value;
  81. const float output = delay.run(input);
  82. TBase::outputs[AUDIO_OUTPUT].value = output;
  83. // clock.setMultiplier(1); // no mult
  84. }