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.

195 lines
4.5KB

  1. /*
  2. * ZamTube triode WDF distortion model
  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 ZAMTUBEPLUGIN_HPP_INCLUDED
  18. #define ZAMTUBEPLUGIN_HPP_INCLUDED
  19. #include "DistrhoPlugin.hpp"
  20. #include "wdf.h"
  21. START_NAMESPACE_DISTRHO
  22. // -----------------------------------------------------------------------
  23. template <int N> inline float faustpower(float x) { return powf(x,N); }
  24. template <int N> inline double faustpower(double x) { return pow(x,N); }
  25. template <int N> inline int faustpower(int x) { return faustpower<N/2>(x) * faustpower<N-N/2>(x); }
  26. template <> inline int faustpower<0>(int) { return 1; }
  27. template <> inline int faustpower<1>(int x) { return x; }
  28. #define FAUSTFLOAT float
  29. typedef long double quad;
  30. #define TOLERANCE 1e-6
  31. #define DANGER 1000.f
  32. class ZamTubePlugin : public Plugin
  33. {
  34. public:
  35. Triode v;
  36. V Vi;
  37. C Ci;
  38. C Ck;
  39. C Co;
  40. R Ro;
  41. R Rg;
  42. R Ri;
  43. R Rk;
  44. V E;
  45. T e;
  46. //Official
  47. //->Gate
  48. ser S0;
  49. inv I0;
  50. par P0;
  51. ser S1;
  52. inv I1;
  53. //->Cathode
  54. par I3;
  55. //->Plate
  56. ser S2;
  57. inv I4;
  58. par P2;
  59. float fConst0;
  60. float fConst1;
  61. float fConst2;
  62. float fConst3;
  63. float fRec0[4];
  64. float fRec1[4];
  65. float fRec2[4];
  66. float fRec3[4];
  67. float fRec4[4];
  68. float fRec5[4];
  69. float fRec6[4];
  70. float fRec7[4];
  71. float fRec8[4];
  72. float fRec9[4];
  73. float fRec10[4];
  74. float fRec11[4];
  75. float fRec12[4];
  76. float fRec13[4];
  77. float fConst4;
  78. float fConst5;
  79. float fRec14[4];
  80. float fConst6;
  81. float fRec15[4];
  82. float fRec16[4];
  83. float fRec17[4];
  84. float fRec18[4];
  85. float fRec19[4];
  86. float fRec20[4];
  87. float fRec21[4];
  88. float fRec22[4];
  89. float fRec23[4];
  90. float fRec24[4];
  91. float fSamplingFreq;
  92. enum Parameters
  93. {
  94. paramTubedrive = 0,
  95. paramBass,
  96. paramMiddle,
  97. paramTreble,
  98. paramToneStack,
  99. paramGain,
  100. paramCount
  101. };
  102. ZamTubePlugin();
  103. protected:
  104. // -------------------------------------------------------------------
  105. // Information
  106. const char* d_getLabel() const noexcept override
  107. {
  108. return "ZamTube";
  109. }
  110. const char* d_getMaker() const noexcept override
  111. {
  112. return "Damien Zammit";
  113. }
  114. const char* d_getLicense() const noexcept override
  115. {
  116. return "GPL v2+";
  117. }
  118. uint32_t d_getVersion() const noexcept override
  119. {
  120. return 0x1000;
  121. }
  122. long d_getUniqueId() const noexcept override
  123. {
  124. return d_cconst('Z', 'T', 'U', 'B');
  125. }
  126. // -------------------------------------------------------------------
  127. // Init
  128. void d_initParameter(uint32_t index, Parameter& parameter) ;
  129. void d_initProgramName(uint32_t index, d_string& programName) ;
  130. // -------------------------------------------------------------------
  131. // Internal data
  132. float d_getParameterValue(uint32_t index) const override;
  133. void d_setParameterValue(uint32_t index, float value) override;
  134. void d_setProgram(uint32_t index) ;
  135. // -------------------------------------------------------------------
  136. // Process
  137. static inline float
  138. sanitize_denormal(float v) {
  139. if(!std::isnormal(v) || !std::isfinite(v))
  140. return 0.f;
  141. return v;
  142. }
  143. static inline float
  144. from_dB(float gdb) {
  145. return (exp(gdb/20.f*log(10.f)));
  146. }
  147. static inline float
  148. to_dB(float g) {
  149. return (20.f*log10(g));
  150. }
  151. void d_activate() override;
  152. void d_run(const float** inputs, float** outputs, uint32_t frames) override;
  153. // -------------------------------------------------------------------
  154. private:
  155. float tubedrive,bass,middle,treble,tonestack,mastergain; //parameters
  156. };
  157. // -----------------------------------------------------------------------
  158. END_NAMESPACE_DISTRHO
  159. #endif // ZAMTUBE_HPP_INCLUDED