Skip to content

Commit

Permalink
ZamTube: Use two tube stages with tonestack in between
Browse files Browse the repository at this point in the history
This gives the best of both combinations of tonestack position,
and insane mode just changes the behaviour of the first tube stage.
  • Loading branch information
zamaudio committed Oct 21, 2023
1 parent b8b2a42 commit 462c82a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions plugins/ZamTube/ZamTubePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ void ZamTubePlugin::activate()
ro[0] = 100e+3;
*/

ckt.updateRValues(ci[0], ck[0], co[0], e[0], er[0], rg[0], 800e+3, rk[0], 1e+3, ro[0], Fs);
ckt[0].updateRValues(ci[0], ck[0], co[0], e[0], er[0], rg[0], 800e+3, rk[0], 1e+3, ro[0], Fs);
ckt[1].updateRValues(ci[0], ck[0], co[0], e[0], er[0], rg[0], 800e+3, rk[0], 1e+3, ro[0], Fs);
ckt[0].set_mode(ckt[0].TUBE_MODE_SIXTIES);
ckt[1].set_mode(ckt[1].TUBE_MODE_SIXTIES);

fSamplingFreq = Fs;

Expand Down Expand Up @@ -412,7 +415,7 @@ void ZamTubePlugin::run(const float** inputs, float** outputs, uint32_t frames)
float scaled_drive = (tubedrive - 0.1) / 10.9;

float pregain = from_dB(scaled_drive * 20.);
float postgain = from_dB(mastergain - 6.) * 0.01;
float postgain = from_dB(mastergain - 48.);

if ((tonestackold != stack) || (bassold != bass) ||
(middleold != middle) || (trebleold != treble)) {
Expand All @@ -425,21 +428,22 @@ void ZamTubePlugin::run(const float** inputs, float** outputs, uint32_t frames)

if (insaneold != (int)insane) {
insaneold = (int)insane;
ckt.set_mode(insane > 0.5 ? ckt.TUBE_MODE_GRIDLEAK : ckt.TUBE_MODE_SIXTIES);
ckt.updateRValues(ci[0], ck[0], co[0], e[0], er[0], rg[0], 800e+3, rk[0], 1e+3, ro[0], getSampleRate());
ZamTubePlugin::deactivate();
ckt[0].set_mode(insane > 0.5 ? ckt[0].TUBE_MODE_GRIDLEAK : ckt[0].TUBE_MODE_SIXTIES);
ckt[0].updateRValues(ci[0], ck[0], co[0], e[0], er[0], rg[0], 800e+3, rk[0], 1e+3, ro[0], getSampleRate());
}

for (uint32_t i = 0; i < frames; ++i) {

//Step 1: read input sample as voltage for the source
float in = inputs[0][i] * pregain;

tubeout = ckt.run(in) * postgain;
tubeout = ckt[0].run(in) * 0.01;

//Tone Stack (post tube)
//Tone Stack (sandwiched between two tube stages)
fRec0[0] = ((float)tubeout - (fSlow31 * (((fSlow30 * fRec0[1]) + (fSlow29 * fRec0[2])) + (fSlow27 * fRec0[3])))) + 1e-20f;
outputs[0][i] = sanitize_denormal((float)(fSlow31 * ((((fSlow46 * fRec0[0]) + (fSlow45 * fRec0[1])) + (fSlow43 * fRec0[2])) + (fSlow41 * fRec0[3]))));
tubeout = sanitize_denormal((float)(fSlow31 * ((((fSlow46 * fRec0[0]) + (fSlow45 * fRec0[1])) + (fSlow43 * fRec0[2])) + (fSlow41 * fRec0[3]))));

outputs[0][i] = ckt[1].run(tubeout) * postgain;

// update filter states
fRec0[3] = fRec0[2];
Expand Down
2 changes: 1 addition & 1 deletion plugins/ZamTube/ZamTubePlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef long double quad;
class ZamTubePlugin : public Plugin
{
public:
TubeStageCircuit ckt;
TubeStageCircuit ckt[2];
T ci[2];
T ck[2];
T co[2];
Expand Down

0 comments on commit 462c82a

Please sign in to comment.