Skip to content

Commit 6704b9e

Browse files
committed
Cached Balancing
1 parent 5526960 commit 6704b9e

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

Plateau2/Plateau2.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ Plateau2::Plateau2(const InstanceInfo& info)
134134
Knobs[16] = new NeedleKnob(IRECT::MakeXYWH(93, 294, 56, 56), NeedleSVG, NeedleBGSVG, NeedleFG1PNG, NeedleFG2PNG, kWidth1, kWidth2);
135135
Knobs[17] = new NeedleKnob(IRECT::MakeXYWH(166, 294, 56, 56), NeedleSVG, NeedleBGSVG, NeedleFG1PNG, NeedleFG2PNG, kPan1, kPan2);
136136

137-
Knobs[18] = new NeedleKnob(IRECT::MakeXYWH(130, 454, 56, 56), NeedleSVG, NeedleBGSVG, NeedleFG1PNG, NeedleFG2PNG, k1to2Level, k2to1Level);
137+
Knobs[18] = new NeedleKnob(IRECT::MakeXYWH(93, 454, 56, 56), NeedleSVG, NeedleBGSVG, NeedleFG1PNG, NeedleFG2PNG, k1to2Level, k2to1Level);
138+
Knobs[19] = new NeedleKnob(IRECT::MakeXYWH(166, 454, 56, 56), NeedleSVG, NeedleBGSVG, NeedleFG1PNG, NeedleFG2PNG, k1to2Delay, k2to1Delay);
138139

139-
for (int i = 12; i <= 18; i++) {
140+
for (int i = 12; i <= 19; i++) {
140141
pGraphics->AttachControl(Knobs[i]);
141142
Knobs[i]->Hide(true);
142143
}
@@ -292,7 +293,7 @@ void Plateau2::UpdateSendVisibility() {
292293
Switches[i]->Hide(currentPage != 2);
293294
}
294295
bool dangerous = GetParam(kDanger)->Value();
295-
for (int i = 18; i <= 18; i++) {
296+
for (int i = 18; i <= 19; i++) {
296297
Knobs[i]->Hide(currentPage != 2 || (!dangerous && tank2Selected));
297298
}
298299
SVGs[0]->Hide(currentPage != 2 || tank2Selected);
@@ -391,6 +392,12 @@ void Plateau2::OnParamChange(int index)
391392
reverb1.setTankDiffusionDecay(scale<double>(GetParam(index)->Value(), 0, 100, .3, 1));
392393
}
393394
break;
395+
case kStereoSource1:
396+
sourceBalance1 = balanceFactors(GetParam(kStereoSource1)->Value()/100);
397+
break;
398+
case kPan1:
399+
panBalance1 = balanceFactors(GetParam(kPan1)->Value()/100);
400+
break;
394401

395402
case kPreDelay2:
396403
reverb2.setPreDelay(GetParam(index)->Value());
@@ -454,6 +461,12 @@ void Plateau2::OnParamChange(int index)
454461
else {
455462
reverb2.setTankDiffusionDecay(scale<double>(GetParam(index)->Value(), 0, 100, .3, 1));
456463
}
464+
break;
465+
case kStereoSource2:
466+
sourceBalance2 = balanceFactors(GetParam(kStereoSource2)->Value()/100);
467+
break;
468+
case kPan2:
469+
panBalance2 = balanceFactors(GetParam(kPan2)->Value()/100);
457470
break;
458471

459472
case kDanger:
@@ -561,12 +574,12 @@ void Plateau2::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
561574
reverb1.freeze(frozen1);
562575
}
563576

564-
reverb1.process(balance((double)(envelope1._value * (inputs[0][s] * input1 + (send2to1 ? (std::get<0>(reverbOut2) * level2to1) : 0))), (double)(envelope1._value * (inputs[nChans > 1 ? 1 : 0][s] * input1 + (send2to1 ? (std::get<1>(reverbOut2) * level2to1) : 0))), GetParam(kStereoSource1)->Value() / 100));
577+
reverb1.process((double)(std::get<0>(sourceBalance1) * envelope1._value * (inputs[0][s] * input1 + (send2to1 ? (std::get<0>(reverbOut2) * level2to1) : 0))), (double)(std::get<1>(sourceBalance1) * envelope1._value * (inputs[nChans > 1 ? 1 : 0][s] * input1 + (send2to1 ? (std::get<1>(reverbOut2) * level2to1) : 0))));
565578

566579
reverbOut1 = { reverb1.getLeftOutput(), reverb1.getRightOutput() };
567580

568581
std::tuple<double,double> out = seperation(std::get<0>(reverbOut1), std::get<1>(reverbOut1), GetParam(kWidth1)->Value() / 100);
569-
out = balance(std::get<0>(out), std::get<1>(out), GetParam(kPan1)->Value()/100);
582+
out = { std::get<0>(panBalance1) * std::get<0>(out), std::get<1>(panBalance1)* std::get<1>(out) };
570583

571584
outputs[0][s] += std::get<0>(out) * wet1Param;
572585

@@ -625,12 +638,12 @@ void Plateau2::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
625638
reverb2.freeze(frozen2);
626639
}
627640

628-
reverb2.process(balance((double)(envelope2._value * (inputs[0][s] * input2 + (send1to2 ? (std::get<0>(reverbOut1) * level1to2) : 0))), (double)(envelope2._value*(inputs[nChans > 1 ? 1 : 0][s] * input2 + (send1to2 ? (std::get<1>(reverbOut1) * level1to2) : 0))), GetParam(kStereoSource2)->Value() / 100));
641+
reverb2.process((double)(std::get<0>(sourceBalance2) * envelope2._value * (inputs[0][s] * input2 + (send1to2 ? (std::get<0>(reverbOut1) * level1to2) : 0))), (double)(std::get<1>(sourceBalance2) * envelope2._value*(inputs[nChans > 1 ? 1 : 0][s] * input2 + (send1to2 ? (std::get<1>(reverbOut1) * level1to2) : 0))));
629642

630643
reverbOut2 = { reverb2.getLeftOutput(), reverb2.getRightOutput() };
631644

632645
std::tuple<double, double> out = seperation(std::get<0>(reverbOut2), std::get<1>(reverbOut2), GetParam(kWidth2)->Value()/100);
633-
out = balance(std::get<0>(out), std::get<1>(out), GetParam(kPan2)->Value()/100);
646+
out = { std::get<0>(panBalance2) * std::get<0>(out), std::get<1>(panBalance2) * std::get<1>(out) };
634647

635648
outputs[0][s] += std::get<0>(out) * wet2Param;
636649

Plateau2/Plateau2.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum EParams
4545
kPan1,
4646
k1to2,
4747
k1to2Level,
48+
k1to2Delay,
4849

4950
kEnable2,
5051
kWet2,
@@ -72,13 +73,14 @@ enum EParams
7273
kPan2,
7374
k2to1,
7475
k2to1Level,
76+
k2to1Delay,
7577

7678
kDanger,
7779

7880
kNumParams
7981
};
8082

81-
const int kNumKnobs = 19;
83+
const int kNumKnobs = 20;
8284
const int kNumSwitches = 8;
8385
const int kNumButtons = 2;
8486
const int kNumPages = 3;
@@ -105,8 +107,11 @@ class Plateau2 final : public Plugin
105107
#endif
106108
private:
107109
Dattorro reverb1;
108-
std::tuple<double, double> reverbOut1 = {0,0};
110+
std::tuple<double, double> reverbOut1 = { 0,0 };
111+
std::tuple<double, double> sourceBalance1 = { 0, 0 };
112+
std::tuple<double, double> panBalance1 = { 0, 0 };
109113
LinearEnvelope envelope1;
114+
InterpDelay<double> send1To2Delay;
110115
bool clear1 = false;
111116
bool cleared1 = true;
112117
bool fadeOut1 = false;
@@ -115,7 +120,10 @@ class Plateau2 final : public Plugin
115120

116121
Dattorro reverb2;
117122
std::tuple<double, double> reverbOut2 = { 0,0 };
123+
std::tuple<double, double> sourceBalance2 = { 0, 0 };
124+
std::tuple<double, double> panBalance2 = { 0, 0 };
118125
LinearEnvelope envelope2;
126+
InterpDelay<double> send2To1Delay;
119127
bool clear2 = false;
120128
bool cleared2 = true;
121129
bool fadeOut2 = false;

Plateau2/dsp/Dattorro.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,7 @@ Dattorro::Dattorro(const double initMaxSampleRate,
292292
rightInputDCBlock.setCutoffFreq(20.0);
293293
}
294294

295-
void Dattorro::process(std::tuple<double, double> input) {
296-
double leftInput = std::get<0>(input);
297-
double rightInput = std::get<1>(input);
298-
295+
void Dattorro::process(double leftInput, double rightInput) {
299296
leftInputDCBlock.input = leftInput;
300297
rightInputDCBlock.input = rightInput;
301298
inputLpf.setCutoffFreq(inputHighCut);

Plateau2/dsp/Dattorro.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Dattorro {
165165
Dattorro(const double initMaxSampleRate = 44100.0,
166166
const double initMaxLfoDepth = 16.0,
167167
const double initMaxTimeScale = 1.0);
168-
void process(std::tuple<double, double> input);
168+
void process(double leftInput, double rightInput);
169169
void clear();
170170

171171
void setTimeScale(double timeScale);

Plateau2/dsp/Utilities.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ T semitone(T x) {
2626
return ((int)(x * 12)) * 0.0833333f;
2727
}
2828

29-
std::tuple<double, double> balance(double left, double right, double pan) {
29+
std::tuple<double, double> balanceFactors(double pan) {
3030
//Circular Equal Power Panning from pan -1 to 1
3131
return {
32-
left * std::cos((pan + 1) * _TAU / 8),
33-
right * std::sin((pan + 1) * _TAU / 8)
32+
std::cos((pan + 1) * _TAU / 8),
33+
std::sin((pan + 1) * _TAU / 8)
3434
};
3535
}
3636

37+
3738
std::tuple<double, double> seperation(double left, double right, double width) {
3839
double mid = (left + right) * 0.5; // Mid (Mono)
3940
double side = (left - right) * 0.5; // Side (Stereo Width)

0 commit comments

Comments
 (0)