Skip to content

Commit

Permalink
Updates all boards to latest ADCController API. Fixes DPT LFOs.
Browse files Browse the repository at this point in the history
Removes namespace export from DPT DAC7554 driver header file,
which avoids ambiguity for "allocator" name.
  • Loading branch information
colinbdclark committed Nov 4, 2024
1 parent b5011f8 commit b73273c
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 83 deletions.
165 changes: 99 additions & 66 deletions hosts/daisy/examples/dpt/lfos/src/signaletic-dpt-lfos.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <libsignaletic.h>
#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,
Expand All @@ -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;
Expand All @@ -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);

Expand Down
19 changes: 12 additions & 7 deletions hosts/daisy/examples/lichen-four/lfos/src/lichen-four-lfos.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <libsignaletic.h>
#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;
Expand All @@ -28,6 +27,7 @@ struct sig_dsp_SignalListEvaluator* evaluator;
DaisyHost<FourDevice> 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;
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef SIGNALETIC_CLOCKED_LFO_H
#define SIGNALETIC_CLOCKED_LFO_H

#include <libsignaletic.h>
#include "../../../../include/signaletic-host.h"

Expand Down Expand Up @@ -79,3 +82,4 @@ void sig_dsp_ClockedLFO_destroy(struct sig_Allocator* allocator,
self = NULL;
}

#endif /* SIGNALETIC_CLOCKED_LFO_H */
3 changes: 2 additions & 1 deletion hosts/daisy/include/dspcoffee-dpt-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion hosts/daisy/include/electrosmith-patch-init-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion hosts/daisy/include/kxmx-bluemchen-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion hosts/daisy/include/lichen-bifocals-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion hosts/daisy/include/lichen-freddie-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion hosts/daisy/include/lichen-medium-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion hosts/daisy/include/ne-versio-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 0 additions & 3 deletions hosts/daisy/vendor/dpt/lib/dev/DAC7554.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <stdint.h>
#include "daisy_core.h"

using namespace std;


namespace daisy
{

Expand Down

0 comments on commit b73273c

Please sign in to comment.