commit e7bd80efcb94512964df8d50c76c3da30bd6f656
parent 4af2e2d38004b98645deb8a25c7ec74c7c8f1a03
Author: Matt Demanett <matt@demanett.net>
Date: Sat, 14 May 2022 16:16:15 -0400
Add no-output-clipping mode to matrix mixers. #199
Diffstat:
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/README-prerelease.md b/README-prerelease.md
@@ -775,7 +775,7 @@ A 4x4 channel matrix mixer. Each input can be routed with an independent level
*Note that the matrix knobs are attenuverters, and default to zero.* That means there will be no output, regardless of the inputs, until some knobs are changed to non-zero values. The knobs can be set to unipolar mode, as below; they still default to zero.
-Saturation (soft clipping) limits each output to +/-12V. This can be changed to a hard clip at +/-12V on the context menu ("Output clipping") -- as described on UMIX, this is mode is better if you need to precisely sum CVs.
+Saturation (soft clipping) limits each output to +/-12V. This can be changed to a hard clip at +/-12V on the context menu ("Output clipping") -- as described on UMIX, this is mode is better if you need to precisely sum CVs. Clipping may also be disabled entirely by setting "Output clipping" to "None".
Another context menu option allows the input gains to be reduced by up to 12db.
diff --git a/src/matrix_base.cpp b/src/matrix_base.cpp
@@ -20,7 +20,7 @@ void MatrixBaseModule::loadFromJson(json_t* root) {
json_t* c = json_object_get(root, CLIPPING_MODE);
if (c) {
_clippingMode = (Clipping)json_integer_value(c);
- if (_clippingMode != HARD_CLIPPING) {
+ if (_clippingMode != HARD_CLIPPING && _clippingMode != NO_CLIPPING) {
_clippingMode = SOFT_CLIPPING;
}
}
@@ -54,6 +54,7 @@ void MatrixBaseModuleWidget::contextMenu(Menu* menu) {
OptionsMenuItem* c = new OptionsMenuItem("Output clipping");
c->addItem(OptionMenuItem("Soft/saturated (better for audio)", [m]() { return m->_clippingMode == MatrixBaseModule::SOFT_CLIPPING; }, [m]() { m->_clippingMode = MatrixBaseModule::SOFT_CLIPPING; }));
c->addItem(OptionMenuItem("Hard/clipped (better for CV)", [m]() { return m->_clippingMode == MatrixBaseModule::HARD_CLIPPING; }, [m]() { m->_clippingMode = MatrixBaseModule::HARD_CLIPPING; }));
+ c->addItem(OptionMenuItem("None", [m]() { return m->_clippingMode == MatrixBaseModule::NO_CLIPPING; }, [m]() { m->_clippingMode = MatrixBaseModule::NO_CLIPPING; }));
OptionsMenuItem::addToMenu(c, menu);
menu->addChild(new OptionMenuItem("Average", [m]() { return !m->_sum; }, [m]() { m->_sum = !m->_sum; }));
@@ -154,12 +155,12 @@ void MatrixModule::processChannel(const ProcessArgs& args, int c) {
if (!_sum && _invActive > 0.0f) {
out *= _invActive;
}
- if (_clippingMode == HARD_CLIPPING) {
- out = clamp(out, -12.0f, 12.0f);
- }
- else {
+ if (_clippingMode == SOFT_CLIPPING) {
out = _saturators[c * _outs + i].next(out);
}
+ else if (_clippingMode == HARD_CLIPPING) {
+ out = clamp(out, -12.0f, 12.0f);
+ }
outputs[_firstOutputID + i].setChannels(_channels);
outputs[_firstOutputID + i].setVoltage(out, c);
}
diff --git a/src/matrix_base.hpp b/src/matrix_base.hpp
@@ -12,7 +12,8 @@ namespace bogaudio {
struct MatrixBaseModule : BGModule {
enum Clipping {
SOFT_CLIPPING,
- HARD_CLIPPING
+ HARD_CLIPPING,
+ NO_CLIPPING
};
Clipping _clippingMode = SOFT_CLIPPING;