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.

89 lines
1.7KB

  1. #pragma once
  2. #include <assert.h>
  3. #include <memory>
  4. /**
  5. * When ignoring wrap, inputIndex > outputIndex.
  6. * so output "pull up the rear", reading the samples that were written
  7. * delayTime samples ago.
  8. */
  9. class FractionalDelay
  10. {
  11. public:
  12. FractionalDelay(int numSamples) : numSamples(numSamples), delayMemory( new float[numSamples])
  13. {
  14. for (int i = 0; i < numSamples; ++i) {
  15. delayMemory[i] = 0;
  16. }
  17. }
  18. ~FractionalDelay()
  19. {
  20. delete delayMemory;
  21. }
  22. void setDelay(float samples)
  23. {
  24. assert(samples < numSamples);
  25. delayTime = samples;
  26. }
  27. float run(float input)
  28. {
  29. float ret = getOutput();
  30. setInput(input);
  31. return ret;
  32. }
  33. protected:
  34. /**
  35. * get the fractional delayed output, based in delayTime
  36. */
  37. float getOutput();
  38. /**
  39. * send the next input to the delay line
  40. */
  41. void setInput(float);
  42. private:
  43. /**
  44. * get delay output with integer (non-fractional) delay time
  45. */
  46. float getDelayedOutput(int delaySamples);
  47. double delayTime = 0;
  48. int inputPointerIndex = 0;
  49. /**
  50. * The size of the delay line, in samples
  51. */
  52. const int numSamples;
  53. float* delayMemory;
  54. };
  55. class RecirculatingFractionalDelay : public FractionalDelay
  56. {
  57. public:
  58. RecirculatingFractionalDelay(int numSamples) : FractionalDelay(numSamples)
  59. {
  60. }
  61. #if 0
  62. void setDelay(float samples)
  63. {
  64. delay.setDelay(samples);
  65. }
  66. #endif
  67. void setFeedback(float in_feedback)
  68. {
  69. assert(feedback < 1);
  70. assert(feedback > -1);
  71. feedback = in_feedback;
  72. }
  73. float run(float);
  74. private:
  75. // FractionalDelay delay;
  76. float feedback = 0;
  77. };