Skip to content

Commit

Permalink
Deal with Poly NanCheck and Extra Inputs; Numbus Freeze (#962)
Browse files Browse the repository at this point in the history
The NanCheck and Extra Inputs get poly aware
So the spring reverb can be poly knocked
and nimbus can be poly frozen

Closes #961
  • Loading branch information
baconpaul authored Dec 4, 2023
1 parent 20ed579 commit 19cae08
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 24 deletions.
55 changes: 45 additions & 10 deletions src/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ template <int fxType> struct FXConfig
static constexpr int extraInputs() { return 0; }
static constexpr int extraSchmidtTriggers() { return 1; }
static void configExtraInputs(FX<fxType> *M) {}
static void processExtraInputs(FX<fxType> *M) {}
static void processExtraInputs(FX<fxType> *M, int channel) {}

static constexpr int extraOutputs() { return 0; }
static void configExtraOutputs(FX<fxType> *M) {}
Expand Down Expand Up @@ -134,6 +134,9 @@ struct FX : modules::XTModule, sst::rackhelpers::module_connector::NeighborConne
setupSurge();
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);

for (auto &t : extraInputTriggers)
t.state = false;

int lastParam{0};
for (int i = 0; i < n_fx_params; ++i)
{
Expand Down Expand Up @@ -549,7 +552,7 @@ struct FX : modules::XTModule, sst::rackhelpers::module_connector::NeighborConne
fxstorage->p[i].set_value_f01(modAssist.basevalues[i]);
}

FXConfig<fxType>::processExtraInputs(this);
FXConfig<fxType>::processExtraInputs(this, 0);
FXConfig<fxType>::adjustParamsBasedOnState(this);

copyGlobaldataSubset(storage_id_start, storage_id_end);
Expand Down Expand Up @@ -626,13 +629,21 @@ struct FX : modules::XTModule, sst::rackhelpers::module_connector::NeighborConne

int lastNChan{-1};

void reinitialize()
void reinitialize(int c = -1)
{
surge_effect->init();
halfbandIN.reset();
for (const auto &s : surge_effect_poly)
if (s)
s->init();
if (c == -1)
{
surge_effect->init();
halfbandIN.reset();
for (const auto &s : surge_effect_poly)
if (s)
s->init();
}
else
{
// poly nan case
surge_effect_poly[c]->init();
}
}

void guaranteePolyFX(int chan)
Expand Down Expand Up @@ -700,6 +711,7 @@ struct FX : modules::XTModule, sst::rackhelpers::module_connector::NeighborConne
modulatorR[0][bufferPos] = inputs[SIDEBAND_R].getVoltageSum();
}
}

bufferPos++;

if (bufferPos >= BLOCK_SIZE)
Expand All @@ -717,10 +729,10 @@ struct FX : modules::XTModule, sst::rackhelpers::module_connector::NeighborConne
fxstorage->p[i].set_value_f01(polyModAssist.basevalues[i]);
}

FXConfig<fxType>::processExtraInputs(this);

for (int c = 0; c < chan; ++c)
{
FXConfig<fxType>::processExtraInputs(this, c);

std::memcpy(processedL[c], bufferL[c], BLOCK_SIZE * sizeof(float));
std::memcpy(processedR[c], bufferR[c], BLOCK_SIZE * sizeof(float));

Expand Down Expand Up @@ -750,6 +762,29 @@ struct FX : modules::XTModule, sst::rackhelpers::module_connector::NeighborConne

FXConfig<fxType>::populateExtraOutputs(this, c, surge_effect_poly[c].get());
}

if constexpr (FXConfig<fxType>::nanCheckOutput())
{
if (lastNanCheck == 0)
{
for (int c = 0; c < chan; ++c)
{

bool isNumber{true};
for (int ns = 0; ns < BLOCK_SIZE; ++ns)
{
isNumber = isNumber && std::isfinite(processedL[c][ns]);
isNumber = isNumber && std::isfinite(processedR[c][ns]);
}

if (!isNumber)
{
reinitialize(c);
}
}
}
lastNanCheck = (lastNanCheck + 1) % 32;
}
bufferPos = 0;
}

Expand Down
6 changes: 4 additions & 2 deletions src/fxconfig/Chow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ template <> void FXConfig<fxt_chow>::configExtraInputs(FX<fxt_chow> *m)
* template <> void FXConfig<fxt_chow>::processSpecificParams(FX<fxt_chow> *m)
*/

template <> void FXConfig<fxt_chow>::processExtraInputs(FX<fxt_chow> *that)
template <> void FXConfig<fxt_chow>::processExtraInputs(FX<fxt_chow> *that, int channel)
{
auto t = that->inputs[FX<fxt_chow>::INPUT_SPECIFIC_0].getVoltage() > 3;
auto uc = channel * (that->inputs[FX<fxt_chow>::INPUT_SPECIFIC_0].getChannels() > 1);

auto t = that->inputs[FX<fxt_chow>::INPUT_SPECIFIC_0].getVoltage(uc) > 3;
auto d = that->params[FX<fxt_chow>::FX_SPECIFIC_PARAM_0].getValue() > 0.5;
if (t || d)
{
Expand Down
25 changes: 18 additions & 7 deletions src/fxconfig/Nimbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace sst::surgext_rack::fx

template <> constexpr int FXConfig<fxt_nimbus>::numParams() { return 12; }
template <> constexpr int FXConfig<fxt_nimbus>::extraInputs() { return 2; }
template <> constexpr int FXConfig<fxt_nimbus>::extraSchmidtTriggers() { return 1; }
template <> constexpr int FXConfig<fxt_nimbus>::extraSchmidtTriggers() { return MAX_POLY; }
template <> constexpr int FXConfig<fxt_nimbus>::specificParamCount() { return 2; }

template <> FXConfig<fxt_nimbus>::layout_t FXConfig<fxt_nimbus>::getLayout()
Expand Down Expand Up @@ -149,12 +149,15 @@ template <> void FXConfig<fxt_nimbus>::processSpecificParams(FX<fxt_nimbus> *m)
lv;
}

template <> void FXConfig<fxt_nimbus>::processExtraInputs(FX<fxt_nimbus> *that)
template <> void FXConfig<fxt_nimbus>::processExtraInputs(FX<fxt_nimbus> *that, int channel)
{
auto frozen = that->inputs[FX<fxt_nimbus>::INPUT_SPECIFIC_0].getVoltage() > 3;
auto uc = channel * (that->inputs[FX<fxt_nimbus>::INPUT_SPECIFIC_0].getChannels() > 1);
auto tc = channel * (that->inputs[FX<fxt_nimbus>::INPUT_SPECIFIC_0 + 1].getChannels() > 1);

auto frozen = that->inputs[FX<fxt_nimbus>::INPUT_SPECIFIC_0].getVoltage(uc) > 3;
frozen = frozen || (that->params[FX<fxt_nimbus>::FX_SPECIFIC_PARAM_0].getValue() > 0.5);
auto triggered = that->extraInputTriggers[0].process(
that->inputs[FX<fxt_nimbus>::INPUT_SPECIFIC_0 + 1].getVoltage());
auto triggered = that->extraInputTriggers[channel].process(
that->inputs[FX<fxt_nimbus>::INPUT_SPECIFIC_0 + 1].getVoltage(tc));

if (frozen)
{
Expand All @@ -165,8 +168,16 @@ template <> void FXConfig<fxt_nimbus>::processExtraInputs(FX<fxt_nimbus> *that)
that->fxstorage->p[NimbusEffect::nmb_freeze].set_value_f01(0);
}

auto nb = static_cast<NimbusEffect *>(that->surge_effect.get());
nb->setNimbusTrigger(triggered);
if (that->polyphonicMode)
{
auto nb = static_cast<NimbusEffect *>(that->surge_effect_poly[channel].get());
nb->setNimbusTrigger(triggered);
}
else
{
auto nb = static_cast<NimbusEffect *>(that->surge_effect.get());
nb->setNimbusTrigger(triggered);
}
}

template <>
Expand Down
16 changes: 11 additions & 5 deletions src/fxconfig/SpringReverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ namespace sst::surgext_rack::fx

template <> constexpr int FXConfig<fxt_spring_reverb>::numParams() { return 8; }
template <> constexpr int FXConfig<fxt_spring_reverb>::extraInputs() { return 1; }
template <> constexpr int FXConfig<fxt_spring_reverb>::extraSchmidtTriggers() { return 2; }
template <> constexpr int FXConfig<fxt_spring_reverb>::extraSchmidtTriggers()
{
return 1 + MAX_POLY;
}
template <> constexpr int FXConfig<fxt_spring_reverb>::specificParamCount() { return 1; }
template <> constexpr bool FXConfig<fxt_spring_reverb>::nanCheckOutput() { return true; }
template <> FXConfig<fxt_spring_reverb>::layout_t FXConfig<fxt_spring_reverb>::getLayout()
Expand Down Expand Up @@ -79,12 +82,15 @@ template <> void FXConfig<fxt_spring_reverb>::configExtraInputs(FX<fxt_spring_re
* template <> void FXConfig<fxt_spring_reverb>::processSpecificParams(FX<fxt_spring_reverb> *m)
*/

template <> void FXConfig<fxt_spring_reverb>::processExtraInputs(FX<fxt_spring_reverb> *that)
template <>
void FXConfig<fxt_spring_reverb>::processExtraInputs(FX<fxt_spring_reverb> *that, int channel)
{
auto t = that->extraInputTriggers[0].process(
that->inputs[FX<fxt_spring_reverb>::INPUT_SPECIFIC_0].getVoltage());
auto d = that->extraInputTriggers[1].process(
auto uc = channel * (that->inputs[FX<fxt_spring_reverb>::INPUT_SPECIFIC_0].getChannels() > 1);
auto t = that->extraInputTriggers[1 + channel].process(
that->inputs[FX<fxt_spring_reverb>::INPUT_SPECIFIC_0].getVoltage(uc));
auto d = that->extraInputTriggers[0].process(
that->params[FX<fxt_spring_reverb>::FX_SPECIFIC_PARAM_0].getValue(), 0.5);

if (t || d)
{
that->fxstorage->p[6].set_value_f01(1);
Expand Down

0 comments on commit 19cae08

Please sign in to comment.