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.

Effect.h 4.4KB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "../globals.h"
  21. #include "../Params/FilterParams.h"
  22. #include "../Misc/Stereo.h"
  23. class FilterParams;
  24. /**this class is inherited by the all effects(Reverb, Echo, ..)*/
  25. class Effect
  26. {
  27. public:
  28. /**
  29. * Effect Constructor
  30. * @param insertion_ 1 when it is an insertion Effect
  31. * @param efxoutl_ Effect output buffer Left channel
  32. * @param efxoutr_ Effect output buffer Right channel
  33. * @param filterpars_ pointer to FilterParams array
  34. * @param Ppreset_ chosen preset
  35. * @return Initialized Effect object*/
  36. Effect(bool insertion_, float *efxoutl_, float *efxoutr_,
  37. FilterParams *filterpars_, unsigned char Ppreset_,
  38. unsigned int srate, int bufsize);
  39. virtual ~Effect() {}
  40. /**
  41. * Choose a preset
  42. * @param npreset number of chosen preset*/
  43. virtual void setpreset(unsigned char npreset) = 0;
  44. /**Change parameter npar to value
  45. * @param npar chosen parameter
  46. * @param value chosen new value*/
  47. virtual void changepar(int npar, unsigned char value) = 0;
  48. /**Get the value of parameter npar
  49. * @param npar chosen parameter
  50. * @return the value of the parameter in an unsigned char or 0 if it
  51. * does not exist*/
  52. virtual unsigned char getpar(int npar) const = 0;
  53. /**Output result of effect based on the given buffers
  54. *
  55. * This method should result in the effect generating its results
  56. * and placing them into the efxoutl and efxoutr buffers.
  57. * Every Effect should overide this method.
  58. *
  59. * @param smpsl Input buffer for the Left channel
  60. * @param smpsr Input buffer for the Right channel
  61. */
  62. void out(float *const smpsl, float *const smpsr);
  63. virtual void out(const Stereo<float *> &smp) = 0;
  64. /**Reset the state of the effect*/
  65. virtual void cleanup(void) {}
  66. virtual float getfreqresponse(float freq) { return freq; }
  67. unsigned char Ppreset; /**<Currently used preset*/
  68. float *const efxoutl; /**<Effect out Left Channel*/
  69. float *const efxoutr; /**<Effect out Right Channel*/
  70. float outvolume; /**<This is the volume of effect and is public because
  71. * it is needed in system effects.
  72. * The out volume of such effects are always 1.0f, so
  73. * this setting tells me how is the volume to the
  74. * Master Output only.*/
  75. float volume;
  76. FilterParams *filterpars; /**<Parameters for filters used by Effect*/
  77. //Perform L/R crossover
  78. static void crossover(float &a, float &b, float crossover);
  79. protected:
  80. void setpanning(char Ppanning_);
  81. void setlrcross(char Plrcross_);
  82. const bool insertion;
  83. //panning parameters
  84. char Ppanning;
  85. float pangainL;
  86. float pangainR;
  87. char Plrcross; // L/R mix
  88. float lrcross;
  89. // current setup
  90. unsigned int samplerate;
  91. int buffersize;
  92. // alias for above terms
  93. float samplerate_f;
  94. float halfsamplerate_f;
  95. float buffersize_f;
  96. int bufferbytes;
  97. inline void alias()
  98. {
  99. samplerate_f = samplerate;
  100. halfsamplerate_f = samplerate_f / 2.0f;
  101. buffersize_f = buffersize;
  102. bufferbytes = buffersize * sizeof(float);
  103. }
  104. };
  105. #endif