Skip to content

Commit

Permalink
Begin init patches
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellmattryan committed Oct 17, 2024
1 parent 3eb2a2b commit c6ec779
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/cortex
18 changes: 18 additions & 0 deletions patches/init/oscillator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Project Name
TARGET = Oscillator

# Source Files
CPP_SOURCES = oscillator.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
39 changes: 39 additions & 0 deletions patches/init/oscillator/oscillator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "daisy_patch_sm.h"
#include "cortex.h"

using namespace daisy;
using namespace patch_sm;

DaisyPatchSM hardware;
cortex::Oscillator oscillator(cortex::DEFAULT_CONTEXT, 220.0f);

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

float coarse_knob = hardware.GetAdcValue(CV_1);
float coarse = cortex::map(coarse_knob, 36.f, 96.f);

float voct_cv = hardware.GetAdcValue(CV_5);
float voct = cortex::map(voct_cv, 0.f, 60.f);

float midi_nn = cortex::clamp(coarse + voct, 0.f, 127.f);
float freq = cortex::midi_to_frequency(midi_nn);

oscillator.SetFrequency(freq);

for (size_t idx = 0; idx < size; idx += 2) {
auto sample = (float) oscillator.Generate();
out[idx] = sample;
out[idx + 1] = sample;
}
}

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

while(1) {}
}
11 changes: 2 additions & 9 deletions patches/seed/oscillator/oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ using namespace daisy;
using namespace cortex;

DaisySeed hardware;

Context context {
(size_t)hardware.AudioSampleRate(),
2,
hardware.AudioBlockSize(),
};

Oscillator oscillator(context, 110.0f);
Oscillator oscillator(DEFAULT_CONTEXT, 110.0f);

void AudioCallback(AudioHandle::InterleavingInputBuffer in,
AudioHandle::InterleavingOutputBuffer out,
size_t size)
{
for (size_t idx = 0; idx < size; idx += 2) {
auto sample = (float)oscillator.Generate();
auto sample = (float) oscillator.Generate();
out[idx] = sample;
out[idx + 1] = sample;
}
Expand Down

0 comments on commit c6ec779

Please sign in to comment.