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.

124 lines
4.4KB

  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 modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef EFFECT_H
  18. #define EFFECT_H
  19. #include "../Misc/Util.h"
  20. #include "../Params/FilterParams.h"
  21. #include "../Misc/Stereo.h"
  22. class FilterParams;
  23. /**this class is inherited by the all effects(Reverb, Echo, ..)*/
  24. class Effect
  25. {
  26. public:
  27. /**
  28. * Effect Constructor
  29. * @param insertion_ 1 when it is an insertion Effect
  30. * @param efxoutl_ Effect output buffer Left channel
  31. * @param efxoutr_ Effect output buffer Right channel
  32. * @param filterpars_ pointer to FilterParams array
  33. * @param Ppreset_ chosen preset
  34. * @return Initialized Effect object*/
  35. Effect(bool insertion_, float *efxoutl_, float *efxoutr_,
  36. FilterParams *filterpars_, unsigned char Ppreset_,
  37. unsigned int srate, int bufsize);
  38. virtual ~Effect() {}
  39. /**
  40. * Choose a preset
  41. * @param npreset number of chosen preset*/
  42. virtual void setpreset(unsigned char npreset) = 0;
  43. /**Change parameter npar to value
  44. * @param npar chosen parameter
  45. * @param value chosen new value*/
  46. virtual void changepar(int npar, unsigned char value) = 0;
  47. /**Get the value of parameter npar
  48. * @param npar chosen parameter
  49. * @return the value of the parameter in an unsigned char or 0 if it
  50. * does not exist*/
  51. virtual unsigned char getpar(int npar) const = 0;
  52. /**Output result of effect based on the given buffers
  53. *
  54. * This method should result in the effect generating its results
  55. * and placing them into the efxoutl and efxoutr buffers.
  56. * Every Effect should overide this method.
  57. *
  58. * @param smpsl Input buffer for the Left channel
  59. * @param smpsr Input buffer for the Right channel
  60. */
  61. void out(float *const smpsl, float *const smpsr);
  62. virtual void out(const Stereo<float *> &smp) = 0;
  63. /**Reset the state of the effect*/
  64. virtual void cleanup(void) {}
  65. virtual float getfreqresponse(float freq) { return freq; }
  66. unsigned char Ppreset; /**<Currently used preset*/
  67. float *const efxoutl; /**<Effect out Left Channel*/
  68. float *const efxoutr; /**<Effect out Right Channel*/
  69. float outvolume; /**<This is the volume of effect and is public because
  70. * it is needed in system effects.
  71. * The out volume of such effects are always 1.0f, so
  72. * this setting tells me how is the volume to the
  73. * Master Output only.*/
  74. float volume;
  75. FilterParams *filterpars; /**<Parameters for filters used by Effect*/
  76. //Perform L/R crossover
  77. static void crossover(float &a, float &b, float crossover);
  78. protected:
  79. void setpanning(char Ppanning_);
  80. void setlrcross(char Plrcross_);
  81. const bool insertion;
  82. //panning parameters
  83. char Ppanning;
  84. float pangainL;
  85. float pangainR;
  86. char Plrcross; // L/R mix
  87. float lrcross;
  88. // current setup
  89. unsigned int samplerate;
  90. int buffersize;
  91. // alias for above terms
  92. float samplerate_f;
  93. float halfsamplerate_f;
  94. float buffersize_f;
  95. int bufferbytes;
  96. inline void alias()
  97. {
  98. samplerate_f = samplerate;
  99. halfsamplerate_f = samplerate_f / 2.0f;
  100. buffersize_f = buffersize;
  101. bufferbytes = buffersize * sizeof(float);
  102. }
  103. };
  104. #endif