commit 0005d2d7e510be1a57a38b05aba06969d190ccfb
parent 9c747cb61b880a033f7707c293113c4c36d5c8de
Author: Matt Demanett <matt@demanett.net>
Date: Wed, 22 Apr 2020 00:37:34 -0400
SWITCH* matrix mixers: modest performance improvements.
Diffstat:
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/matrix_base.cpp b/src/matrix_base.cpp
@@ -39,12 +39,31 @@ int MatrixModule::channels() {
return inputs[_firstInputID].getChannels();
}
+void MatrixModule::modulate() {
+ for (int i = 0, nn = _n * _n; i < nn; ++i) {
+ _paramValues[i] = params[_firstParamID + i].getValue();
+ }
+}
+
void MatrixModule::processChannel(const ProcessArgs& args, int c) {
+ bool inActive[maxN];
+ float in[maxN];
for (int i = 0; i < _n; ++i) {
- int paramOffset = _firstParamID + i * _n;
+ inActive[i] = inputs[_firstInputID + i].isConnected();
+ if (inActive[i]) {
+ in[i] = inputs[_firstInputID + i].getPolyVoltage(c) * _inputGainLevel;
+ }
+ }
+
+ for (int i = 0; i < _n; ++i) {
+ if (!outputs[_firstOutputID + i].isConnected()) {
+ continue;
+ }
float out = 0.0f;
for (int j = 0; j < _n; ++j) {
- out += inputs[_firstInputID + j].getPolyVoltage(c) * _inputGainLevel * params[paramOffset + j].getValue();
+ if (inActive[i]) {
+ out += in[j] * _paramValues[i * _n + j];
+ }
}
if (_clippingMode != HARD_CLIPPING) {
out = _saturators[c * _n + i].next(out);
diff --git a/src/matrix_base.hpp b/src/matrix_base.hpp
@@ -45,10 +45,13 @@ struct MatrixBaseModuleWidget : ModuleWidget {
};
struct MatrixModule : MatrixBaseModule {
+ static constexpr int maxN = 16;
int _n;
int _firstParamID;
int _firstInputID;
int _firstOutputID;
+
+ float* _paramValues = NULL;
Saturator* _saturators = NULL;
MatrixModule(int n, int firstParamID, int firstInputID, int firstOutputID)
@@ -57,13 +60,17 @@ struct MatrixModule : MatrixBaseModule {
, _firstInputID(firstInputID)
, _firstOutputID(firstOutputID)
{
+ assert(_n <= maxN);
+ _paramValues = new float[_n * _n];
_saturators = new Saturator[_n * maxChannels];
}
virtual ~MatrixModule() {
+ delete[] _paramValues;
delete[] _saturators;
}
int channels() override;
+ void modulate() override;
void processChannel(const ProcessArgs& args, int c) override;
};