DISTRHO Juice Plugins
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.

213 lines
5.4KB

  1. /*
  2. * Power Juice Plugin
  3. * Copyright (C) 2014 Andre Sklenar <andre.sklenar@gmail.com>, www.juicelab.cz
  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 POWERJUICEPLUGIN_HPP_INCLUDED
  18. #define POWERJUICEPLUGIN_HPP_INCLUDED
  19. #include "DistrhoPlugin.hpp"
  20. #include <cmath>
  21. static const int kFloatStackCount = 563;
  22. struct FloatStack { //history for GUI!
  23. int32_t start;
  24. float data[kFloatStackCount];
  25. };
  26. struct FloatRMSStack { //rms, sr-dependent
  27. int32_t start;
  28. float* data;
  29. };
  30. struct LookaheadStack { //lookahead buffer, sr-dependent
  31. int32_t start;
  32. float* data;
  33. };
  34. struct SharedMemData { //history for the GUI !
  35. float rms[kFloatStackCount];
  36. float gainReduction[kFloatStackCount];
  37. };
  38. START_NAMESPACE_DISTRHO
  39. // -----------------------------------------------------------------------
  40. class PowerJuiceX2Plugin : public Plugin
  41. {
  42. public:
  43. enum Parameters
  44. {
  45. paramAttack = 0,
  46. paramRelease,
  47. paramThreshold,
  48. paramRatio,
  49. paramMakeup,
  50. paramMix,
  51. paramCount
  52. };
  53. PowerJuiceX2Plugin();
  54. ~PowerJuiceX2Plugin() override;
  55. protected:
  56. // -------------------------------------------------------------------
  57. // Information
  58. const char* d_getLabel() const noexcept override
  59. {
  60. return "PowerJuiceX2";
  61. }
  62. const char* d_getMaker() const noexcept override
  63. {
  64. return "Andre Sklenar";
  65. }
  66. const char* d_getLicense() const noexcept override
  67. {
  68. return "GPL v2+";
  69. }
  70. uint32_t d_getVersion() const noexcept override
  71. {
  72. return 0x1000;
  73. }
  74. long d_getUniqueId() const noexcept override
  75. {
  76. return d_cconst('P', 'w', 'J', 'X');
  77. }
  78. // -------------------------------------------------------------------
  79. // Init
  80. void d_initParameter(uint32_t index, Parameter& parameter) override;
  81. void d_initProgramName(uint32_t index, d_string& programName) override;
  82. // -------------------------------------------------------------------
  83. // Internal data
  84. float d_getParameterValue(uint32_t index) const override;
  85. void d_setParameterValue(uint32_t index, float value) override;
  86. void d_setProgram(uint32_t index) override;
  87. // -------------------------------------------------------------------
  88. // Process
  89. void d_activate() override;
  90. void d_deactivate() override;
  91. void d_run(const float** inputs, float** outputs, uint32_t frames) override;
  92. // -------------------------------------------------------------------
  93. private:
  94. // params
  95. float attack, release, threshold, ratio, makeup, mix;
  96. float attackSamples, releaseSamples, makeupFloat;
  97. float balancer;
  98. float targetGR;
  99. float GR;
  100. SharedMemData history;
  101. float sum;
  102. float data;
  103. float difference;
  104. int w; //waveform plane size, size of the plane in pixels;
  105. int w2; //wavefowm array
  106. int h; //waveform plane height
  107. int x; //waveform plane positions
  108. int y;
  109. int dc; //0DC line y position
  110. int kFloatRMSStackCount;
  111. int kFloatLookaheadStackCount;
  112. float refreshSkip;
  113. int averageCounter;
  114. float inputMax;
  115. FloatStack input, rms, gainReduction;
  116. struct FloatRMSStack RMSStack;
  117. struct LookaheadStack lookaheadStack;
  118. bool newRepaint;
  119. int repaintSkip;
  120. float fromDB(float gdb) {
  121. return (std::exp(gdb/20.f*std::log(10.f)));
  122. };
  123. float toDB(float g) {
  124. return (20.f*std::log10(g));
  125. }
  126. float toIEC(float db) {
  127. float def = 0.0f; /* Meter deflection %age */
  128. if (db < -70.0f) {
  129. def = 0.0f;
  130. } else if (db < -60.0f) {
  131. def = (db + 70.0f) * 0.25f;
  132. } else if (db < -50.0f) {
  133. def = (db + 60.0f) * 0.5f + 5.0f;
  134. } else if (db < -40.0f) {
  135. def = (db + 50.0f) * 0.75f + 7.5;
  136. } else if (db < -30.0f) {
  137. def = (db + 40.0f) * 1.5f + 15.0f;
  138. } else if (db < -20.0f) {
  139. def = (db + 30.0f) * 2.0f + 30.0f;
  140. } else if (db < 0.0f) {
  141. def = (db + 20.0f) * 2.5f + 50.0f;
  142. } else {
  143. def = 100.0f;
  144. }
  145. return (def * 2.0f);
  146. }
  147. bool isNan(float& value ) {
  148. if (((*(uint32_t *) &value) & 0x7fffffff) > 0x7f800000) {
  149. return true;
  150. }
  151. return false;
  152. }
  153. void sanitizeDenormal(float& value) {
  154. if (isNan(value)) {
  155. //std::printf("Booo!\n");
  156. value = 0.f;
  157. }
  158. }
  159. public:
  160. //methods
  161. float getRMSHistory(int n);
  162. float getGainReductionHistory(int n);
  163. bool repaintNeeded();
  164. };
  165. // -----------------------------------------------------------------------
  166. END_NAMESPACE_DISTRHO
  167. #endif // POWERJUICE_HPP_INCLUDED