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.

158 lines
5.2KB

  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. #ifndef rEffPar
  20. #define rEffPar(name, idx, ...) \
  21. {STRINGIFY(name) "::i", rProp(parameter) DOC(__VA_ARGS__), NULL, rEffParCb(idx)}
  22. #define rEffParTF(name, idx, ...) \
  23. {STRINGIFY(name) "::T:F", rProp(parameter) DOC(__VA_ARGS__), NULL, rEffParTFCb(idx)}
  24. #define rEffParCb(idx) \
  25. [](const char *msg, rtosc::RtData &d) {\
  26. rObject &obj = *(rObject*)d.obj; \
  27. if(rtosc_narguments(msg)) \
  28. obj.changepar(idx, rtosc_argument(msg, 0).i); \
  29. else \
  30. d.reply(d.loc, "i", obj.getpar(idx));}
  31. #define rEffParTFCb(idx) \
  32. [](const char *msg, rtosc::RtData &d) {\
  33. rObject &obj = *(rObject*)d.obj; \
  34. if(rtosc_narguments(msg)) \
  35. obj.changepar(idx, rtosc_argument(msg, 0).T*127); \
  36. else \
  37. d.reply(d.loc, obj.getpar(idx)?"T":"F");}
  38. #endif
  39. struct EffectParams
  40. {
  41. /**
  42. * Effect Parameter Constructor
  43. * @param alloc Realtime Memory Allocator
  44. * @param insertion_ 1 when it is an insertion Effect
  45. * @param efxoutl_ Effect output buffer Left channel
  46. * @param efxoutr_ Effect output buffer Right channel
  47. * @param filterpars_ pointer to FilterParams array
  48. * @param Ppreset_ chosen preset
  49. * @return Initialized Effect Parameter object*/
  50. EffectParams(Allocator &alloc_, bool insertion_, float *efxoutl_, float *efxoutr_,
  51. unsigned char Ppreset_, unsigned int srate, int bufsize, FilterParams *filterpars_,
  52. bool filterprotect=false);
  53. Allocator &alloc;
  54. bool insertion;
  55. float *efxoutl;
  56. float *efxoutr;
  57. unsigned char Ppreset;
  58. unsigned int srate;
  59. int bufsize;
  60. FilterParams *filterpars;
  61. bool filterprotect;
  62. };
  63. /**this class is inherited by the all effects(Reverb, Echo, ..)*/
  64. class Effect
  65. {
  66. public:
  67. Effect(EffectParams pars);
  68. virtual ~Effect() {}
  69. /**
  70. * Choose a preset
  71. * @param npreset number of chosen preset*/
  72. virtual void setpreset(unsigned char npreset) = 0;
  73. /**Change parameter npar to value
  74. * @param npar chosen parameter
  75. * @param value chosen new value*/
  76. virtual void changepar(int npar, unsigned char value) = 0;
  77. /**Get the value of parameter npar
  78. * @param npar chosen parameter
  79. * @return the value of the parameter in an unsigned char or 0 if it
  80. * does not exist*/
  81. virtual unsigned char getpar(int npar) const = 0;
  82. /**Output result of effect based on the given buffers
  83. *
  84. * This method should result in the effect generating its results
  85. * and placing them into the efxoutl and efxoutr buffers.
  86. * Every Effect should overide this method.
  87. *
  88. * @param smpsl Input buffer for the Left channel
  89. * @param smpsr Input buffer for the Right channel
  90. */
  91. void out(float *const smpsl, float *const smpsr);
  92. virtual void out(const Stereo<float *> &smp) = 0;
  93. /**Reset the state of the effect*/
  94. virtual void cleanup(void) {}
  95. virtual float getfreqresponse(float freq) { return freq; }
  96. unsigned char Ppreset; /**<Currently used preset*/
  97. float *const efxoutl; /**<Effect out Left Channel*/
  98. float *const efxoutr; /**<Effect out Right Channel*/
  99. float outvolume; /**<This is the volume of effect and is public because
  100. * it is needed in system effects.
  101. * The out volume of such effects are always 1.0f, so
  102. * this setting tells me how is the volume to the
  103. * Master Output only.*/
  104. float volume;
  105. FilterParams *filterpars; /**<Parameters for filters used by Effect*/
  106. //Perform L/R crossover
  107. static void crossover(float &a, float &b, float crossover);
  108. protected:
  109. void setpanning(char Ppanning_);
  110. void setlrcross(char Plrcross_);
  111. const bool insertion;
  112. //panning parameters
  113. char Ppanning;
  114. float pangainL;
  115. float pangainR;
  116. char Plrcross; // L/R mix
  117. float lrcross;
  118. //Allocator
  119. Allocator &memory;
  120. // current setup
  121. unsigned int samplerate;
  122. int buffersize;
  123. // alias for above terms
  124. float samplerate_f;
  125. float halfsamplerate_f;
  126. float buffersize_f;
  127. int bufferbytes;
  128. inline void alias()
  129. {
  130. samplerate_f = samplerate;
  131. halfsamplerate_f = samplerate_f / 2.0f;
  132. buffersize_f = buffersize;
  133. bufferbytes = buffersize * sizeof(float);
  134. }
  135. };
  136. #endif