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.

135 lines
4.3KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Effect.h - this class is inherited by the all effects(Reverb, Echo, ..)
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #ifndef EFFECT_H
  12. #define EFFECT_H
  13. #include "../Misc/Util.h"
  14. #include "../globals.h"
  15. #include "../Params/FilterParams.h"
  16. #include "../Misc/Stereo.h"
  17. class FilterParams;
  18. class Allocator;
  19. struct EffectParams
  20. {
  21. /**
  22. * Effect Parameter Constructor
  23. * @param alloc Realtime Memory Allocator
  24. * @param insertion_ 1 when it is an insertion Effect
  25. * @param efxoutl_ Effect output buffer Left channel
  26. * @param efxoutr_ Effect output buffer Right channel
  27. * @param filterpars_ pointer to FilterParams array
  28. * @param Ppreset_ chosen preset
  29. * @return Initialized Effect Parameter object*/
  30. EffectParams(Allocator &alloc_, bool insertion_, float *efxoutl_, float *efxoutr_,
  31. unsigned char Ppreset_, unsigned int srate, int bufsize, FilterParams *filterpars_=0);
  32. Allocator &alloc;
  33. bool insertion;
  34. float *efxoutl;
  35. float *efxoutr;
  36. unsigned char Ppreset;
  37. unsigned int srate;
  38. int bufsize;
  39. FilterParams *filterpars;
  40. };
  41. /**this class is inherited by the all effects(Reverb, Echo, ..)*/
  42. class Effect
  43. {
  44. public:
  45. Effect(EffectParams pars);
  46. virtual ~Effect() {}
  47. /**
  48. * Choose a preset
  49. * @param npreset number of chosen preset*/
  50. virtual void setpreset(unsigned char npreset) = 0;
  51. /**Change parameter npar to value
  52. * @param npar chosen parameter
  53. * @param value chosen new value*/
  54. virtual void changepar(int npar, unsigned char value) = 0;
  55. /**Get the value of parameter npar
  56. * @param npar chosen parameter
  57. * @return the value of the parameter in an unsigned char or 0 if it
  58. * does not exist*/
  59. virtual unsigned char getpar(int npar) const = 0;
  60. /**Output result of effect based on the given buffers
  61. *
  62. * This method should result in the effect generating its results
  63. * and placing them into the efxoutl and efxoutr buffers.
  64. * Every Effect should overide this method.
  65. *
  66. * @param smpsl Input buffer for the Left channel
  67. * @param smpsr Input buffer for the Right channel
  68. */
  69. void out(float *const smpsl, float *const smpsr);
  70. virtual void out(const Stereo<float *> &smp) = 0;
  71. /**Reset the state of the effect*/
  72. virtual void cleanup(void) {}
  73. virtual float getfreqresponse(float freq) { return freq; }
  74. unsigned char Ppreset; /**<Currently used preset*/
  75. float *const efxoutl; /**<Effect out Left Channel*/
  76. float *const efxoutr; /**<Effect out Right Channel*/
  77. float outvolume; /**<This is the volume of effect and is public because
  78. * it is needed in system effects.
  79. * The out volume of such effects are always 1.0f, so
  80. * this setting tells me how is the volume to the
  81. * Master Output only.*/
  82. float volume;
  83. FilterParams *filterpars; /**<Parameters for filters used by Effect*/
  84. //Perform L/R crossover
  85. static void crossover(float &a, float &b, float crossover);
  86. protected:
  87. void setpanning(char Ppanning_);
  88. void setlrcross(char Plrcross_);
  89. const bool insertion;
  90. //panning parameters
  91. char Ppanning;
  92. float pangainL;
  93. float pangainR;
  94. char Plrcross; // L/R mix
  95. float lrcross;
  96. //Allocator
  97. Allocator &memory;
  98. // current setup
  99. unsigned int samplerate;
  100. int buffersize;
  101. // alias for above terms
  102. float samplerate_f;
  103. float halfsamplerate_f;
  104. float buffersize_f;
  105. int bufferbytes;
  106. inline void alias()
  107. {
  108. samplerate_f = samplerate;
  109. halfsamplerate_f = samplerate_f / 2.0f;
  110. buffersize_f = buffersize;
  111. bufferbytes = buffersize * sizeof(float);
  112. }
  113. };
  114. #endif