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.

168 lines
4.0KB

  1. /*
  2. * ZaMultiComp Plugin
  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 ZAMULTICOMPPLUGIN_HPP_INCLUDED
  18. #define ZAMULTICOMPPLUGIN_HPP_INCLUDED
  19. #define MAX_FILT 8
  20. #define MAX_COMP 3
  21. #define ONEOVERROOT2 0.7071068f
  22. #define ROOT2 1.4142135f
  23. #define DANGER 100000.f
  24. #include "DistrhoPlugin.hpp"
  25. START_NAMESPACE_DISTRHO
  26. // -----------------------------------------------------------------------
  27. class ZaMultiCompPlugin : public Plugin
  28. {
  29. public:
  30. enum Parameters
  31. {
  32. paramAttack = 0,
  33. paramRelease,
  34. paramKnee,
  35. paramRatio,
  36. paramThresh,
  37. paramMakeup1,
  38. paramMakeup2,
  39. paramMakeup3,
  40. paramXover1,
  41. paramXover2,
  42. paramGainR1,
  43. paramGainR2,
  44. paramGainR3,
  45. paramToggle1,
  46. paramToggle2,
  47. paramToggle3,
  48. paramListen1,
  49. paramListen2,
  50. paramListen3,
  51. paramGlobalGain,
  52. paramOutputLevel,
  53. paramCount
  54. };
  55. ZaMultiCompPlugin();
  56. ~ZaMultiCompPlugin() override;
  57. protected:
  58. // -------------------------------------------------------------------
  59. // Information
  60. const char* d_getLabel() const noexcept override
  61. {
  62. return "ZaMultiComp";
  63. }
  64. const char* d_getMaker() const noexcept override
  65. {
  66. return "Damien Zammit";
  67. }
  68. const char* d_getLicense() const noexcept override
  69. {
  70. return "GPL v2+";
  71. }
  72. uint32_t d_getVersion() const noexcept override
  73. {
  74. return 0x1000;
  75. }
  76. long d_getUniqueId() const noexcept override
  77. {
  78. return d_cconst('Z', 'M', 'C', 'P');
  79. }
  80. // -------------------------------------------------------------------
  81. // Init
  82. void d_initParameter(uint32_t index, Parameter& parameter) ;
  83. void d_initProgramName(uint32_t index, d_string& programName) ;
  84. // -------------------------------------------------------------------
  85. // Internal data
  86. float d_getParameterValue(uint32_t index) const override;
  87. void d_setParameterValue(uint32_t index, float value) override;
  88. void d_setProgram(uint32_t index) ;
  89. // -------------------------------------------------------------------
  90. // Process
  91. static inline float
  92. sanitize_denormal(float v) {
  93. if(!std::isnormal(v) || !std::isfinite(v))
  94. return 0.f;
  95. return v;
  96. }
  97. static inline float
  98. from_dB(float gdb) {
  99. return (exp(gdb/20.f*log(10.f)));
  100. }
  101. static inline float
  102. to_dB(float g) {
  103. return (20.f*log10(g));
  104. }
  105. float run_comp(int k, float in);
  106. float run_filter(int i, float in);
  107. void set_lp_coeffs(float fc, float q, float sr, int i, float gain);
  108. void set_hp_coeffs(float fc, float q, float sr, int i, float gain);
  109. void d_activate() override;
  110. void d_deactivate() override;
  111. void d_run(float** inputs, float** outputs, uint32_t frames) override;
  112. // -------------------------------------------------------------------
  113. private:
  114. float attack,release,knee,ratio,thresdb,makeup[MAX_COMP],globalgain;
  115. float gainr[MAX_COMP],toggle[MAX_COMP],xover1,xover2,outlevel,listen[MAX_COMP];
  116. float old_yl[MAX_COMP], old_y1[MAX_COMP];
  117. // Crossover filter coefficients
  118. float a0[MAX_FILT];
  119. float a1[MAX_FILT];
  120. float a2[MAX_FILT];
  121. float b1[MAX_FILT];
  122. float b2[MAX_FILT];
  123. //Crossover filter states
  124. float w1[MAX_FILT];
  125. float w2[MAX_FILT];
  126. float z1[MAX_FILT];
  127. float z2[MAX_FILT];
  128. };
  129. // -----------------------------------------------------------------------
  130. END_NAMESPACE_DISTRHO
  131. #endif // ZAMULTICOMP_HPP_INCLUDED