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.

182 lines
4.4KB

  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. protected:
  68. // -------------------------------------------------------------------
  69. // Information
  70. const char* d_getLabel() const noexcept override
  71. {
  72. return "ZaMultiCompX2";
  73. }
  74. const char* d_getMaker() const noexcept override
  75. {
  76. return "Damien Zammit";
  77. }
  78. const char* d_getLicense() const noexcept override
  79. {
  80. return "GPL v2+";
  81. }
  82. uint32_t d_getVersion() const noexcept override
  83. {
  84. return 0x1000;
  85. }
  86. long d_getUniqueId() const noexcept override
  87. {
  88. return d_cconst('Z', 'M', 'M', '2');
  89. }
  90. // -------------------------------------------------------------------
  91. // Init
  92. void d_initParameter(uint32_t index, Parameter& parameter) ;
  93. void d_initProgramName(uint32_t index, d_string& programName) ;
  94. void d_initStateKey(uint32_t, d_string&) override;
  95. // -------------------------------------------------------------------
  96. // Internal data
  97. float d_getParameterValue(uint32_t index) const override;
  98. void d_setParameterValue(uint32_t index, float value) override;
  99. void d_setProgram(uint32_t index) ;
  100. void d_setState(const char* key, const char* value) override;
  101. // -------------------------------------------------------------------
  102. // Process
  103. static inline float
  104. sanitize_denormal(float v) {
  105. if(!std::isnormal(v))
  106. return 0.f;
  107. return v;
  108. }
  109. static inline float
  110. from_dB(float gdb) {
  111. return (exp(gdb/20.f*log(10.f)));
  112. }
  113. static inline float
  114. to_dB(float g) {
  115. return (20.f*log10(g));
  116. }
  117. void run_comp(int k, float inL, float inR, float *outL, float *outR);
  118. float run_filter(int i, int ch, float in);
  119. void set_lp_coeffs(float fc, float q, float sr, int i, int ch, float gain);
  120. void set_hp_coeffs(float fc, float q, float sr, int i, int ch, float gain);
  121. void d_activate() override;
  122. void d_run(const float** inputs, float** outputs, uint32_t frames) override;
  123. // -------------------------------------------------------------------
  124. private:
  125. float attack,release,knee,ratio,thresdb[MAX_COMP],makeup[MAX_COMP],globalgain,stereodet;
  126. float gainr[MAX_COMP],toggle[MAX_COMP],listen[MAX_COMP],maxL,maxR,outl,outr,xover1,xover2;
  127. float old_yl[2][MAX_COMP], old_y1[2][MAX_COMP];
  128. bool resetl;
  129. bool resetr;
  130. // Crossover filter coefficients
  131. float a0[2][MAX_FILT];
  132. float a1[2][MAX_FILT];
  133. float a2[2][MAX_FILT];
  134. float b1[2][MAX_FILT];
  135. float b2[2][MAX_FILT];
  136. //Crossover filter states
  137. float w1[2][MAX_FILT];
  138. float w2[2][MAX_FILT];
  139. float z1[2][MAX_FILT];
  140. float z2[2][MAX_FILT];
  141. };
  142. // -----------------------------------------------------------------------
  143. END_NAMESPACE_DISTRHO
  144. #endif