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.

81 lines
1.3KB

  1. // Allpass filter 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 _allpass_
  8. #define _allpass_
  9. #include "denormals.h"
  10. class allpass
  11. {
  12. public:
  13. allpass()
  14. {
  15. bufidx = 0;
  16. buffer = 0;
  17. };
  18. ~allpass()
  19. {
  20. if (buffer) delete buffer;
  21. };
  22. void makebuffer(float *buf, int size)
  23. {
  24. if (buffer) delete buffer;
  25. buffer = new float[size];
  26. bufsize = size;
  27. bufidx = 0;
  28. }
  29. void deletebuffer()
  30. {
  31. if(buffer) delete buffer;
  32. bufsize = 0;
  33. };
  34. void setbuffer(float *buf, int size)
  35. {
  36. buffer = buf;
  37. bufsize = size;
  38. };
  39. inline float process(float inp, float feedback);
  40. void mute()
  41. {
  42. for (int i=0; i<bufsize; i++) buffer[i] = 0.0;
  43. };
  44. // private:
  45. float *buffer;
  46. int bufsize;
  47. int bufidx;
  48. };
  49. // Big to inline - but crucial for speed
  50. inline float allpass::process(float input, float feedback)
  51. {
  52. float output;
  53. float bufout;
  54. bufout = buffer[bufidx];
  55. // undenormalise(bufout);
  56. output = -input + bufout;
  57. buffer[bufidx] = input + (bufout*feedback);
  58. if(++bufidx>=bufsize) bufidx = 0;
  59. return output;
  60. }
  61. #endif//_allpass
  62. //ends