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.

165 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. protected:
  57. // -------------------------------------------------------------------
  58. // Information
  59. const char* d_getLabel() const noexcept override
  60. {
  61. return "ZaMultiComp";
  62. }
  63. const char* d_getMaker() const noexcept override
  64. {
  65. return "Damien Zammit";
  66. }
  67. const char* d_getLicense() const noexcept override
  68. {
  69. return "GPL v2+";
  70. }
  71. uint32_t d_getVersion() const noexcept override
  72. {
  73. return 0x1000;
  74. }
  75. long d_getUniqueId() const noexcept override
  76. {
  77. return d_cconst('Z', 'M', 'C', 'P');
  78. }
  79. // -------------------------------------------------------------------
  80. // Init
  81. void d_initParameter(uint32_t index, Parameter& parameter) override;
  82. void d_initProgramName(uint32_t index, d_string& programName) override;
  83. // -------------------------------------------------------------------
  84. // Internal data
  85. float d_getParameterValue(uint32_t index) const override;
  86. void d_setParameterValue(uint32_t index, float value) override;
  87. void d_setProgram(uint32_t index) override;
  88. // -------------------------------------------------------------------
  89. // Process
  90. static inline float
  91. sanitize_denormal(float v) {
  92. if(!std::isnormal(v) || !std::isfinite(v))
  93. return 0.f;
  94. return v;
  95. }
  96. static inline float
  97. from_dB(float gdb) {
  98. return (exp(gdb/20.f*log(10.f)));
  99. }
  100. static inline float
  101. to_dB(float g) {
  102. return (20.f*log10(g));
  103. }
  104. float run_comp(int k, float in);
  105. float run_filter(int i, float in);
  106. void set_lp_coeffs(float fc, float q, float sr, int i, float gain);
  107. void set_hp_coeffs(float fc, float q, float sr, int i, float gain);
  108. void d_activate() override;
  109. void d_run(const float** inputs, float** outputs, uint32_t frames) override;
  110. // -------------------------------------------------------------------
  111. private:
  112. float attack,release,knee,ratio,thresdb,makeup[MAX_COMP],globalgain;
  113. float gainr[MAX_COMP],toggle[MAX_COMP],xover1,xover2,outlevel,listen[MAX_COMP];
  114. float old_yl[MAX_COMP], old_y1[MAX_COMP];
  115. // Crossover filter coefficients
  116. float a0[MAX_FILT];
  117. float a1[MAX_FILT];
  118. float a2[MAX_FILT];
  119. float b1[MAX_FILT];
  120. float b2[MAX_FILT];
  121. //Crossover filter states
  122. float w1[MAX_FILT];
  123. float w2[MAX_FILT];
  124. float z1[MAX_FILT];
  125. float z2[MAX_FILT];
  126. };
  127. // -----------------------------------------------------------------------
  128. END_NAMESPACE_DISTRHO
  129. #endif // ZAMULTICOMP_HPP_INCLUDED