Audio plugin host https://kx.studio/carla
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.

77 lines
1.9KB

  1. /*
  2. * Moog-like resonant LPF
  3. * Implemented by Andre Sklenar <andre.sklenar@gmail.com>, www.juicelab.cz .
  4. *
  5. * Filter design from http://www.musicdsp.com .
  6. */
  7. #ifndef MOOG_VCF_HXX_INCLUDED
  8. #define MOOG_VCF_HXX_INCLUDED
  9. #include <cmath>
  10. #include <cstdlib>
  11. class MoogVCF
  12. {
  13. public:
  14. MoogVCF()
  15. {
  16. cutoff = 16000;
  17. res = 0.5;
  18. f=k=p=scale=r=0;
  19. y1=y2=y3=y4=oldIn=oldY1=oldY2=oldY3=0;
  20. in=oldIn=0;
  21. pureInput=drivenInput=processedInput=0;
  22. }
  23. void recalc(float cutoff, float reso, int sr, float nDrive)
  24. {
  25. f = 2*cutoff/sr;
  26. k=2*std::sin(f*M_PI/2)-1;
  27. p = (k+1)*0.5;
  28. scale = std::pow(2.71828, (1-p)*1.386249);
  29. r = reso*scale;
  30. drive = nDrive;
  31. }
  32. void process (long frames, const float* inputs, float* outputs)
  33. {
  34. //run the shit
  35. for (long i=0; i<frames; i++)
  36. {
  37. pureInput = inputs[i]; //clean signal
  38. drivenInput = std::tanh(pureInput*(drive*15+1)) * (drive); //a touch of waveshaping
  39. processedInput = pureInput*(1-drive) + drivenInput; // combine
  40. processedInput*=1-drive/3; //reduce gain a little
  41. /* filter */
  42. in = processedInput-r*y4;
  43. y1 = in*p + oldIn*p - k*y1;
  44. y2 = y1*p + oldY1*p - k*y2;
  45. y3 = y2*p + oldY2*p - k*y3;
  46. y4 = y3*p + oldY3*p - k*y4;
  47. oldIn = in;
  48. oldY1 = y1;
  49. oldY2 = y2;
  50. oldY3 = y3;
  51. /* output */
  52. outputs[i] = y4;
  53. }
  54. }
  55. private:
  56. /* vcf filter */
  57. float cutoff; //freq in Hz
  58. float res; //resonance 0..1
  59. float drive; //drive 1...2;
  60. float f, k, p, scale, r;
  61. float y1, y2, y3, y4, oldY1, oldY2, oldY3;
  62. float in, oldIn;
  63. /* waveshaping vars */
  64. float pureInput, drivenInput, processedInput;
  65. };
  66. #endif // MOOG_VCF_HXX_INCLUDED