From 6d9a679d2fac6c8ac21782e57369981da4d48944 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Thu, 4 Jul 2024 18:36:56 -0400 Subject: [PATCH] gh-22: Updates DPT support to use new Host API. --- .vscode/launch.json | 30 +++ hosts/daisy/examples/dpt/Makefile | 2 + hosts/daisy/examples/dpt/lfos/Makefile | 8 +- .../include/signaletic-dpt-lfos-signals.h | 103 ++++---- .../dpt/lfos/src/signaletic-dpt-lfos.cpp | 106 ++++---- hosts/daisy/examples/dpt/passthrough/Makefile | 21 ++ .../src/signaletic-dpt-passthrough.cpp | 185 +++++++++++++ .../sines/src/lichen-medium-sines.cpp | 3 +- hosts/daisy/include/daisy-dpt-host.h | 93 ------- hosts/daisy/include/dspcoffee-dpt-device.hpp | 242 ++++++++++++++++++ hosts/daisy/include/signaletic-daisy-host.hpp | 3 +- hosts/daisy/src/daisy-dpt-host.cpp | 120 --------- hosts/daisy/vendor/dpt/lib/dev/DAC7554.h | 11 +- 13 files changed, 595 insertions(+), 332 deletions(-) create mode 100644 hosts/daisy/examples/dpt/passthrough/Makefile create mode 100644 hosts/daisy/examples/dpt/passthrough/src/signaletic-dpt-passthrough.cpp delete mode 100644 hosts/daisy/include/daisy-dpt-host.h create mode 100644 hosts/daisy/include/dspcoffee-dpt-device.hpp delete mode 100644 hosts/daisy/src/daisy-dpt-host.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json index ab40d59..384c819 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -314,6 +314,36 @@ "svdFile": "${workspaceRoot}/.vscode/STM32H750x.svd", "type": "cortex-debug" }, + { + "name": "Remote DPT passthrough", + "configFiles": [ + "interface/stlink.cfg", + "target/stm32h7x.cfg" + ], + "cwd": "${workspaceFolder}/hosts/daisy/examples/dpt/passthrough", + "debuggerArgs": [ + "-d", + "${workspaceRoot}/hosts/daisy/examples/dpt/passthrough" + ], + "executable": "${workspaceRoot}/hosts/daisy/examples/dpt/passthrough/build/signaletic-dpt-passthrough.elf", + "interface": "swd", + "openOCDLaunchCommands": [ + "init", + "reset init" + ], + "preLaunchTask": "Debug Build DPT Examples", + "preRestartCommands": [ + "load", + "enable breakpoint", + "monitor reset" + ], + "request": "launch", + "runToEntryPoint": "main", + "servertype": "openocd", + "showDevDebugOutput": "parsed", + "svdFile": "${workspaceRoot}/.vscode/STM32H750x.svd", + "type": "cortex-debug" + }, { "name": "Remote DPT lfos", "configFiles": [ diff --git a/hosts/daisy/examples/dpt/Makefile b/hosts/daisy/examples/dpt/Makefile index 420997f..aa72bd6 100644 --- a/hosts/daisy/examples/dpt/Makefile +++ b/hosts/daisy/examples/dpt/Makefile @@ -1,5 +1,7 @@ all: $(MAKE) -C lfos + $(MAKE) -C passthrough clean: $(MAKE) -C lfos clean + $(MAKE) -C passthrough clean diff --git a/hosts/daisy/examples/dpt/lfos/Makefile b/hosts/daisy/examples/dpt/lfos/Makefile index b72abbf..ead8557 100644 --- a/hosts/daisy/examples/dpt/lfos/Makefile +++ b/hosts/daisy/examples/dpt/lfos/Makefile @@ -1,15 +1,15 @@ # Project Name TARGET ?= signaletic-dpt-lfos -DEBUG = 0 -OPT = -O3 +DEBUG = 1 +OPT = -O0 # Sources -C_SOURCES += ../../../../../libsignaletic/vendor/tlsf/tlsf.c ../../../../../libsignaletic/src/libsignaletic.c +C_SOURCES += ../../../../../libsignaletic/vendor/tlsf/tlsf.c ../../../../../libsignaletic/src/libsignaletic.c ../../../src/signaletic-host.c C_INCLUDES += -I../../../../../libsignaletic/vendor/tlsf -I../../../../../libsignaletic/include CPP_INCLUDES += -I../vendor/lib -I../../../vendor/lib/dev -I../../../include -CPP_SOURCES = src/${TARGET}.cpp ../../../vendor/dpt/lib/daisy_dpt.cpp ../../../vendor/dpt/lib/dev/DAC7554.cpp ../../../src/signaletic-daisy-host.cpp ../../../src/daisy-dpt-host.cpp +CPP_SOURCES = ../../../vendor/dpt/lib/dev/DAC7554.cpp ../../../src/signaletic-daisy-host.cpp ../../../src/sig-daisy-patch-sm.cpp src/${TARGET}.cpp USE_FATFS = 0 diff --git a/hosts/daisy/examples/dpt/lfos/include/signaletic-dpt-lfos-signals.h b/hosts/daisy/examples/dpt/lfos/include/signaletic-dpt-lfos-signals.h index b741b90..305dfb5 100644 --- a/hosts/daisy/examples/dpt/lfos/include/signaletic-dpt-lfos-signals.h +++ b/hosts/daisy/examples/dpt/lfos/include/signaletic-dpt-lfos-signals.h @@ -1,60 +1,57 @@ #include -#include "../../../../include/signaletic-daisy-host.hpp" +#include "../../../../include/signaletic-host.h" -struct sig_daisy_ClockedLFO_Inputs { +struct sig_host_ClockedLFO_Inputs { float_array_ptr clockFreq; }; -struct sig_daisy_ClockedLFO_Parameters { +struct sig_host_ClockedLFO_Parameters { int freqScaleCVInputControl; int lfoGainCVInputControl; int cvOutputControl; }; // TODO: This isn't quite the correct name. -struct sig_daisy_ClockedLFO { +struct sig_host_ClockedLFO { struct sig_dsp_Signal signal; - struct sig_daisy_ClockedLFO_Inputs inputs; - struct sig_daisy_ClockedLFO_Parameters parameters; + struct sig_host_ClockedLFO_Inputs inputs; + struct sig_host_ClockedLFO_Parameters parameters; struct sig_dsp_Signal_SingleMonoOutput outputs; - struct sig_daisy_FilteredCVIn* freqScaleIn; + struct sig_host_FilteredCVIn* freqScaleIn; struct sig_dsp_BinaryOp* clockFreqMultiplier; - struct sig_daisy_FilteredCVIn* lfoGainIn; + struct sig_host_FilteredCVIn* lfoGainIn; struct sig_dsp_Oscillator* lfo; - struct sig_daisy_CVOut* cvOut; + struct sig_host_CVOut* cvOut; + struct sig_host_HardwareInterface* hardware; }; +void sig_host_ClockedLFO_generate(void* signal) { + struct sig_host_ClockedLFO* self = + (struct sig_host_ClockedLFO*) signal; + // FIXME: Need to either more formally separate construction from + // initialization, or introduce an additional lifecycle hook for + // handling this kind of initialization logic. + self->freqScaleIn->hardware = self->hardware; + self->freqScaleIn->parameters.control = + self->parameters.freqScaleCVInputControl; + self->lfoGainIn->hardware = self->hardware; + self->lfoGainIn->parameters.control = + self->parameters.lfoGainCVInputControl; + self->cvOut->hardware = self->hardware; + self->cvOut->parameters.control = self->parameters.cvOutputControl; -struct sig_daisy_ClockedLFO* sig_daisy_ClockedLFO_new( - struct sig_Allocator* allocator, struct sig_SignalContext* context, - struct sig_daisy_Host* host); -void sig_daisy_ClockedLFO_init(struct sig_daisy_ClockedLFO* self, - struct sig_SignalContext* context); -void sig_daisy_ClockedLFO_generate(void* signal); -void sig_daisy_ClockedLFO_destroy(struct sig_Allocator* allocator, - struct sig_daisy_ClockedLFO* self); - - -struct sig_daisy_ClockedLFO* sig_daisy_ClockedLFO_new( - struct sig_Allocator* allocator, struct sig_SignalContext* context, - struct sig_daisy_Host* host) { - struct sig_daisy_ClockedLFO* self = sig_MALLOC(allocator, - struct sig_daisy_ClockedLFO); - - self->freqScaleIn = sig_daisy_FilteredCVIn_new(allocator, context, host); - self->clockFreqMultiplier = sig_dsp_Mul_new(allocator, context); - self->lfoGainIn = sig_daisy_FilteredCVIn_new(allocator, context, host); - self->lfo = sig_dsp_LFTriangle_new(allocator, context); - self->cvOut = sig_daisy_CVOut_new(allocator, context, host); - - sig_daisy_ClockedLFO_init(self, context); + self->clockFreqMultiplier->inputs.left = self->inputs.clockFreq; - return self; + self->freqScaleIn->signal.generate(self->freqScaleIn); + self->clockFreqMultiplier->signal.generate(self->clockFreqMultiplier); + self->lfoGainIn->signal.generate(self->lfoGainIn); + self->lfo->signal.generate(self->lfo); + self->cvOut->signal.generate(self->cvOut); } -void sig_daisy_ClockedLFO_init(struct sig_daisy_ClockedLFO* self, +void sig_host_ClockedLFO_init(struct sig_host_ClockedLFO* self, struct sig_SignalContext* context) { - sig_dsp_Signal_init(self, context, *sig_daisy_ClockedLFO_generate); + sig_dsp_Signal_init(self, context, *sig_host_ClockedLFO_generate); self->parameters.freqScaleCVInputControl = 1; self->parameters.lfoGainCVInputControl = 2; self->parameters.cvOutputControl = 1; @@ -76,31 +73,29 @@ void sig_daisy_ClockedLFO_init(struct sig_daisy_ClockedLFO* self, sig_CONNECT_TO_SILENCE(self, clockFreq, context); } -void sig_daisy_ClockedLFO_generate(void* signal) { - struct sig_daisy_ClockedLFO* self = - (struct sig_daisy_ClockedLFO*) signal; - self->freqScaleIn->parameters.control = - self->parameters.freqScaleCVInputControl; - self->lfoGainIn->parameters.control = - self->parameters.lfoGainCVInputControl; - self->cvOut->parameters.control = self->parameters.cvOutputControl; +struct sig_host_ClockedLFO* sig_host_ClockedLFO_new( + struct sig_Allocator* allocator, struct sig_SignalContext* context) { + struct sig_host_ClockedLFO* self = sig_MALLOC(allocator, + struct sig_host_ClockedLFO); - self->clockFreqMultiplier->inputs.left = self->inputs.clockFreq; + self->freqScaleIn = sig_host_FilteredCVIn_new(allocator, context); + self->clockFreqMultiplier = sig_dsp_Mul_new(allocator, context); + self->lfoGainIn = sig_host_FilteredCVIn_new(allocator, context); + self->lfo = sig_dsp_LFTriangle_new(allocator, context); + self->cvOut = sig_host_CVOut_new(allocator, context); - self->freqScaleIn->signal.generate(self->freqScaleIn); - self->clockFreqMultiplier->signal.generate(self->clockFreqMultiplier); - self->lfoGainIn->signal.generate(self->lfoGainIn); - self->lfo->signal.generate(self->lfo); - self->cvOut->signal.generate(self->cvOut); + sig_host_ClockedLFO_init(self, context); + + return self; } -void sig_daisy_ClockedLFO_destroy(struct sig_Allocator* allocator, - struct sig_daisy_ClockedLFO* self) { - sig_daisy_FilteredCVIn_destroy(allocator, self->freqScaleIn); +void sig_host_ClockedLFO_destroy(struct sig_Allocator* allocator, + struct sig_host_ClockedLFO* self) { + sig_host_FilteredCVIn_destroy(allocator, self->freqScaleIn); sig_dsp_Mul_destroy(allocator, self->clockFreqMultiplier); - sig_daisy_FilteredCVIn_destroy(allocator, self->lfoGainIn); + sig_host_FilteredCVIn_destroy(allocator, self->lfoGainIn); sig_dsp_LFTriangle_destroy(allocator, self->lfo); - sig_daisy_CVOut_destroy(allocator, self->cvOut); + sig_host_CVOut_destroy(allocator, self->cvOut); // We don't call sig_dsp_Signal_destroy // because our output is borrowed from self->lfo, diff --git a/hosts/daisy/examples/dpt/lfos/src/signaletic-dpt-lfos.cpp b/hosts/daisy/examples/dpt/lfos/src/signaletic-dpt-lfos.cpp index 218b45d..dfb881e 100644 --- a/hosts/daisy/examples/dpt/lfos/src/signaletic-dpt-lfos.cpp +++ b/hosts/daisy/examples/dpt/lfos/src/signaletic-dpt-lfos.cpp @@ -1,7 +1,7 @@ -#include "daisy.h" #include "../include/signaletic-dpt-lfos-signals.h" -#include "../../../../include/daisy-dpt-host.h" +#include "../../../../include/dspcoffee-dpt-device.hpp" +#define SAMPLERATE 48000 #define HEAP_SIZE 1024 * 256 // 256KB #define MAX_NUM_SIGNALS 128 @@ -11,13 +11,12 @@ struct sig_AllocatorHeap heap = { .memory = (void*) memory }; -struct sig_Allocator alloc = { +struct sig_Allocator allocator = { .impl = &sig_TLSFAllocatorImpl, .heap = &heap }; -daisy::dpt::DPT dpt; -struct sig_daisy_Host* dptHost; +DaisyHost host; struct sig_dsp_Signal* listStorage[MAX_NUM_SIGNALS]; struct sig_List signals = { @@ -27,87 +26,95 @@ struct sig_List signals = { }; struct sig_dsp_SignalListEvaluator* evaluator; -struct sig_daisy_GateIn* clockInput; +struct sig_host_GateIn* clockInput; struct sig_dsp_ClockDetector* clockFreq; -struct sig_daisy_ClockedLFO* lfo1; -struct sig_daisy_ClockedLFO* lfo2; -struct sig_daisy_ClockedLFO* lfo3; -struct sig_daisy_ClockedLFO* lfo4; +struct sig_host_ClockedLFO* lfo1; +struct sig_host_ClockedLFO* lfo2; +struct sig_host_ClockedLFO* lfo3; +struct sig_host_ClockedLFO* lfo4; struct sig_dsp_BinaryOp* lfo1PlusLFO3; struct sig_dsp_BinaryOp* lfo2PlusLFO4; -struct sig_daisy_CVOut* lfo1And3Out; -struct sig_daisy_CVOut* lfo2And4Out; -struct sig_daisy_GateOut* gate1Out; +struct sig_host_CVOut* lfo1And3Out; +struct sig_host_CVOut* lfo2And4Out; +struct sig_host_GateOut* gate1Out; void InitCVInputs(struct sig_SignalContext* context, struct sig_Status* status) { - clockInput = sig_daisy_GateIn_new(&alloc, context, dptHost); - clockInput->parameters.control = sig_daisy_DPT_GATE_IN_1; + clockInput = sig_host_GateIn_new(&allocator, context); + clockInput->hardware = &host.device.hardware; + clockInput->parameters.control = sig_host_GATE_IN_1; sig_List_append(&signals, clockInput, status); } void InitClock(struct sig_SignalContext* context, struct sig_Status* status) { - clockFreq = sig_dsp_ClockDetector_new(&alloc, context); + clockFreq = sig_dsp_ClockDetector_new(&allocator, context); clockFreq->inputs.source = clockInput->outputs.main; sig_List_append(&signals, clockFreq, status); } void InitLFO(struct sig_SignalContext* context, struct sig_Status* status) { - lfo1 = sig_daisy_ClockedLFO_new(&alloc, context, dptHost); + lfo1 = sig_host_ClockedLFO_new(&allocator, context); + lfo1->hardware = &host.device.hardware; sig_List_append(&signals, lfo1, status); - lfo1->parameters.freqScaleCVInputControl = sig_daisy_DPT_CV_IN_1; - lfo1->parameters.lfoGainCVInputControl = sig_daisy_DPT_CV_IN_2; - lfo1->parameters.cvOutputControl = sig_daisy_DPT_CV_OUT_1; + lfo1->parameters.freqScaleCVInputControl = sig_host_CV_IN_1; + lfo1->parameters.lfoGainCVInputControl = sig_host_CV_IN_2; + lfo1->parameters.cvOutputControl = sig_host_CV_OUT_1; lfo1->inputs.clockFreq = clockFreq->outputs.main; - lfo2 = sig_daisy_ClockedLFO_new(&alloc, context, dptHost); + lfo2 = sig_host_ClockedLFO_new(&allocator, context); + lfo2->hardware = &host.device.hardware; sig_List_append(&signals, lfo2, status); - lfo2->parameters.freqScaleCVInputControl = sig_daisy_DPT_CV_IN_3; - lfo2->parameters.lfoGainCVInputControl = sig_daisy_DPT_CV_IN_4; - lfo2->parameters.cvOutputControl = sig_daisy_DPT_CV_OUT_2; + lfo2->parameters.freqScaleCVInputControl = sig_host_CV_IN_3; + lfo2->parameters.lfoGainCVInputControl = sig_host_CV_IN_4; + lfo2->parameters.cvOutputControl = sig_host_CV_OUT_2; lfo2->inputs.clockFreq = clockFreq->outputs.main; - lfo3 = sig_daisy_ClockedLFO_new(&alloc, context, dptHost); + lfo3 = sig_host_ClockedLFO_new(&allocator, context); + lfo3->hardware = &host.device.hardware; sig_List_append(&signals, lfo3, status); lfo3->inputs.clockFreq = clockFreq->outputs.main; - lfo3->parameters.freqScaleCVInputControl = sig_daisy_DPT_CV_IN_5; - lfo3->parameters.lfoGainCVInputControl = sig_daisy_DPT_CV_IN_6; - lfo3->parameters.cvOutputControl = sig_daisy_DPT_CV_OUT_3; + lfo3->parameters.freqScaleCVInputControl = sig_host_CV_IN_5; + lfo3->parameters.lfoGainCVInputControl = sig_host_CV_IN_6; + lfo3->parameters.cvOutputControl = sig_host_CV_OUT_3; - lfo4 = sig_daisy_ClockedLFO_new(&alloc, context, dptHost); + lfo4 = sig_host_ClockedLFO_new(&allocator, context); + lfo4->hardware = &host.device.hardware; sig_List_append(&signals, lfo4, status); lfo4->inputs.clockFreq = clockFreq->outputs.main; - lfo4->parameters.freqScaleCVInputControl = sig_daisy_DPT_CV_IN_7; - lfo4->parameters.lfoGainCVInputControl = sig_daisy_DPT_CV_IN_8; - lfo4->parameters.cvOutputControl = sig_daisy_DPT_CV_OUT_4; + lfo4->parameters.freqScaleCVInputControl = sig_host_CV_IN_7; + lfo4->parameters.lfoGainCVInputControl = sig_host_CV_IN_8; + lfo4->parameters.cvOutputControl = sig_host_CV_OUT_4; - lfo1PlusLFO3 = sig_dsp_Add_new(&alloc, context); + lfo1PlusLFO3 = sig_dsp_Add_new(&allocator, context); sig_List_append(&signals, lfo1PlusLFO3, status); lfo1PlusLFO3->inputs.left = lfo1->outputs.main; lfo1PlusLFO3->inputs.right = lfo3->outputs.main; - lfo2PlusLFO4 = sig_dsp_Add_new(&alloc, context); + lfo2PlusLFO4 = sig_dsp_Add_new(&allocator, context); sig_List_append(&signals, lfo2PlusLFO4, status); lfo2PlusLFO4->inputs.left = lfo2->outputs.main; lfo2PlusLFO4->inputs.right = lfo4->outputs.main; - lfo1And3Out = sig_daisy_CVOut_new(&alloc, context, dptHost); + lfo1And3Out = sig_host_CVOut_new(&allocator, context); + lfo1And3Out->hardware = &host.device.hardware; sig_List_append(&signals, lfo1And3Out, status); lfo1And3Out->inputs.source = lfo1PlusLFO3->outputs.main; - lfo1And3Out->parameters.control = sig_daisy_DPT_CV_OUT_5; + lfo1And3Out->parameters.control = sig_host_CV_OUT_5; lfo1And3Out->parameters.scale = 0.5f; // TODO: Replace with a wavefolder. - lfo2And4Out = sig_daisy_CVOut_new(&alloc, context, dptHost); + lfo2And4Out = sig_host_CVOut_new(&allocator, context); + lfo2And4Out->hardware = &host.device.hardware; sig_List_append(&signals, lfo2And4Out, status); lfo2And4Out->inputs.source = lfo2PlusLFO4->outputs.main; - lfo2And4Out->parameters.control = sig_daisy_DPT_CV_OUT_6; + lfo2And4Out->parameters.control = sig_host_CV_OUT_6; lfo2And4Out->parameters.scale = 0.5f; } void InitCVOutputs(struct sig_SignalContext* context, struct sig_Status* status) { - gate1Out = sig_daisy_GateOut_new(&alloc, context, dptHost); - gate1Out->parameters.control = sig_daisy_DPT_GATE_OUT_1; + gate1Out = sig_host_GateOut_new(&allocator, context); + gate1Out->hardware = &host.device.hardware; + gate1Out->parameters.control = sig_host_GATE_OUT_1; gate1Out->inputs.source = clockInput->outputs.main; sig_List_append(&signals, gate1Out, status); } @@ -121,28 +128,25 @@ void buildSignalGraph(struct sig_SignalContext* context, } int main(void) { + allocator.impl->init(&allocator); + struct sig_AudioSettings audioSettings = { - .sampleRate = 48000, + .sampleRate = SAMPLERATE, .numChannels = 2, .blockSize = 48 }; struct sig_Status status; sig_Status_init(&status); - alloc.impl->init(&alloc); sig_List_init(&signals, (void**) &listStorage, MAX_NUM_SIGNALS); - evaluator = sig_dsp_SignalListEvaluator_new(&alloc, &signals); - dptHost = sig_daisy_DPTHost_new(&alloc, - &audioSettings, &dpt, (struct sig_dsp_SignalEvaluator*) evaluator); - sig_daisy_Host_registerGlobalHost(dptHost); + evaluator = sig_dsp_SignalListEvaluator_new(&allocator, &signals); + host.Init(&audioSettings, (struct sig_dsp_SignalEvaluator*) evaluator); struct sig_SignalContext* context = sig_SignalContext_new( - &alloc, &audioSettings); + &allocator, &audioSettings); buildSignalGraph(context, &status); - dptHost->impl->start(dptHost); - - while (1) { + host.Start(); - } + while (1) {} } diff --git a/hosts/daisy/examples/dpt/passthrough/Makefile b/hosts/daisy/examples/dpt/passthrough/Makefile new file mode 100644 index 0000000..a79facc --- /dev/null +++ b/hosts/daisy/examples/dpt/passthrough/Makefile @@ -0,0 +1,21 @@ +# Project Name +TARGET ?= signaletic-dpt-passthrough + +DEBUG = 1 +OPT = -O0 + +# Sources +C_SOURCES += ../../../../../libsignaletic/vendor/tlsf/tlsf.c ../../../../../libsignaletic/src/libsignaletic.c ../../../src/signaletic-host.c +C_INCLUDES += -I../../../../../libsignaletic/vendor/tlsf -I../../../../../libsignaletic/include + +CPP_INCLUDES += -I../vendor/lib -I../../../vendor/lib/dev -I../../../include +CPP_SOURCES = ../../../vendor/dpt/lib/dev/DAC7554.cpp ../../../src/signaletic-daisy-host.cpp ../../../src/sig-daisy-patch-sm.cpp src/${TARGET}.cpp + +USE_FATFS = 0 + +# Library Locations +LIBDAISY_DIR = ../../../vendor/libDaisy + +# Core location, and generic Makefile. +SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core +include $(SYSTEM_FILES_DIR)/Makefile diff --git a/hosts/daisy/examples/dpt/passthrough/src/signaletic-dpt-passthrough.cpp b/hosts/daisy/examples/dpt/passthrough/src/signaletic-dpt-passthrough.cpp new file mode 100644 index 0000000..5f184fa --- /dev/null +++ b/hosts/daisy/examples/dpt/passthrough/src/signaletic-dpt-passthrough.cpp @@ -0,0 +1,185 @@ +#include "../../../../include/dspcoffee-dpt-device.hpp" + +#define SAMPLERATE 96000 +#define HEAP_SIZE 1024 * 256 // 256KB +#define MAX_NUM_SIGNALS 128 + +uint8_t memory[HEAP_SIZE]; +struct sig_AllocatorHeap heap = { + .length = HEAP_SIZE, + .memory = (void*) memory +}; + +struct sig_Allocator allocator = { + .impl = &sig_TLSFAllocatorImpl, + .heap = &heap +}; + +DaisyHost host; + +struct sig_dsp_Signal* listStorage[MAX_NUM_SIGNALS]; +struct sig_List signals = { + .items = (void**) &listStorage, + .capacity = MAX_NUM_SIGNALS, + .length = 0 +}; + +struct sig_dsp_SignalListEvaluator* evaluator; +struct sig_host_CVIn* cv1In; +struct sig_host_CVIn* cv2In; +struct sig_host_CVIn* cv3In; +struct sig_host_CVIn* cv4In; +struct sig_host_CVIn* cv5In; +struct sig_host_CVIn* cv6In; +struct sig_host_CVOut* cv1Out; +struct sig_host_CVOut* cv2Out; +struct sig_host_CVOut* cv3Out; +struct sig_host_CVOut* cv4Out; +struct sig_host_CVOut* cv5Out; +struct sig_host_CVOut* cv6Out; +struct sig_host_GateIn* gate1In; +struct sig_host_GateIn* gate2In; +struct sig_host_GateOut* gate1Out; +struct sig_host_GateOut* gate2Out; +struct sig_host_AudioIn* leftAudioIn; +struct sig_host_AudioIn* rightAudioIn; +struct sig_host_AudioOut* leftAudioOut; +struct sig_host_AudioOut* rightAudioOut; + +void buildSignalGraph(struct sig_SignalContext* context, + struct sig_Status* status) { + cv1In = sig_host_CVIn_new(&allocator, context); + cv1In->hardware = &host.device.hardware; + sig_List_append(&signals, cv1In, status); + cv1In->parameters.control = sig_host_CV_IN_1; + + cv2In = sig_host_CVIn_new(&allocator, context); + cv2In->hardware = &host.device.hardware; + sig_List_append(&signals, cv2In, status); + cv2In->parameters.control = sig_host_CV_IN_2; + + cv3In = sig_host_CVIn_new(&allocator, context); + cv3In->hardware = &host.device.hardware; + sig_List_append(&signals, cv3In, status); + cv3In->parameters.control = sig_host_CV_IN_3; + + cv4In = sig_host_CVIn_new(&allocator, context); + cv4In->hardware = &host.device.hardware; + sig_List_append(&signals, cv4In, status); + cv4In->parameters.control = sig_host_CV_IN_4; + + cv5In = sig_host_CVIn_new(&allocator, context); + cv5In->hardware = &host.device.hardware; + sig_List_append(&signals, cv5In, status); + cv5In->parameters.control = sig_host_CV_IN_5; + + cv6In = sig_host_CVIn_new(&allocator, context); + cv6In->hardware = &host.device.hardware; + sig_List_append(&signals, cv6In, status); + cv6In->parameters.control = sig_host_CV_IN_6; + + cv1Out = sig_host_CVOut_new(&allocator, context); + cv1Out->hardware = &host.device.hardware; + sig_List_append(&signals, cv1Out, status); + cv1Out->inputs.source = cv1In->outputs.main; + cv1Out->parameters.control = sig_host_CV_OUT_1; + + cv2Out = sig_host_CVOut_new(&allocator, context); + cv2Out->hardware = &host.device.hardware; + sig_List_append(&signals, cv2Out, status); + cv2Out->inputs.source = cv2In->outputs.main; + cv2Out->parameters.control = sig_host_CV_OUT_2; + + cv3Out = sig_host_CVOut_new(&allocator, context); + cv3Out->hardware = &host.device.hardware; + sig_List_append(&signals, cv3Out, status); + cv3Out->inputs.source = cv3In->outputs.main; + cv3Out->parameters.control = sig_host_CV_OUT_3; + + cv4Out = sig_host_CVOut_new(&allocator, context); + cv4Out->hardware = &host.device.hardware; + sig_List_append(&signals, cv4Out, status); + cv4Out->inputs.source = cv4In->outputs.main; + cv4Out->parameters.control = sig_host_CV_OUT_4; + + cv5Out = sig_host_CVOut_new(&allocator, context); + cv5Out->hardware = &host.device.hardware; + sig_List_append(&signals, cv5Out, status); + cv5Out->inputs.source = cv5In->outputs.main; + cv5Out->parameters.control = sig_host_CV_OUT_5; + + cv6Out = sig_host_CVOut_new(&allocator, context); + cv6Out->hardware = &host.device.hardware; + sig_List_append(&signals, cv6Out, status); + cv6Out->inputs.source = cv6In->outputs.main; + cv6Out->parameters.control = sig_host_CV_OUT_6; + + gate1In = sig_host_GateIn_new(&allocator, context); + gate1In->hardware = &host.device.hardware; + sig_List_append(&signals, gate1In, status); + gate1In->parameters.control = sig_host_GATE_IN_1; + + gate2In = sig_host_GateIn_new(&allocator, context); + gate2In->hardware = &host.device.hardware; + sig_List_append(&signals, gate2In, status); + gate2In->parameters.control = sig_host_GATE_IN_2; + + gate1Out = sig_host_GateOut_new(&allocator, context); + gate1Out->hardware = &host.device.hardware; + sig_List_append(&signals, gate1Out, status); + gate1Out->parameters.control = sig_host_GATE_OUT_1; + gate1Out->inputs.source = gate1In->outputs.main; + + gate2Out = sig_host_GateOut_new(&allocator, context); + gate2Out->hardware = &host.device.hardware; + sig_List_append(&signals, gate2Out, status); + gate2Out->parameters.control = sig_host_GATE_OUT_2; + gate2Out->inputs.source = gate2In->outputs.main; + + leftAudioIn = sig_host_AudioIn_new(&allocator, context); + leftAudioIn->hardware = &host.device.hardware; + sig_List_append(&signals, leftAudioIn, status); + leftAudioIn->parameters.channel = sig_host_AUDIO_IN_1; + + rightAudioIn = sig_host_AudioIn_new(&allocator, context); + rightAudioIn->hardware = &host.device.hardware; + sig_List_append(&signals, rightAudioIn, status); + rightAudioIn->parameters.channel = sig_host_AUDIO_IN_2; + + leftAudioOut = sig_host_AudioOut_new(&allocator, context); + leftAudioOut->hardware = &host.device.hardware; + sig_List_append(&signals, leftAudioOut, status); + leftAudioOut->parameters.channel = sig_host_AUDIO_OUT_1; + leftAudioOut->inputs.source = leftAudioIn->outputs.main; + + + rightAudioOut = sig_host_AudioOut_new(&allocator, context); + rightAudioOut->hardware = &host.device.hardware; + sig_List_append(&signals, rightAudioOut, status); + rightAudioOut->parameters.channel = sig_host_AUDIO_IN_2; + rightAudioOut->inputs.source = rightAudioIn->outputs.main; +} + +int main(void) { + allocator.impl->init(&allocator); + + struct sig_AudioSettings audioSettings = { + .sampleRate = SAMPLERATE, + .numChannels = 2, + .blockSize = 1 + }; + + struct sig_Status status; + sig_Status_init(&status); + sig_List_init(&signals, (void**) &listStorage, MAX_NUM_SIGNALS); + + evaluator = sig_dsp_SignalListEvaluator_new(&allocator, &signals); + host.Init(&audioSettings, (struct sig_dsp_SignalEvaluator*) evaluator); + + struct sig_SignalContext* context = sig_SignalContext_new( + &allocator, &audioSettings); + buildSignalGraph(context, &status); + host.Start(); + + while (1) {} +} diff --git a/hosts/daisy/examples/lichen-medium/sines/src/lichen-medium-sines.cpp b/hosts/daisy/examples/lichen-medium/sines/src/lichen-medium-sines.cpp index 0be8f14..07ea14b 100644 --- a/hosts/daisy/examples/lichen-medium/sines/src/lichen-medium-sines.cpp +++ b/hosts/daisy/examples/lichen-medium/sines/src/lichen-medium-sines.cpp @@ -1,7 +1,6 @@ #include #include "../../../../include/lichen-medium-device.hpp" -using namespace lichen::medium; using namespace sig::libdaisy; #define SAMPLERATE 96000 @@ -22,7 +21,7 @@ struct sig_Allocator allocator = { struct sig_dsp_Signal* listStorage[MAX_NUM_SIGNALS]; struct sig_List signals; struct sig_dsp_SignalListEvaluator* evaluator; -DaisyHost host; +DaisyHost host; struct sig_host_FilteredCVIn* freqKnob; struct sig_host_CVIn* freqCV; diff --git a/hosts/daisy/include/daisy-dpt-host.h b/hosts/daisy/include/daisy-dpt-host.h deleted file mode 100644 index cad2840..0000000 --- a/hosts/daisy/include/daisy-dpt-host.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef SIGNALETIC_DAISY_DPT_H -#define SIGNALETIC_DAISY_DPT_H - -#include "./signaletic-daisy-host.hpp" -#include "../vendor/dpt/lib/daisy_dpt.h" - -enum { - sig_daisy_DPT_CV_IN_1 = daisy::dpt::CV_1, - sig_daisy_DPT_CV_IN_2 = daisy::dpt::CV_2, - sig_daisy_DPT_CV_IN_3 = daisy::dpt::CV_3, - sig_daisy_DPT_CV_IN_4 = daisy::dpt::CV_4, - sig_daisy_DPT_CV_IN_5 = daisy::dpt::CV_5, - sig_daisy_DPT_CV_IN_6 = daisy::dpt::CV_6, - sig_daisy_DPT_CV_IN_7 = daisy::dpt::CV_7, - sig_daisy_DPT_CV_IN_8 = daisy::dpt::CV_8, - sig_daisy_DPT_CV_IN_LAST -}; - -const int sig_daisy_DPT_NUM_ANALOG_INPUTS = daisy::dpt::ADC_LAST; - -enum { - sig_daisy_DPT_CV_OUT_1 = 0, - sig_daisy_DPT_CV_OUT_2, - sig_daisy_DPT_CV_OUT_3, - sig_daisy_DPT_CV_OUT_4, - sig_daisy_DPT_CV_OUT_5, - sig_daisy_DPT_CV_OUT_6, - sig_daisy_DPT_CV_OUT_LAST -}; - -const int sig_daisy_DPT_NUM_ANALOG_OUTPUTS = sig_daisy_DPT_CV_OUT_LAST; - -enum { - sig_daisy_DPT_GATE_IN_1 = sig_daisy_GATE_IN_1, - sig_daisy_DPT_GATE_IN_2 = sig_daisy_GATE_IN_2, - sig_daisy_DPT_GATE_IN_LAST = sig_daisy_GATE_IN_LAST -}; - -const int sig_daisy_DPT_NUM_GATE_INPUTS = sig_daisy_DPT_GATE_IN_LAST; - -enum { - sig_daisy_DPT_GATE_OUT_1 = sig_daisy_GATE_OUT_1, - sig_daisy_DPT_GATE_OUT_2 = sig_daisy_GATE_OUT_2, - sig_daisy_DPT_GATE_OUT_LAST = sig_daisy_GATE_OUT_LAST -}; - -const int sig_daisy_DPT_NUM_GATE_OUTPUTS = sig_daisy_GATE_OUT_LAST; - -const int sig_daisy_DPT_NUM_SWITCHES = 0; -const int sig_daisy_DPT_NUM_TRI_SWITCHES = 0; -const int sig_daisy_DPT_NUM_ENCODERS = 0; - -void sig_daisy_DPT_dacWriterCallback(void* dptHost); - -struct sig_daisy_DPTHost { - struct sig_daisy_Host host; - daisy::Dac7554* expansionDAC; - uint16_t expansionDACBuffer[4]; -}; - -extern struct sig_daisy_Host_Impl sig_daisy_DPTHostImpl; - -void sig_daisy_DPTHostImpl_start(struct sig_daisy_Host* host); - -void sig_daisy_DPTHostImpl_stop(struct sig_daisy_Host* host); - -void sig_daisy_DPTHostImpl_setControlValue( - struct sig_daisy_Host* host, int control, float value); - -float sig_daisy_DPTHostImpl_getGateValue( - struct sig_daisy_Host* host, int control); - -void sig_daisy_DPTHostImpl_setGateValue( - struct sig_daisy_Host* host, int control, float value); - -struct sig_daisy_Host* sig_daisy_DPTHost_new(struct sig_Allocator* allocator, - sig_AudioSettings* audioSettings, - daisy::dpt::DPT* dpt, - struct sig_dsp_SignalEvaluator* evaluator); - -void sig_daisy_DPTHost_Board_init(struct sig_daisy_Host_Board* self, - daisy::dpt::DPT* dpt); - -void sig_daisy_DPTHost_init(struct sig_daisy_DPTHost* self, - sig_AudioSettings* audioSettings, - daisy::dpt::DPT* dpt, - struct sig_dsp_SignalEvaluator* evaluator); - -void sig_daisy_DPTHost_destroy( - struct sig_Allocator* allocator, - struct sig_daisy_DPTHost* self); - -#endif // SIGNALETIC_DAISY_DPT_H diff --git a/hosts/daisy/include/dspcoffee-dpt-device.hpp b/hosts/daisy/include/dspcoffee-dpt-device.hpp new file mode 100644 index 0000000..01cdbc4 --- /dev/null +++ b/hosts/daisy/include/dspcoffee-dpt-device.hpp @@ -0,0 +1,242 @@ +#pragma once + +#include "signaletic-host.h" +#include "signaletic-daisy-host.hpp" +#include "sig-daisy-patch-sm.hpp" +#include "../vendor/dpt/lib/dev/DAC7554.h" +#include "../vendor/libDaisy/src/util/hal_map.h" +#include "../vendor/libDaisy/src/per/tim.h" + +using namespace sig::libdaisy; + +enum { + sig_host_CV_IN_1 = 0, + sig_host_CV_IN_2, + sig_host_CV_IN_3, + sig_host_CV_IN_4, + sig_host_CV_IN_5, + sig_host_CV_IN_6, + sig_host_CV_IN_7, + sig_host_CV_IN_8 +}; + +enum { + sig_host_CV_OUT_1 = 0, + sig_host_CV_OUT_2, + sig_host_CV_OUT_3, + sig_host_CV_OUT_4, + sig_host_CV_OUT_5, + sig_host_CV_OUT_6 +}; + +enum { + sig_host_GATE_IN_1 = 0, + sig_host_GATE_IN_2 +}; + +enum { + sig_host_GATE_OUT_1 = 0, + sig_host_GATE_OUT_2 +}; + +enum { + sig_host_AUDIO_IN_1 = 0, + sig_host_AUDIO_IN_2 +}; + +enum { + sig_host_AUDIO_OUT_1 = 0, + sig_host_AUDIO_OUT_2 +}; + +namespace dspcoffee { +namespace dpt { + static const size_t NUM_ADC_CHANNELS = 8; + + // DPT exposes eight CV inputs from the PatchSM; + // its knobs configured as hardware attenuators of the incoming + // CV jacks, normaled to ~5V when unplugged. + static ADCChannelSpec ADC_CHANNEL_SPECS[NUM_ADC_CHANNELS] = { + {patchsm::PIN_CV_1, INVERT}, // C5 + {patchsm::PIN_CV_2, INVERT}, // C4 + {patchsm::PIN_CV_3, INVERT}, // C3 + {patchsm::PIN_CV_4, INVERT}, // C2 + {patchsm::PIN_CV_8, INVERT}, // C9 + {patchsm::PIN_CV_7, INVERT}, // C8 + {patchsm::PIN_CV_5, INVERT}, // C6 + {patchsm::PIN_CV_6, INVERT} // C7 + }; + + static const size_t NUM_GATES = 2; + + static dsy_gpio_pin GATE_IN_PINS[NUM_GATES] = { + patchsm::PIN_B10, + patchsm::PIN_B9 + }; + + static dsy_gpio_pin GATE_OUT_PINS[NUM_GATES] = { + patchsm::PIN_B6, + patchsm::PIN_B5 + }; + + static const size_t NUM_INTERNAL_DAC_CHANNELS = 2; + static const size_t NUM_EXTERNAL_DAC_CHANNELS = 4; + static const size_t NUM_DAC_CHANNELS = NUM_INTERNAL_DAC_CHANNELS + + NUM_EXTERNAL_DAC_CHANNELS; + + class DPTDevice { + public: + patchsm::PatchSMBoard board; + uint16_t externalDACBuffer[NUM_EXTERNAL_DAC_CHANNELS]; + daisy::Dac7554 externalDAC; + daisy::TimerHandle tim5; + ADCController adcController; + GateInput gateInputs[NUM_GATES]; + InputBank gateInputBank; + GPIOOutput gateOutputs[NUM_GATES]; + OutputBank gateOutputBank; + DMAAnalogOutput dacChannels[NUM_DAC_CHANNELS]; + OutputBank dacOutputBank; + struct sig_host_HardwareInterface hardware; + + static void onEvaluateSignals(size_t size, + struct sig_host_HardwareInterface* hardware) { + DPTDevice* self = static_cast(hardware->userData); + self->Read(); + } + + static void afterEvaluateSignals(size_t size, + struct sig_host_HardwareInterface* hardware) { + DPTDevice* self = static_cast(hardware->userData); + self->Write(); + } + + static void externalDACWriteCallback(void* data) { + DPTDevice* self = static_cast(data); + self->externalDAC.Write(self->externalDACBuffer); + self->externalDAC.WriteDac7554(); + } + + void InitExternalDACWriteTimer( + struct sig_AudioSettings* audioSettings, + daisy::TimerHandle::PeriodElapsedCallback cb, void *data) { + uint32_t target_freq = + static_cast(audioSettings->sampleRate); + uint32_t tim_base_freq = daisy::System::GetPClk2Freq(); + uint32_t tim_period = tim_base_freq / target_freq; + + daisy::TimerHandle::Config timerConfig; + timerConfig.periph = + daisy::TimerHandle::Config::Peripheral::TIM_5; + timerConfig.dir = daisy::TimerHandle::Config::CounterDir::UP; + timerConfig.period = tim_period; + timerConfig.enable_irq = true; + tim5.Init(timerConfig); + HAL_NVIC_SetPriority(TIM5_IRQn, 0x0, 0x0); + tim5.SetCallback(cb, data); + } + + void InitExternalDAC(struct sig_AudioSettings* audioSettings, + daisy::TimerHandle::PeriodElapsedCallback cb, void *data) { + externalDAC.Init(); + InitExternalDACWriteTimer(audioSettings, cb, data); + } + + void Init(struct sig_AudioSettings* audioSettings, + struct sig_dsp_SignalEvaluator* evaluator) { + board.Init(audioSettings->blockSize, audioSettings->sampleRate); + // The DAC and ADC have to be initialized after the board. + InitADCController(); + InitDAC(); + InitExternalDAC(audioSettings, externalDACWriteCallback, + this); + InitControls(); + + hardware = { + .evaluator = evaluator, + .onEvaluateSignals = onEvaluateSignals, + .afterEvaluateSignals = afterEvaluateSignals, + .userData = this, + .numAudioInputChannels = 2, + .audioInputChannels = NULL, // Supplied by audio callback + .numAudioOutputChannels = 2, + .audioOutputChannels = NULL, // Supplied by audio callback + .numADCChannels = NUM_ADC_CHANNELS, + .adcChannels = adcController.channelBank.values, + .numDACChannels = NUM_DAC_CHANNELS, + .dacChannels = dacOutputBank.values, + .numGateInputs = NUM_GATES, + .gateInputs = gateInputBank.values, + .numGPIOOutputs = NUM_GATES, + .gpioOutputs = gateOutputBank.values, + .numToggles = 0, + .toggles = NULL, + .numTriSwitches = 0, + .triSwitches = NULL + }; + } + + void InitADCController() { + // TODO: Scale DPT CV outputs so that they're all in + // a normalized range (e.g. -4V to +4V). + // Currently, I think, they're outputting -4.67V to 7.96V) + //static constexpr struct Normalization DPT_TO_8VPP = { + // .scale = ??f, + // .offset = ??f + // }; + + adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + } + + void InitDAC() { + // TODO: We're actually managing two different buffers + // here. A better architecture would allow for + // multiple DAC (and ADC) instances. + for (size_t i = 0; i < NUM_INTERNAL_DAC_CHANNELS; i++) { + dacChannels[i].Init(board.dacOutputValues, i); + } + + for (size_t i = 0; i < NUM_EXTERNAL_DAC_CHANNELS; i++) { + size_t j = NUM_INTERNAL_DAC_CHANNELS + i; + dacChannels[j].Init(externalDACBuffer, i); + } + + dacOutputBank.outputs = dacChannels; + } + + void InitControls() { + for (size_t i = 0; i < NUM_GATES; i++) { + gateInputs[i].Init(GATE_IN_PINS[i]); + gateOutputs[i].Init(GATE_OUT_PINS[i], + DSY_GPIO_MODE_OUTPUT_PP, DSY_GPIO_NOPULL); + } + gateInputBank.inputs = gateInputs; + gateOutputBank.outputs = gateOutputs; + } + + void Start(daisy::AudioHandle::AudioCallback callback) { + adcController.Start(); + board.StartDac(); + tim5.Start(); + board.audio.Start(callback); + } + + void Stop () { + adcController.Stop(); + board.dac.Stop(); + tim5.Stop(); + board.audio.Stop(); + } + + inline void Read() { + adcController.Read(); + gateInputBank.Read(); + } + + inline void Write() { + gateOutputBank.Write(); + dacOutputBank.Write(); + } + }; +}; +}; diff --git a/hosts/daisy/include/signaletic-daisy-host.hpp b/hosts/daisy/include/signaletic-daisy-host.hpp index 8869cc7..f316961 100644 --- a/hosts/daisy/include/signaletic-daisy-host.hpp +++ b/hosts/daisy/include/signaletic-daisy-host.hpp @@ -28,7 +28,8 @@ static constexpr struct Normalization BI_TO_UNIPOLAR = { }; static constexpr struct Normalization INVERT = { - .scale = -1.0f + .scale = -1.0f, + .offset = 0.0f }; static constexpr struct Normalization INV_UNI_TO_BIPOLAR = { diff --git a/hosts/daisy/src/daisy-dpt-host.cpp b/hosts/daisy/src/daisy-dpt-host.cpp deleted file mode 100644 index c4fcfb3..0000000 --- a/hosts/daisy/src/daisy-dpt-host.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "../include/daisy-dpt-host.h" - -void sig_daisy_DPT_dacWriterCallback(void* dptHost) { - struct sig_daisy_DPTHost* self = static_cast( - dptHost); - daisy::Dac7554* expansionDAC = self->expansionDAC; - expansionDAC->Write(self->expansionDACBuffer); - expansionDAC->WriteDac7554(); -} - -struct sig_daisy_Host_BoardConfiguration sig_daisy_DPTConfig = { - .numAudioInputChannels = 2, - .numAudioOutputChannels = 2, - .numAnalogInputs = sig_daisy_DPT_NUM_ANALOG_INPUTS, - .numAnalogOutputs = sig_daisy_DPT_NUM_ANALOG_OUTPUTS, - .numGateInputs = sig_daisy_DPT_NUM_GATE_INPUTS, - .numGateOutputs = sig_daisy_DPT_NUM_GATE_OUTPUTS, - .numSwitches = sig_daisy_DPT_NUM_SWITCHES, - .numTriSwitches = sig_daisy_DPT_NUM_TRI_SWITCHES, - .numEncoders = sig_daisy_DPT_NUM_ENCODERS -}; - -struct sig_daisy_Host_Impl sig_daisy_DPTHostImpl = { - .getControlValue = sig_daisy_HostImpl_processControlValue, - .setControlValue = sig_daisy_DPTHostImpl_setControlValue, - .getGateValue = sig_daisy_HostImpl_getGateValue, - .setGateValue = sig_daisy_HostImpl_setGateValue, - .getSwitchValue = sig_daisy_HostImpl_noOpGetControl, - .getTriSwitchValue = sig_daisy_HostImpl_noOpGetControl, - .getEncoderIncrement = sig_daisy_HostImpl_noOpGetControl, - .getEncoderButtonValue = sig_daisy_HostImpl_noOpGetControl, - .start = sig_daisy_DPTHostImpl_start, - .stop = sig_daisy_DPTHostImpl_stop, -}; - -void sig_daisy_DPTHostImpl_start(struct sig_daisy_Host* host) { - daisy::dpt::DPT* dpt = - static_cast(host->board.boardInstance); - dpt->StartAdc(); - dpt->StartAudio(sig_daisy_Host_audioCallback); -} - -void sig_daisy_DPTHostImpl_stop(struct sig_daisy_Host* host) { - daisy::dpt::DPT* dpt = - static_cast(host->board.boardInstance); - dpt->StopAudio(); -} - -void sig_daisy_DPTHostImpl_setControlValue(struct sig_daisy_Host* host, - int control, float value) { - struct sig_daisy_DPTHost* self = (struct sig_daisy_DPTHost*) host; - - if (control < 0 || control >= sig_daisy_DPT_NUM_ANALOG_OUTPUTS) { - return; - } - - uint16_t convertedValue = sig_bipolarToInvUint12(value); - - // Controls are indexed 0-5, - // but 2-5 need to be placed into a buffer that will be - // written in the DAC timer interrupt. - // And libdaisy indexes the two CV outs on the Seed/Patch SM - // as 1 and 2, because 0 is reserved for writing to both outputs. - if (control > 1) { - self->expansionDACBuffer[control - 2] = convertedValue; - } else { - daisy::dpt::DPT* dpt = static_cast( - self->host.board.boardInstance); - dpt->WriteCvOut(control + 1, convertedValue, true); - } -} - -struct sig_daisy_Host* sig_daisy_DPTHost_new(struct sig_Allocator* allocator, - sig_AudioSettings* audioSettings, - daisy::dpt::DPT* dpt, - struct sig_dsp_SignalEvaluator* evaluator) { - struct sig_daisy_DPTHost* self = sig_MALLOC(allocator, - struct sig_daisy_DPTHost); - sig_daisy_DPTHost_init(self, audioSettings, dpt, evaluator); - - return &self->host; -} - -void sig_daisy_DPTHost_Board_init(struct sig_daisy_Host_Board* self, - daisy::dpt::DPT* dpt) { - self->boardInstance = (void*) dpt; - self->config = &sig_daisy_DPTConfig; - self->analogControls = &(dpt->controls[0]); - self->gateInputs[0] = &dpt->gate_in_1; - self->gateInputs[1] = &dpt->gate_in_2; - self->gateOutputs[0] = &dpt->gate_out_1; - self->gateOutputs[1] = &dpt->gate_out_2; - self->dac = &dpt->dac; -} - -void sig_daisy_DPTHost_init(struct sig_daisy_DPTHost* self, - sig_AudioSettings* audioSettings, - daisy::dpt::DPT* dpt, - struct sig_dsp_SignalEvaluator* evaluator) { - self->host.impl = &sig_daisy_DPTHostImpl; - self->host.audioSettings = audioSettings; - self->host.evaluator = evaluator; - self->expansionDAC = &dpt->dac_exp; - self->expansionDACBuffer[0] = 4095; - self->expansionDACBuffer[1] = 4095; - self->expansionDACBuffer[2] = 4095; - self->expansionDACBuffer[3] = 4095; - - dpt->Init(); - dpt->SetAudioBlockSize(audioSettings->blockSize); - dpt->SetAudioSampleRate(audioSettings->sampleRate); - sig_daisy_DPTHost_Board_init(&self->host.board, dpt); - sig_daisy_Host_init(&self->host); - dpt->InitTimer(&sig_daisy_DPT_dacWriterCallback, self); -} - -void sig_daisy_DPTHost_destroy(struct sig_Allocator* allocator, - struct sig_daisy_DPTHost* self) { - allocator->impl->free(allocator, self); -} diff --git a/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h b/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h index f311772..f3e926c 100644 --- a/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h +++ b/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h @@ -3,7 +3,6 @@ #define DSY_DEV_DAC_7554_H /**< Macro */ #include #include -#include #include "daisy_core.h" using namespace std; @@ -13,10 +12,10 @@ namespace daisy { /** @addtogroup analog_digital_conversion - @{ + @{ */ -/** +/** Driver for DAC7554, based on code from driver for DAC8568 Based on Code from Westlicht Performer - https://westlicht.github.io/performer/ Port for Daisy by Making Sound Machines - https://github.com/makingsoundmachines @@ -59,8 +58,6 @@ class Dac7554 typedef uint16_t Value; - vector buf; - uint8_t buff[1024]; uint16_t buff16[1024]; @@ -74,7 +71,7 @@ class Dac7554 // configuration currently only uses SPI1, w/ soft chip select. - /** + /** Takes an argument for the pin cfg \param pin_cfg should be a pointer to an array of Dac7554::NUM_PINS dsy_gpio_pins */ @@ -106,4 +103,4 @@ class Dac7554 /** @} */ } // namespace daisy -#endif \ No newline at end of file +#endif