From b73273c1a531fddf55be9c73f89901ecc5c75ae9 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sun, 3 Nov 2024 20:36:41 -0500 Subject: [PATCH] Updates all boards to latest ADCController API. Fixes DPT LFOs. Removes namespace export from DPT DAC7554 driver header file, which avoids ambiguity for "allocator" name. --- .../dpt/lfos/src/signaletic-dpt-lfos.cpp | 165 +++++++++++------- .../lichen-four/lfos/src/lichen-four-lfos.cpp | 19 +- ...ignaletic-lfos-signals.h => clocked-lfo.h} | 4 + hosts/daisy/include/dspcoffee-dpt-device.hpp | 3 +- .../electrosmith-patch-init-device.hpp | 3 +- hosts/daisy/include/kxmx-bluemchen-device.hpp | 3 +- .../daisy/include/lichen-bifocals-device.hpp | 3 +- hosts/daisy/include/lichen-freddie-device.hpp | 3 +- hosts/daisy/include/lichen-medium-device.hpp | 3 +- hosts/daisy/include/ne-versio-device.hpp | 3 +- hosts/daisy/vendor/dpt/lib/dev/DAC7554.h | 3 - 11 files changed, 129 insertions(+), 83 deletions(-) rename hosts/daisy/examples/shared/include/{signaletic-lfos-signals.h => clocked-lfo.h} (96%) 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 2a3d073..1d8ea2a 100644 --- a/hosts/daisy/examples/dpt/lfos/src/signaletic-dpt-lfos.cpp +++ b/hosts/daisy/examples/dpt/lfos/src/signaletic-dpt-lfos.cpp @@ -1,11 +1,11 @@ #include -#include "../../../shared/include/signaletic-lfos-signals.h" +#include "../../../shared/include/clocked-lfo.h" #include "../../../../include/dspcoffee-dpt-device.hpp" #define SAMPLERATE 48000 #define HEAP_SIZE 1024 * 256 // 256KB #define MAX_NUM_SIGNALS 128 - +#define NUM_LFOS 4 uint8_t memory[HEAP_SIZE]; struct sig_AllocatorHeap heap = { .length = HEAP_SIZE, @@ -27,74 +27,118 @@ struct sig_List signals = { }; struct sig_dsp_SignalListEvaluator* evaluator; -struct sig_host_GateIn* clockInput; -struct sig_dsp_ClockDetector* clockFreq; -struct sig_host_ClockedLFO* lfo1; -struct sig_host_ClockedLFO* lfo2; -struct sig_host_ClockedLFO* lfo3; -struct sig_host_ClockedLFO* lfo4; +struct sig_host_GateIn* clockIn; +struct sig_host_CVIn* lfoFrequency[NUM_LFOS]; +struct sig_host_CVIn* lfoScale[NUM_LFOS]; +struct sig_dsp_ClockedLFO* lfo[NUM_LFOS]; +struct sig_host_CVOut* out[NUM_LFOS]; struct sig_dsp_BinaryOp* lfo1PlusLFO3; struct sig_dsp_BinaryOp* lfo2PlusLFO4; 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_host_GateIn_new(&allocator, context); - clockInput->hardware = &host.device.hardware; - clockInput->parameters.control = sig_host_GATE_IN_1; - sig_List_append(&signals, clockInput, status); +struct sig_host_CVIn* makeCVInput(struct sig_SignalContext* context, + struct sig_Status* status, uint8_t control, float scale, float offset) { + struct sig_host_CVIn* cvInput = sig_host_CVIn_new(&allocator, context); + cvInput->hardware = &host.device.hardware; + sig_List_append(&signals, cvInput, status); + cvInput->parameters.control = control; + cvInput->parameters.scale = scale; + cvInput->parameters.offset = offset; + + return cvInput; +} + +void makeCVInputs(struct sig_SignalContext* context, + struct sig_Status* status, struct sig_host_CVIn** cvInputs, uint8_t* controls, size_t numCVInputs, float scale, float offset) { + for (size_t i = 0; i < numCVInputs; i++) { + cvInputs[i] = makeCVInput(context, status, controls[i], scale, offset); + } +} + +struct sig_dsp_ClockedLFO* makeLFO(struct sig_SignalContext* context, + struct sig_Status* status, + struct sig_host_CVIn* frequencyInput, + struct sig_host_CVIn* scaleInput) { + struct sig_dsp_ClockedLFO* lfo = sig_dsp_ClockedLFO_new(&allocator, + context); + sig_List_append(&signals, lfo, status); + lfo->inputs.clock = clockIn->outputs.main; + lfo->inputs.frequencyScale = frequencyInput->outputs.main; + lfo->inputs.scale = scaleInput->outputs.main; + + return lfo; } -void InitClock(struct sig_SignalContext* context, struct sig_Status* status) { - clockFreq = sig_dsp_ClockDetector_new(&allocator, context); - clockFreq->inputs.source = clockInput->outputs.main; - sig_List_append(&signals, clockFreq, status); +void makeLFOs(struct sig_SignalContext* context, + struct sig_Status* status, struct sig_dsp_ClockedLFO** lfos, + struct sig_host_CVIn** frequencyInputs, + struct sig_host_CVIn** scaleInputs, size_t numLFOs) { + for (size_t i = 0; i < numLFOs; i++) { + lfos[i] = makeLFO(context, status, frequencyInputs[i], scaleInputs[i]); + } } -void InitLFO(struct sig_SignalContext* context, struct sig_Status* status) { - lfo1 = sig_host_ClockedLFO_new(&allocator, context); - lfo1->hardware = &host.device.hardware; - sig_List_append(&signals, lfo1, status); - 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_host_ClockedLFO_new(&allocator, context); - lfo2->hardware = &host.device.hardware; - sig_List_append(&signals, lfo2, status); - 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_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_host_CV_IN_5; - lfo3->parameters.lfoGainCVInputControl = sig_host_CV_IN_6; - lfo3->parameters.cvOutputControl = sig_host_CV_OUT_3; - - 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_host_CV_IN_7; - lfo4->parameters.lfoGainCVInputControl = sig_host_CV_IN_8; - lfo4->parameters.cvOutputControl = sig_host_CV_OUT_4; +struct sig_host_CVOut* makeCVOutput(struct sig_SignalContext* context, + struct sig_Status* status, uint8_t control, + struct sig_dsp_ClockedLFO* lfo) { + struct sig_host_CVOut* output = sig_host_CVOut_new(&allocator, context); + output->hardware = &host.device.hardware; + sig_List_append(&signals, output, status); + output->parameters.control = control; + output->inputs.source = lfo->outputs.main; + + return output; +} + +void makeCVOutputs(struct sig_SignalContext* context, + struct sig_Status* status, struct sig_host_CVOut** outputs, + struct sig_dsp_ClockedLFO** lfos, + uint8_t* controls, size_t numOutputs) { + for (size_t i = 0; i < numOutputs; i++) { + outputs[i] = makeCVOutput(context, status, controls[i], lfos[i]); + } +} + +void buildSignalGraph(struct sig_SignalContext* context, + struct sig_Status* status) { + clockIn = sig_host_GateIn_new(&allocator, context); + sig_List_append(&signals, clockIn, status); + clockIn->hardware = &host.device.hardware; + clockIn->parameters.control = sig_host_GATE_IN_1; + + uint8_t frequencyControls[NUM_LFOS] = { + sig_host_CV_IN_1, sig_host_CV_IN_3, + sig_host_CV_IN_5, sig_host_CV_IN_7 + }; + makeCVInputs(context, status, lfoFrequency, frequencyControls, + NUM_LFOS, 10.0f, 0.0f); + + + uint8_t scaleControls[NUM_LFOS] = { + sig_host_CV_IN_2, sig_host_CV_IN_4, + sig_host_CV_IN_6, sig_host_CV_IN_8 + }; + makeCVInputs(context, status, lfoScale, scaleControls, + NUM_LFOS, 1.0f, 0.0f); + makeLFOs(context, status, lfo, lfoFrequency, lfoScale, NUM_LFOS); 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; + lfo1PlusLFO3->inputs.left = lfo[0]->outputs.main; + lfo1PlusLFO3->inputs.right = lfo[2]->outputs.main; 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; + lfo2PlusLFO4->inputs.left = lfo[1]->outputs.main; + lfo2PlusLFO4->inputs.right = lfo[3]->outputs.main; + + uint8_t outputControls[NUM_LFOS] = { + sig_host_CV_OUT_1, sig_host_CV_OUT_2, + sig_host_CV_OUT_3, sig_host_CV_OUT_4 + }; + makeCVOutputs(context, status, out, lfo, outputControls, NUM_LFOS); lfo1And3Out = sig_host_CVOut_new(&allocator, context); lfo1And3Out->hardware = &host.device.hardware; @@ -109,25 +153,14 @@ void InitLFO(struct sig_SignalContext* context, struct sig_Status* status) { lfo2And4Out->inputs.source = lfo2PlusLFO4->outputs.main; 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_host_GateOut_new(&allocator, context); gate1Out->hardware = &host.device.hardware; gate1Out->parameters.control = sig_host_GATE_OUT_1; - gate1Out->inputs.source = clockInput->outputs.main; + gate1Out->inputs.source = clockIn->outputs.main; sig_List_append(&signals, gate1Out, status); } -void buildSignalGraph(struct sig_SignalContext* context, - struct sig_Status* status) { - InitCVInputs(context, status); - InitClock(context, status); - InitLFO(context, status); - InitCVOutputs(context, status); -} - int main(void) { allocator.impl->init(&allocator); diff --git a/hosts/daisy/examples/lichen-four/lfos/src/lichen-four-lfos.cpp b/hosts/daisy/examples/lichen-four/lfos/src/lichen-four-lfos.cpp index 4b0609b..22aefce 100644 --- a/hosts/daisy/examples/lichen-four/lfos/src/lichen-four-lfos.cpp +++ b/hosts/daisy/examples/lichen-four/lfos/src/lichen-four-lfos.cpp @@ -1,7 +1,6 @@ #include -#include "../../../shared/include/signaletic-lfos-signals.h" +#include "../../../shared/include/clocked-lfo.h" #include "../../../shared/include/summed-cv-in.h" - #include "../../../../include/lichen-four-device.hpp" using namespace lichen::four; @@ -28,6 +27,7 @@ struct sig_dsp_SignalListEvaluator* evaluator; DaisyHost host; struct sig_host_GateIn* clockIn; +struct sig_host_SwitchIn* button; struct sig_host_SummedCVIn* lfo1Frequency; struct sig_host_SummedCVIn* lfo2Frequency; struct sig_host_SummedCVIn* lfo3Frequency; @@ -45,7 +45,6 @@ struct sig_host_CVOut* out2; struct sig_host_CVOut* out3; struct sig_host_AudioOut* out4; struct sig_host_GateOut* clockOut; -struct sig_host_SwitchIn* button; struct sig_host_GateOut* led; void buildSignalGraph(struct sig_SignalContext* context, @@ -55,6 +54,11 @@ void buildSignalGraph(struct sig_SignalContext* context, sig_List_append(&signals, clockIn, status); clockIn->parameters.control = sig_host_GATE_IN_1; + button = sig_host_SwitchIn_new(&allocator, context); + button->hardware = &host.device.hardware; + sig_List_append(&signals, button, status); + button->parameters.control = sig_host_GATE_IN_1; + lfo1Frequency = sig_host_SummedCVIn_new(&allocator, context); lfo1Frequency->hardware = &host.device.hardware; sig_List_append(&signals, lfo1Frequency, status); lfo1Frequency->leftCVIn->parameters.control = sig_host_KNOB_1; @@ -165,10 +169,11 @@ void buildSignalGraph(struct sig_SignalContext* context, out4->parameters.channel = sig_host_AUDIO_OUT_2; out4->inputs.source = lfo4->outputs.main; - button = sig_host_SwitchIn_new(&allocator, context); - button->hardware = &host.device.hardware; - sig_List_append(&signals, button, status); - button->parameters.control = sig_host_GATE_IN_1; + clockOut = sig_host_GateOut_new(&allocator, context); + clockOut->hardware = &host.device.hardware; + sig_List_append(&signals, clockOut, status); + clockOut->parameters.control = sig_host_GATE_OUT_1; + clockOut->inputs.source = clockIn->outputs.main; led = sig_host_GateOut_new(&allocator, context); led->hardware = &host.device.hardware; diff --git a/hosts/daisy/examples/shared/include/signaletic-lfos-signals.h b/hosts/daisy/examples/shared/include/clocked-lfo.h similarity index 96% rename from hosts/daisy/examples/shared/include/signaletic-lfos-signals.h rename to hosts/daisy/examples/shared/include/clocked-lfo.h index 7a7483e..a744eb6 100644 --- a/hosts/daisy/examples/shared/include/signaletic-lfos-signals.h +++ b/hosts/daisy/examples/shared/include/clocked-lfo.h @@ -1,3 +1,6 @@ +#ifndef SIGNALETIC_CLOCKED_LFO_H +#define SIGNALETIC_CLOCKED_LFO_H + #include #include "../../../../include/signaletic-host.h" @@ -79,3 +82,4 @@ void sig_dsp_ClockedLFO_destroy(struct sig_Allocator* allocator, self = NULL; } +#endif /* SIGNALETIC_CLOCKED_LFO_H */ diff --git a/hosts/daisy/include/dspcoffee-dpt-device.hpp b/hosts/daisy/include/dspcoffee-dpt-device.hpp index 3e1fe1e..d519974 100644 --- a/hosts/daisy/include/dspcoffee-dpt-device.hpp +++ b/hosts/daisy/include/dspcoffee-dpt-device.hpp @@ -183,7 +183,8 @@ namespace dpt { } void InitADCController() { - adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + adcController.Init(&board.adc, ADC_CHANNEL_SPECS, + NUM_ADC_CHANNELS); } void InitDAC() { diff --git a/hosts/daisy/include/electrosmith-patch-init-device.hpp b/hosts/daisy/include/electrosmith-patch-init-device.hpp index bdc35f7..34d96b2 100644 --- a/hosts/daisy/include/electrosmith-patch-init-device.hpp +++ b/hosts/daisy/include/electrosmith-patch-init-device.hpp @@ -126,7 +126,8 @@ namespace patchinit { } void InitADCController() { - adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + adcController.Init(&board.adc, ADC_CHANNEL_SPECS, + NUM_ADC_CHANNELS); } void InitDAC() { diff --git a/hosts/daisy/include/kxmx-bluemchen-device.hpp b/hosts/daisy/include/kxmx-bluemchen-device.hpp index e72329a..f8d1b1b 100644 --- a/hosts/daisy/include/kxmx-bluemchen-device.hpp +++ b/hosts/daisy/include/kxmx-bluemchen-device.hpp @@ -104,7 +104,8 @@ namespace bluemchen { } void InitADCController() { - adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + adcController.Init(&board.adc, ADC_CHANNEL_SPECS, + NUM_ADC_CHANNELS); } void InitDisplay() { diff --git a/hosts/daisy/include/lichen-bifocals-device.hpp b/hosts/daisy/include/lichen-bifocals-device.hpp index cfae274..4c10701 100644 --- a/hosts/daisy/include/lichen-bifocals-device.hpp +++ b/hosts/daisy/include/lichen-bifocals-device.hpp @@ -132,7 +132,8 @@ namespace bifocals { } void InitADCController() { - adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + adcController.Init(&board.adc, ADC_CHANNEL_SPECS, + NUM_ADC_CHANNELS); } void InitDAC() { diff --git a/hosts/daisy/include/lichen-freddie-device.hpp b/hosts/daisy/include/lichen-freddie-device.hpp index 6e62b50..3581ca8 100644 --- a/hosts/daisy/include/lichen-freddie-device.hpp +++ b/hosts/daisy/include/lichen-freddie-device.hpp @@ -91,7 +91,8 @@ namespace freddie { } void InitADCController() { - adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + adcController.Init(&board.adc, ADC_CHANNEL_SPECS, + NUM_CONTROLS); } void InitButtons() { diff --git a/hosts/daisy/include/lichen-medium-device.hpp b/hosts/daisy/include/lichen-medium-device.hpp index 5521f73..53567e5 100644 --- a/hosts/daisy/include/lichen-medium-device.hpp +++ b/hosts/daisy/include/lichen-medium-device.hpp @@ -148,7 +148,8 @@ namespace medium { } void InitADCController() { - adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + adcController.Init(&board.adc, ADC_CHANNEL_SPECS, + NUM_ADC_CHANNELS); } void InitDAC() { diff --git a/hosts/daisy/include/ne-versio-device.hpp b/hosts/daisy/include/ne-versio-device.hpp index 4211766..4af22a1 100644 --- a/hosts/daisy/include/ne-versio-device.hpp +++ b/hosts/daisy/include/ne-versio-device.hpp @@ -116,7 +116,8 @@ namespace versio { } void InitADCController() { - adcController.Init(&board.adc, ADC_CHANNEL_SPECS); + adcController.Init(&board.adc, ADC_CHANNEL_SPECS, + NUM_ADC_CHANNELS); } void InitControls() { diff --git a/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h b/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h index f3e926c..1d5f63d 100644 --- a/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h +++ b/hosts/daisy/vendor/dpt/lib/dev/DAC7554.h @@ -5,9 +5,6 @@ #include #include "daisy_core.h" -using namespace std; - - namespace daisy {