Skip to content

Commit

Permalink
New Width mode
Browse files Browse the repository at this point in the history
if the FXConfig has width mode as a bool set to true
in the var static constexpr bool widthIsLinear then
width is no linger +/- 24db but is insteadn +/- 200%
or 6db->inf and inverting same.
  • Loading branch information
baconpaul committed Jul 6, 2024
1 parent e63fe46 commit 48052ee
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 14 deletions.
4 changes: 2 additions & 2 deletions include/sst/effects/Delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ template <typename FXConfig> struct Delay : core::EffectTemplateBase<FXConfig>
case dly_mix:
return pmd().withName("Mix").asPercent().withDefault(0.5f);
case dly_width:
return pmd().withName("Width").asDecibelNarrow().withDefault(0.f);
return this->getWidthParam();
}
return {};
}
Expand Down Expand Up @@ -282,7 +282,7 @@ template <typename FXConfig> inline void Delay<FXConfig>::setvars(bool init)
}

mix.set_target_smoothed(this->floatValue(dly_mix));
width.set_target_smoothed(this->dbToLinear(this->floatValue(dly_width)));
this->setWidthTarget(width, dly_width);
pan.set_target_smoothed(std::clamp(this->floatValue(dly_input_channel), -1.f, 1.f));

lp.coeff_LP2B(lp.calc_omega(this->floatValue(dly_highcut) / 12.0), 0.707);
Expand Down
30 changes: 30 additions & 0 deletions include/sst/effects/EffectCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
// For shared width calculations
#include "sst/basic-blocks/dsp/MidSide.h"
#include "sst/basic-blocks/dsp/BlockInterpolators.h"
#include "sst/basic-blocks/params/ParamMetadata.h"
#include "sst/filters/BiquadFilter.h"

#include "EffectCoreDetails.h"
Expand Down Expand Up @@ -243,6 +244,35 @@ template <typename FXConfig> struct EffectTemplateBase : public FXConfig::BaseCl
}

static constexpr int slowrate{8}, slowrate_m1{slowrate - 1};

static constexpr bool useLinearWidth()
{
if constexpr (details::Has_widthIsLinear<FXConfig>::value)
{
return FXConfig::widthIsLinear;
}
else
{
return false;
}
}

basic_blocks::params::ParamMetaData getWidthParam() const
{
auto res = basic_blocks::params::ParamMetaData().withName("Width");
if constexpr (!useLinearWidth())
return res.asDecibelNarrow().withDefault(0.f);
else
return res.asPercentBipolar().withRange(-2.f, 2.f).withDefault(1.f);
}

template <typename Smoother> void setWidthTarget(Smoother &width, int idx, float scale = 1.f)
{
if constexpr (!useLinearWidth())
width.set_target_smoothed(this->dbToLinear(this->floatValue(idx)) * scale);
else
width.set_target_smoothed(this->floatValue(idx));
}
};
} // namespace sst::effects::core

Expand Down
3 changes: 3 additions & 0 deletions include/sst/effects/EffectCoreDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ HAS_MEMBER(floatValueExtendedAt);
HAS_MEMBER(temposyncInitialized);
HAS_MEMBER(temposyncRatioInv);
HAS_MEMBER(deformType);

HAS_MEMBER(widthIsLinear);

#undef HAS_MEMBER

} // namespace sst::effects::core::details
Expand Down
5 changes: 2 additions & 3 deletions include/sst/effects/Flanger.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ template <typename FXConfig> struct Flanger : core::EffectTemplateBase<FXConfig>
case fl_damping:
return result.withName("HF Damping").asPercent().withDefault(0.1f);
case fl_width:
return result.withName("Width").asDecibelNarrow().withDefault(0.f);
return this->getWidthParam();
case fl_mix:
return result.withName("Mix").asPercentBipolar().withDefault(0.8f);
case fl_num_params:
Expand Down Expand Up @@ -591,8 +591,7 @@ inline void Flanger<FXConfig>::processBlock(float *__restrict dataL, float *__re
voices.process();
}

width.set_target_smoothed(this->dbToLinear(this->floatValue(fl_width)) / 3);

this->setWidthTarget(width, fl_width, 1.0 / 3.0);
this->applyWidth(dataL, dataR, width);
}

Expand Down
5 changes: 3 additions & 2 deletions include/sst/effects/Phaser.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ template <typename FXConfig> struct Phaser : core::EffectTemplateBase<FXConfig>

feedback.newValue(0.95f * this->floatValue(ph_feedback));
tone.newValue(std::clamp(this->floatValue(ph_tone), -1.f, 1.f));
width.set_target_smoothed(this->dbToLinear(this->floatValue(ph_width)));

this->setWidthTarget(width, ph_width);

// lowpass range is from MIDI note 136 down to 57 (~21.1 kHz down to 220 Hz)
// highpass range is from MIDI note 34 to 136(~61 Hz to ~21.1 kHz)
Expand Down Expand Up @@ -324,7 +325,7 @@ fxdata->p[ph_mod_rate].deactivated = false;
case ph_mix:
return pmd().asPercent().withName("Mix").withDefault(0.5);
case ph_width:
return pmd().withName("Width").asDecibelNarrow().withDefault(0.f);
return this->getWidthParam();
case ph_tone:
return pmd().withName("Tone").asPercentBipolar().deactivatable(true).withDefault(0.f);
case ph_mod_rate:
Expand Down
4 changes: 2 additions & 2 deletions include/sst/effects/Reverb1.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ template <typename FXConfig> struct Reverb1 : core::EffectTemplateBase<FXConfig>
case rev1_mix:
return result.withName("Mix").asPercent().withDefault(0.5f);
case rev1_width:
return result.withName("Width").asDecibelNarrow().withDefault(0.f);
return this->getWidthParam();
default:
break;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ inline void Reverb1<FXConfig>::processBlock(float *__restrict dataL, float *__re
b = (b + 1) & 31;

mix.set_target_smoothed(this->floatValue(rev1_mix));
width.set_target_smoothed(this->dbToLinear(this->floatValue(rev1_width)));
this->setWidthTarget(width, rev1_width);

int pdtime = (int)(float)this->sampleRate() *
this->noteToPitchIgnoringTuning(12 * this->floatValue(rev1_predelay)) *
Expand Down
11 changes: 6 additions & 5 deletions include/sst/effects/Reverb2.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ template <typename FXConfig> struct Reverb2 : core::EffectTemplateBase<FXConfig>
return pmd().asPercent().withName("Mix").withDefault(0.33f);

case rev2_width:
return pmd().withName("Width").asDecibelNarrow().withDefault(0.f);
return this->getWidthParam();

default:
return pmd().asPercentBipolar().withName("ERROR " + std::to_string(idx));
Expand Down Expand Up @@ -329,7 +329,7 @@ template <typename FXConfig> void Reverb2<FXConfig>::update_rtime()
// * 2.f is to get the dB120 time
auto pdlyt = std::max(0.1f, powf(2.f, this->floatValue(rev2_predelay)) * ts) * 2.f;
auto dcyt = std::max(1.0f, powf(2.f, this->floatValue(rev2_decay_time))) * 2.f;
float t = (this->sampleRate() * (dcyt + pdlyt)) / FXConfig::blockSize;
float t = (this->sampleRate() * (dcyt + pdlyt)) / FXConfig::blockSize;

ringout_time = (int)t;
}
Expand Down Expand Up @@ -407,14 +407,15 @@ template <typename FXConfig> void Reverb2<FXConfig>::processBlock(float *dataL,
_lf_damp_coefficent.newValue(0.2 * this->floatValue(rev2_lf_damping));
_modulation.newValue(this->floatValue(rev2_modulation) * this->sampleRate() * 0.001f * 5.f);

width.set_target_smoothed(this->dbToLinear(this->floatValue(rev2_width)));
this->setWidthTarget(width, rev2_width);

mix.set_target_smoothed(this->floatValue(rev2_mix));

_lfo.set_rate(2.0 * M_PI * powf(2, -2.f) / this->sampleRate());

int pdt = std::clamp((int)(this->sampleRate() * pow(2.f, this->floatValue(rev2_predelay)) *
this->temposyncRatioInv(rev2_predelay)),
1, PREDELAY_BUFFER_SIZE_LIMIT - 1);
this->temposyncRatioInv(rev2_predelay)),
1, PREDELAY_BUFFER_SIZE_LIMIT - 1);

for (int k = 0; k < FXConfig::blockSize; k++)
{
Expand Down

0 comments on commit 48052ee

Please sign in to comment.