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.7KB

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