From 1f3ae275d3140a28de041a0132b3734c393511ae Mon Sep 17 00:00:00 2001 From: Matthew Maxwell Date: Sun, 20 Oct 2024 18:34:35 -0500 Subject: [PATCH] Add fix header path --- lib/cortex | 2 +- patches/init/lotus/Makefile | 18 ++++++++++ patches/init/lotus/README.md | 18 ++++++++++ patches/init/lotus/lotus.cpp | 64 ++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 patches/init/lotus/Makefile create mode 100644 patches/init/lotus/README.md create mode 100644 patches/init/lotus/lotus.cpp diff --git a/lib/cortex b/lib/cortex index 60878f2..e743964 160000 --- a/lib/cortex +++ b/lib/cortex @@ -1 +1 @@ -Subproject commit 60878f270614ab2653b41174f20555086751c599 +Subproject commit e743964b37440b78730e4d6bc975c63c0fc66ceb diff --git a/patches/init/lotus/Makefile b/patches/init/lotus/Makefile new file mode 100644 index 0000000..df2acd1 --- /dev/null +++ b/patches/init/lotus/Makefile @@ -0,0 +1,18 @@ +# Project Name +TARGET = Lotus + +# Source Files +CPP_SOURCES = lotus.cpp + +# Library Directories +LIBDAISY_DIR = ../../../vendor/libDaisy +LIBCORTEX_DIR = ../../../lib/cortex + +# Include Cortex library +C_INCLUDES += -I$(LIBCORTEX_DIR)/src +LIBS += -lcortex +LIBDIR += -L$(LIBCORTEX_DIR)/target/release + +# Include Daisy library Makefile +SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core +include $(SYSTEM_FILES_DIR)/Makefile diff --git a/patches/init/lotus/README.md b/patches/init/lotus/README.md new file mode 100644 index 0000000..210996a --- /dev/null +++ b/patches/init/lotus/README.md @@ -0,0 +1,18 @@ +# Lotus + +> Emitting a harmonic meditation 🪷 + +_Lotus_ is a rich binaural oscillator patch, named after the Lotus flower which symbolizes spiritual +awakening and harmony. It's connection to meditative practices can loosely be connected to the dual-frequency +harmony of binaural beats. + +## Controls + +| Control | Name | Description | +|----------|-----------|---------------------------------------------------------------------------------------------------------| +| **CV_1** | Tune | The leader oscillator's running frequency (100-400Hz) | +| **CV_2** | Detune | The speed of the binaural beat, detuning the follower oscillator within 20Hz from the leader oscillator | +| **CV_3** | LFO Rate | The speed at which the follower oscillator changes frequency | +| **CV_4** | LFO Depth | The amount in which the LFO rate affects the follower oscillator's frequency | +| **B8** | Sync | Syncs the two oscillators together when turned on | + diff --git a/patches/init/lotus/lotus.cpp b/patches/init/lotus/lotus.cpp new file mode 100644 index 0000000..34b4e4c --- /dev/null +++ b/patches/init/lotus/lotus.cpp @@ -0,0 +1,64 @@ +#include "cortex.h" +#include "daisy_patch_sm.h" + +using namespace daisy; +using namespace patch_sm; + +DaisyPatchSM hardware; +Switch toggle; + +cortex::Oscillator leader; +cortex::Oscillator follower; +cortex::Oscillator lfo; + +const float MAX_DETUNE_AMOUNT = 20.0f; + +void AudioCallback(AudioHandle::InterleavingInputBuffer in, AudioHandle::InterleavingOutputBuffer out, size_t size) +{ + hardware.ProcessAllControls(); + toggle.Debounce(); + + float tuneKnob = hardware.GetAdcValue(CV_1); + float detuneKnob = hardware.GetAdcValue(CV_2); + float lfoRateKnob = hardware.GetAdcValue(CV_3); + float lfoDepthKnob = hardware.GetAdcValue(CV_4); + + bool isSyncOn = toggle.Pressed(); + if (isSyncOn) { + leader.AttachFollower(&follower); + } else { + leader.DetachFollower(); + } + + float leaderFrequency = cortex::map(tuneKnob, 65.406f, 261.626f, cortex::Mapping::LOG); + leader.SetFrequency(leaderFrequency); + + float followerDetune = MAX_DETUNE_AMOUNT * ((detuneKnob * 2.0f) - 1.0f); + follower.SetFrequency(leaderFrequency - followerDetune); + + float lfoRate = (lfoRateKnob * 1000.0f) + 0.1f; + lfo.SetFrequency(lfoRate); + + for (size_t idx = 0; idx < size; idx += 2) { + float leaderSample = leader.Generate(); + float followerSample = follower.Generate(); + + float lfoMod = lfoDepthKnob * lfo.Generate(); + float modulatedLeaderFrequency = leaderFrequency + (MAX_DETUNE_AMOUNT * lfoMod); + leader.SetFrequency(modulatedLeaderFrequency + (MAX_DETUNE_AMOUNT * lfoMod)); + follower.SetFrequency(modulatedLeaderFrequency - followerDetune); + + out[idx] = leaderSample; + out[idx + 1] = followerSample; + } + + hardware.WriteCvOut(2, 5.0f * out[0]); +} + +int main(void) +{ + hardware.Init(); + toggle.Init(hardware.B8); + hardware.StartAudio(AudioCallback); + while (1) { } +}