Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Scrambler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,26 @@ struct Scrambler : Module
float cleanVal = params[CLEAN_PARAM].getValue();
if (inputs[CVINC_INPUT].isConnected())
cleanVal += inputs[CVINC_INPUT].getVoltage() * 1000.f;
int cleanLen = std::max(1, (int)cleanVal);
int cleanLen = std::max(0, (int)cleanVal);

float scrambleVal = params[SCRAMBLE_PARAM].getValue();
if (inputs[CVINS_INPUT].isConnected())
scrambleVal += inputs[CVINS_INPUT].getVoltage() * 1000.f;
// Clamp to MAX_SAMPLES so we never index past the pre-allocated buffer.
// Using rack::clamp (from math.hpp) since the SDK targets C++11.
int scrambleLen = clamp((int)scrambleVal, 1, MAX_SAMPLES);
int scrambleLen = clamp((int)scrambleVal, 0, MAX_SAMPLES);
float in = inputs[IN_INPUT].getVoltage();

// scramble=0 → pure bypass. Reset state so re-enabling starts fresh.
if (scrambleLen <= 0)
{
outputs[OUT_OUTPUT].setVoltage(in);
inClean = true;
inPlayback = false;
position = 0;
return;
}

if (inPlayback)
{
outputs[OUT_OUTPUT].setVoltage(playbackBuffer[playbackIndex++]);
Expand All @@ -92,6 +102,14 @@ struct Scrambler : Module
return;
}

// clean=0 → skip clean phase, collect this sample directly.
if (inClean && cleanLen <= 0)
{
inClean = false;
collectLen = scrambleLen;
collectIndex = 0;
}

if (inClean)
{
outputs[OUT_OUTPUT].setVoltage(in);
Expand Down
Loading