2
2
#include " BaconModule.hpp"
3
3
#include " BaconModuleWidget.h"
4
4
5
+ #include " sst/basic-blocks/dsp/HilbertTransform.h"
6
+ #include " sst/basic-blocks/dsp/QuadratureOscillators.h"
7
+
5
8
namespace bp = baconpaul::rackplugs;
6
9
7
10
struct BaconTest : bp::BaconModule
@@ -30,6 +33,10 @@ struct BaconTest : bp::BaconModule
30
33
NUM_LIGHTS
31
34
};
32
35
36
+ sst::basic_blocks::dsp::HilbertTransformMonoFloat hilbertMono;
37
+ sst::basic_blocks::dsp::HilbertTransformStereoSSE hilbert;
38
+ sst::basic_blocks::dsp::QuadratureOscillator<float > qo;
39
+
33
40
BaconTest ()
34
41
{
35
42
config (NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
@@ -43,7 +50,43 @@ struct BaconTest : bp::BaconModule
43
50
}
44
51
}
45
52
46
- void process (const ProcessArgs &args) override {}
53
+ double theSampleRate{1 };
54
+ void onSampleRateChange (const SampleRateChangeEvent &e) override
55
+ {
56
+ qo.setRate (2.0 * M_PI * 50 * e.sampleTime );
57
+ hilbert.setSampleRate (e.sampleRate );
58
+ hilbertMono.setSampleRate (e.sampleRate );
59
+ Module::onSampleRateChange (e);
60
+ }
61
+ float lrt = -1 .f;
62
+ float prior[2 ]{0 .f , 0 .f };
63
+ void process (const ProcessArgs &args) override {
64
+ auto iL = inputs[INPUT_0].getVoltage () / 5 .0f ;
65
+ auto iR = inputs[INPUT_0 + 1 ].getVoltage () / 5 .0f ;
66
+
67
+ qo.step ();
68
+
69
+ if (params[PARAM_0].getValue () != lrt)
70
+ {
71
+ lrt = params[PARAM_0].getValue ();
72
+ auto rf = lrt * 800 - 200 ;
73
+ qo.setRate (2.0 * M_PI * rf * args.sampleTime );
74
+ }
75
+ auto fb = params[PARAM_0 + 1 ].getValue ();
76
+ iL = 0.8 * ( iL + fb * fb * fb * prior[0 ] );
77
+ iR = 0.8 * ( iR + fb * fb * fb * prior[1 ] );
78
+
79
+ auto [L, R] = hilbert.stepToPair (iL, iR);
80
+
81
+ auto [re, im] = L;
82
+
83
+ auto [reR, imR] = R;
84
+
85
+ prior[0 ] = (re * qo.v - im * qo.u );
86
+ prior[1 ] = (reR * qo.v - imR * qo.u );
87
+ outputs[OUTPUT_0+0 ].setVoltage (prior[0 ] * 5 .f );
88
+ outputs[OUTPUT_0+1 ].setVoltage (prior[1 ] * 5 .f );
89
+ }
47
90
};
48
91
49
92
struct BaconTestWidget : bp::BaconModuleWidget
0 commit comments