From 95ec28f4d730e3eef3d36302a3533d487ed7bb35 Mon Sep 17 00:00:00 2001 From: Matthew Maxwell Date: Fri, 18 Oct 2024 02:08:11 -0500 Subject: [PATCH] Add wavefolder to Kudzu --- lib/cortex | 2 +- patches/init/kudzu/kudzu.cpp | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/cortex b/lib/cortex index e2431cd..1ece6f3 160000 --- a/lib/cortex +++ b/lib/cortex @@ -1 +1 @@ -Subproject commit e2431cdf2e4f6f9f6e64a84911ed0e656125c29d +Subproject commit 1ece6f36eda2cfb5011958a76a95bad9d6726c23 diff --git a/patches/init/kudzu/kudzu.cpp b/patches/init/kudzu/kudzu.cpp index 6531d84..6ed9fa8 100644 --- a/patches/init/kudzu/kudzu.cpp +++ b/patches/init/kudzu/kudzu.cpp @@ -5,7 +5,10 @@ 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, @@ -13,32 +16,38 @@ void AudioCallback(AudioHandle::InterleavingInputBuffer in, 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) { }