Skip to content

Commit

Permalink
Add wavefolder to Kudzu
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellmattryan committed Oct 18, 2024
1 parent 130d2a8 commit 95ec28f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/cortex
27 changes: 18 additions & 9 deletions patches/init/kudzu/kudzu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,49 @@ using namespace daisy;
using namespace patch_sm;

DaisyPatchSM hardware;
Switch toggle;

cortex::Saturator saturator;
cortex::Wavefolder wavefolder;
cortex::Filter filter;

void AudioCallback(AudioHandle::InterleavingInputBuffer in,
AudioHandle::InterleavingOutputBuffer out,
size_t size)
{
hardware.ProcessAllControls();
toggle.Debounce();

float driveKnob = hardware.GetAdcValue(CV_1);
const float MAX_SATURATION = 24.0f;
saturator.SetSaturation((driveKnob * MAX_SATURATION) + 1.0f);
saturator.SetSaturation((driveKnob * 24.0f) + 1.0f);
wavefolder.SetInputGain((driveKnob * 6.0f) + 1.0f);

float toneKnob = hardware.GetAdcValue(CV_2);
filter.SetCutoffFrequency(cortex::map(toneKnob, 1000.0f, cortex::FILTER_CUTOFF_FREQ_MAX, cortex::Mapping::LOG));

float symmetryKnob = hardware.GetAdcValue(CV_3);
saturator.SetSymmetry(1.0f - symmetryKnob);
wavefolder.SetSymmetry(1.0f - symmetryKnob);

float mixKnob = hardware.GetAdcValue(CV_4);
bool useSaturator = toggle.Pressed();

for (size_t idx = 0; idx < size; idx += 2) {
float originalLeftSample = in[idx];
float originalRightSample = in[idx + 1];
auto saturatedLeftSample = (float)filter.Process(saturator.Process(originalLeftSample));
auto saturatedRightSample = (float)filter.Process(saturator.Process(originalRightSample));
out[idx] = originalLeftSample * (1.0f - mixKnob) + saturatedLeftSample * mixKnob;
out[idx + 1] = originalRightSample * (1.0f - mixKnob) + saturatedRightSample * mixKnob;
for (size_t idx = 0; idx < size; idx++) {
float originalSample = in[idx];
auto distortedSample = useSaturator ? saturator.Process(originalSample) : wavefolder.Process(originalSample);
auto filteredSample = (float)filter.Process(distortedSample);
out[idx] = originalSample * (1.0f - mixKnob) + filteredSample * mixKnob;
}

hardware.WriteCvOut(2, 5.0f * out[0]);
}

int main(void)
{
hardware.Init();

toggle.Init(hardware.B8);

hardware.StartAudio(AudioCallback);

while (1) { }
Expand Down

0 comments on commit 95ec28f

Please sign in to comment.