diff options
Diffstat (limited to 'plugins/ZamTube')
-rw-r--r-- | plugins/ZamTube/ZamTubePlugin.cpp | 55 | ||||
-rw-r--r-- | plugins/ZamTube/ZamTubePlugin.hpp | 3 | ||||
-rw-r--r-- | plugins/ZamTube/ZamTubeUI.cpp | 9 | ||||
-rw-r--r-- | plugins/ZamTube/triode.cpp | 16 | ||||
-rw-r--r-- | plugins/ZamTube/triode.h | 1 | ||||
-rw-r--r-- | plugins/ZamTube/wdfcircuits.h | 3 |
6 files changed, 43 insertions, 44 deletions
diff --git a/plugins/ZamTube/ZamTubePlugin.cpp b/plugins/ZamTube/ZamTubePlugin.cpp index 719a2ae..81f8587 100644 --- a/plugins/ZamTube/ZamTubePlugin.cpp +++ b/plugins/ZamTube/ZamTubePlugin.cpp @@ -78,7 +78,7 @@ void ZamTubePlugin::initParameter(uint32_t index, Parameter& parameter) switch (index) { case paramTubedrive: - parameter.hints = kParameterIsAutomable | kParameterIsLogarithmic; + parameter.hints = kParameterIsAutomable; parameter.name = "Tube Drive"; parameter.symbol = "tubedrive"; parameter.unit = " "; @@ -127,8 +127,8 @@ void ZamTubePlugin::initParameter(uint32_t index, Parameter& parameter) parameter.name = "Output level"; parameter.symbol = "gain"; parameter.unit = " "; - parameter.ranges.def = 0.0f; - parameter.ranges.min = -30.0f; + parameter.ranges.def = 15.0f; + parameter.ranges.min = 0.0f; parameter.ranges.max = 30.0f; break; case paramInsane: @@ -136,7 +136,7 @@ void ZamTubePlugin::initParameter(uint32_t index, Parameter& parameter) parameter.name = "Quality Insane"; parameter.symbol = "insane"; parameter.unit = " "; - parameter.ranges.def = 1.0f; + parameter.ranges.def = 0.0f; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; break; @@ -223,9 +223,9 @@ void ZamTubePlugin::loadProgram(uint32_t index) middle = 5.f; treble = 5.f; tonestack = 0.0f; - mastergain = 0.0f; - insane = 1.0f; - insaneold = 1.0f; + mastergain = 15.0f; + insane = 0.0f; + insaneold = 0.0f; /* Default variable values */ @@ -251,7 +251,7 @@ void ZamTubePlugin::activate() co[0] = 10e-9; ro[0] = 1e+6; - /* Matt's preamp */ + /* Matt's preamp ci[1] = 100e-9; rg[1] = 1.; rk[1] = 820.; @@ -260,6 +260,7 @@ void ZamTubePlugin::activate() er[1] = 120e+3; co[1] = 4.7e-9; ro[1] = 470e+3; + */ /* CLA's preamp ci[1] = 1.0e-7; @@ -273,8 +274,9 @@ void ZamTubePlugin::activate() */ int pre = 0; - ckt.updateRValues(ci[pre], ck[pre], co[pre], e[pre], er[pre], rg[pre], 0., rk[pre], 136e+3, ro[pre], Fs, v); - ckt.t.insane = insane; + float volumepot = 1e+6; + ckt.on = false; + ckt.updateRValues(ci[pre], ck[pre], co[pre], e[pre], er[pre], rg[pre], volumepot, rk[pre], 136e+3, ro[pre], Fs, v); ckt.warmup_tubes(); fSamplingFreq = Fs; @@ -282,7 +284,19 @@ void ZamTubePlugin::activate() fConst0 = (2 * float(MIN(192000, MAX(1, fSamplingFreq)))); fConst1 = faustpower<2>(fConst0); fConst2 = (3 * fConst0); - for (int i=0; i<4; i++) fRec0[i] = 0; + fRec0[3] = 0.f; + fRec0[2] = 0.f; + fRec0[1] = 0.f; + fRec0[0] = 0.f; +} + +void ZamTubePlugin::deactivate() +{ + ckt.warmup_tubes(); + fRec0[3] = 0.f; + fRec0[2] = 0.f; + fRec0[1] = 0.f; + fRec0[0] = 0.f; } void ZamTubePlugin::run(const float** inputs, float** outputs, uint32_t frames) @@ -339,23 +353,14 @@ void ZamTubePlugin::run(const float** inputs, float** outputs, uint32_t frames) float tubeout = 0.f; - if (insane != insaneold) { - ckt.reset_tubes(); - ckt.warmup_tubes(); - fRec0[3] = fRec0[2] = fRec0[1] = fRec0[0] = 0.f; - insaneold = insane; - } - int pre = insane < 0.5 ? 0 : 1; - float volumepot = tubedrive / 11. * 1e+6; - ckt.updateRValues(ci[pre], ck[pre], co[pre], e[pre], er[pre], rg[pre], volumepot, rk[pre], 136e+3, ro[pre], getSampleRate(), v); + float cut = insane ? 0. : -15.; + float pregain = from_dB(tubedrive*3.6364 + cut); + float postgain = from_dB(mastergain + 36.*(1. - tubedrive/11.)); - double pregain = from_dB(tubedrive*3.6364 + 15.); - double postgain = from_dB(mastergain*3.) / e[pre]; - for (uint32_t i = 0; i < frames; ++i) { //Step 1: read input sample as voltage for the source - double in = inputs[0][i] * pregain; + float in = inputs[0][i] * pregain; // protect against overflowing circuit in = fabs(in) < DANGER ? in : 0.f; @@ -363,7 +368,7 @@ void ZamTubePlugin::run(const float** inputs, float** outputs, uint32_t frames) tubeout = ckt.advanc(in) * postgain; //Tone Stack (post tube) - fRec0[0] = ((float)tubeout - (fSlow31 * (((fSlow30 * fRec0[1]) + (fSlow29 * fRec0[2])) + (fSlow27 * fRec0[3])))); + fRec0[0] = ((float)tubeout - (fSlow31 * (((fSlow30 * fRec0[1]) + (fSlow29 * fRec0[2])) + (fSlow27 * fRec0[3])))) + 1e-20; outputs[0][i] = sanitize_denormal((float)(fSlow31 * ((((fSlow46 * fRec0[0]) + (fSlow45 * fRec0[1])) + (fSlow43 * fRec0[2])) + (fSlow41 * fRec0[3])))); // update filter states diff --git a/plugins/ZamTube/ZamTubePlugin.hpp b/plugins/ZamTube/ZamTubePlugin.hpp index 1a39810..d576579 100644 --- a/plugins/ZamTube/ZamTubePlugin.hpp +++ b/plugins/ZamTube/ZamTubePlugin.hpp @@ -34,7 +34,7 @@ template <> inline int faustpower<1>(int x) { return x; } typedef long double quad; #define TOLERANCE 1e-6 -#define DANGER 1000.f +#define DANGER 180.f #define R1 0 #define R2 1 @@ -152,6 +152,7 @@ Wave digital filter physical model of a triode tube amplifier stage, with modell } void activate() override; + void deactivate() override; void run(const float** inputs, float** outputs, uint32_t frames) override; // ------------------------------------------------------------------- diff --git a/plugins/ZamTube/ZamTubeUI.cpp b/plugins/ZamTube/ZamTubeUI.cpp index 3cd41d0..2dfd013 100644 --- a/plugins/ZamTube/ZamTubeUI.cpp +++ b/plugins/ZamTube/ZamTubeUI.cpp @@ -52,7 +52,6 @@ ZamTubeUI::ZamTubeUI() fKnobTube->setRange(0.1f, 11.0f); fKnobTube->setLabel(true); fKnobTube->setScrollStep(1.0f); - fKnobTube->setUsingLogScale(true); fKnobTube->setDefault(0.1f); fKnobTube->setRotationAngle(240); fKnobTube->setCallback(this); @@ -86,10 +85,10 @@ ZamTubeUI::ZamTubeUI() fKnobGain = new ZamKnob(this, knobImage); fKnobGain->setAbsolutePos(63, 231); - fKnobGain->setRange(-30.f, 30.0f); + fKnobGain->setRange(0.f, 30.0f); fKnobGain->setLabel(true); fKnobGain->setScrollStep(1.f); - fKnobGain->setDefault(0.0f); + fKnobGain->setDefault(15.0f); fKnobGain->setRotationAngle(240); fKnobGain->setCallback(this); @@ -155,8 +154,8 @@ void ZamTubeUI::programLoaded(uint32_t index) fKnobBass->setValue(5.f); fKnobMids->setValue(5.f); fKnobTreb->setValue(5.f); - fKnobGain->setValue(0.0f); - fToggleInsane->setDown(true); + fKnobGain->setValue(15.0f); + fToggleInsane->setDown(false); fSliderNotch->setValue(0.0f); } diff --git a/plugins/ZamTube/triode.cpp b/plugins/ZamTube/triode.cpp index dfa2505..a847a2f 100644 --- a/plugins/ZamTube/triode.cpp +++ b/plugins/ZamTube/triode.cpp @@ -29,7 +29,7 @@ T Triode::getIa(T Vgk, T Vpk) { if (!prepared) { const double L2 = log(2.0); - const double scale = 2e+9*pow(L2, kx-2.0)/(8.0*pow(kp, kx)); + const double scale = 1e+6*pow(L2, kx-2.0)/(8.0*pow(kp, kx)); coeff[0] = 8.0*L2*L2*scale; coeff[1] = kx*kp*L2*4.0*scale; coeff[2] = (kp*kp*kx*kx + L2*kp*kp*kx - kp*kp*kx) * scale; @@ -45,9 +45,9 @@ T Triode::getIa(T Vgk, T Vpk) { } double A = 1./mu + Vgk / sqrt(kvb + Vpk*Vpk); - return (coeff[0] + coeff[1]*A + coeff[2]*A*A) / kg1; + return Vpk*(coeff[0] + coeff[1]*A + coeff[2]*A*A) / kg1; - /* exact solution (takes > 300x longer) + /* exact solution (takes > 3x longer) e1 = Vpk*log1p(exp(kp*(1./mu+Vgk/sqrt(kvb+Vpk*Vpk))))/kp; if (e1 < 0) { return 0.; @@ -56,14 +56,10 @@ T Triode::getIa(T Vgk, T Vpk) { */ } -T Triode::evaluateImplicitEquation(T Vak, T Vgk, T a, T R){ - T Iak = getIa(Vgk, Vak); - return Vak + R*Iak - a; -} - T Triode::iterateNewtonRaphson(T x, T dx, T Vgk, T a, T R){ - T F = evaluateImplicitEquation(x, Vgk, a, R); - T xNew = x - dx*F/(evaluateImplicitEquation(x + dx, Vgk, a, R) - F); + T xIak = getIa(Vgk, x); + T dxIak = getIa(Vgk, x + dx); + T xNew = x - dx*(x + R*xIak - a)/(dx + R*(dxIak - xIak)); return xNew; } diff --git a/plugins/ZamTube/triode.h b/plugins/ZamTube/triode.h index ae552fe..1d3b927 100644 --- a/plugins/ZamTube/triode.h +++ b/plugins/ZamTube/triode.h @@ -37,7 +37,6 @@ public: Triode(); T compute(T a, T R, T Vg, T Vk); T getIa(T Vgk, T Vak); - T evaluateImplicitEquation(T Vak, T Vgk, T a, T R); T iterateNewtonRaphson(T x, T dx, T Vgk, T a, T R); bool insane; }; diff --git a/plugins/ZamTube/wdfcircuits.h b/plugins/ZamTube/wdfcircuits.h index 37203a1..aab382f 100644 --- a/plugins/ZamTube/wdfcircuits.h +++ b/plugins/ZamTube/wdfcircuits.h @@ -10,7 +10,6 @@ public: bool on; TubeStageCircuit() { - on = false; reset_tubes(); warmup_tubes(); } @@ -18,7 +17,7 @@ public: void warmup_tubes(void) { int i; on = false; - for (i = 0; i < 100; i++) { + for (i = 0; i < 5000; i++) { advanc(0.0); } on = true; |