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
1.5KB

  1. // Comb filter class declaration
  2. //
  3. // Written by Jezar at Dreampoint, June 2000
  4. // http://www.dreampoint.co.uk
  5. // This code is public domain
  6. // adapted for use in VCV Rack by Martin Lueders
  7. #ifndef _comb_
  8. #define _comb_
  9. #include "denormals.h"
  10. class comb
  11. {
  12. public:
  13. comb()
  14. {
  15. buffer = 0;
  16. filterstore = 0;
  17. bufidx = 0;
  18. };
  19. ~comb()
  20. {
  21. if (buffer) delete buffer;
  22. };
  23. void makebuffer(float *buf, int size)
  24. {
  25. if (buffer) {delete buffer;}
  26. buffer = new float[size];
  27. bufsize = size;
  28. bufidx = 0;
  29. }
  30. void deletebuffer()
  31. {
  32. if(buffer) delete buffer;
  33. bufsize = 0;
  34. };
  35. void setbuffer(float *buf, int size)
  36. {
  37. buffer = buf;
  38. bufsize = size;
  39. };
  40. inline float process(float inp, float damp1, float damp2, float feedback);
  41. void mute()
  42. {
  43. for( int i=0; i<bufsize; i++) buffer[i]=0.0;
  44. };
  45. private:
  46. float filterstore;
  47. float *buffer;
  48. int bufsize;
  49. int bufidx;
  50. };
  51. // Big to inline - but crucial for speed
  52. inline float comb::process(float input, float damp1, float damp2, float feedback)
  53. {
  54. float output;
  55. output = buffer[bufidx]; // y[n-K]
  56. // undenormalise(output);
  57. filterstore *= damp1;
  58. filterstore += (output*damp2);
  59. // filterstore = damp1*filterstore + damp2*output;
  60. // filterstore = damp1*filterstore + (1.0-damp1) * output;
  61. // filterstore = output + damp1*(filterstore - output);
  62. // undenormalise(filterstore);
  63. buffer[bufidx] = input + (filterstore*feedback);
  64. if(++bufidx>=bufsize) bufidx = 0;
  65. return output;
  66. }
  67. #endif //_comb_
  68. //ends