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.

185 lines
4.5KB

  1. /*
  2. * ZaMultiCompX2 stereo multiband compressor
  3. * Copyright (C) 2014 Damien Zammit <damien@zamaudio.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef ZAMULTICOMPX2PLUGIN_HPP_INCLUDED
  18. #define ZAMULTICOMPX2PLUGIN_HPP_INCLUDED
  19. #include "DistrhoPlugin.hpp"
  20. START_NAMESPACE_DISTRHO
  21. #define MAX_FILT 8
  22. #define MAX_COMP 3
  23. #define ONEOVERROOT2 0.7071068f
  24. #define ROOT2 1.4142135f
  25. #define STEREOLINK_MAX 1
  26. #define STEREOLINK_AVERAGE 0
  27. #define DANGER 100000.f
  28. // -----------------------------------------------------------------------
  29. class ZaMultiCompX2Plugin : public Plugin
  30. {
  31. public:
  32. enum Parameters
  33. {
  34. paramAttack = 0,
  35. paramRelease,
  36. paramKnee,
  37. paramRatio,
  38. paramThresh1,
  39. paramThresh2,
  40. paramThresh3,
  41. paramMakeup1,
  42. paramMakeup2,
  43. paramMakeup3,
  44. paramXover1,
  45. paramXover2,
  46. paramGainR1,
  47. paramGainR2,
  48. paramGainR3,
  49. paramToggle1,
  50. paramToggle2,
  51. paramToggle3,
  52. paramListen1,
  53. paramListen2,
  54. paramListen3,
  55. paramStereoDet,
  56. paramGlobalGain,
  57. paramOutputLevelL,
  58. paramOutputLevelR,
  59. paramCount
  60. };
  61. enum States
  62. {
  63. stateReadMeter,
  64. stateCount
  65. };
  66. ZaMultiCompX2Plugin();
  67. ~ZaMultiCompX2Plugin() override;
  68. protected:
  69. // -------------------------------------------------------------------
  70. // Information
  71. const char* d_getLabel() const noexcept override
  72. {
  73. return "ZaMultiCompX2";
  74. }
  75. const char* d_getMaker() const noexcept override
  76. {
  77. return "Damien Zammit";
  78. }
  79. const char* d_getLicense() const noexcept override
  80. {
  81. return "GPL v2+";
  82. }
  83. uint32_t d_getVersion() const noexcept override
  84. {
  85. return 0x1000;
  86. }
  87. long d_getUniqueId() const noexcept override
  88. {
  89. return d_cconst('Z', 'M', 'M', '2');
  90. }
  91. // -------------------------------------------------------------------
  92. // Init
  93. void d_initParameter(uint32_t index, Parameter& parameter) ;
  94. void d_initProgramName(uint32_t index, d_string& programName) ;
  95. void d_initStateKey(uint32_t, d_string&) override;
  96. // -------------------------------------------------------------------
  97. // Internal data
  98. float d_getParameterValue(uint32_t index) const override;
  99. void d_setParameterValue(uint32_t index, float value) override;
  100. void d_setProgram(uint32_t index) ;
  101. void d_setState(const char* key, const char* value) override;
  102. // -------------------------------------------------------------------
  103. // Process
  104. static inline float
  105. sanitize_denormal(float v) {
  106. if(!std::isnormal(v))
  107. return 0.f;
  108. return v;
  109. }
  110. static inline float
  111. from_dB(float gdb) {
  112. return (exp(gdb/20.f*log(10.f)));
  113. }
  114. static inline float
  115. to_dB(float g) {
  116. return (20.f*log10(g));
  117. }
  118. void run_comp(int k, float inL, float inR, float *outL, float *outR);
  119. float run_filter(int i, int ch, float in);
  120. void set_lp_coeffs(float fc, float q, float sr, int i, int ch, float gain);
  121. void set_hp_coeffs(float fc, float q, float sr, int i, int ch, float gain);
  122. void d_activate() override;
  123. void d_deactivate() override;
  124. void d_run(float** inputs, float** outputs, uint32_t frames) override;
  125. // -------------------------------------------------------------------
  126. private:
  127. float attack,release,knee,ratio,thresdb[MAX_COMP],makeup[MAX_COMP],globalgain,stereodet;
  128. float gainr[MAX_COMP],toggle[MAX_COMP],listen[MAX_COMP],maxL,maxR,outl,outr,xover1,xover2;
  129. float old_yl[2][MAX_COMP], old_y1[2][MAX_COMP];
  130. bool resetl;
  131. bool resetr;
  132. // Crossover filter coefficients
  133. float a0[2][MAX_FILT];
  134. float a1[2][MAX_FILT];
  135. float a2[2][MAX_FILT];
  136. float b1[2][MAX_FILT];
  137. float b2[2][MAX_FILT];
  138. //Crossover filter states
  139. float w1[2][MAX_FILT];
  140. float w2[2][MAX_FILT];
  141. float z1[2][MAX_FILT];
  142. float z2[2][MAX_FILT];
  143. };
  144. // -----------------------------------------------------------------------
  145. END_NAMESPACE_DISTRHO
  146. #endif