Skip to content

Commit

Permalink
lichen-community-systemsgh-22: Adds a Patch_init() device and updates…
Browse files Browse the repository at this point in the history
… examples to new Host API.
  • Loading branch information
colinbdclark committed Jul 8, 2024
1 parent f5dc957 commit 40dc209
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 136 deletions.
4 changes: 2 additions & 2 deletions hosts/daisy/examples/patch_init/calibrator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ 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 ../../../src/signaletic-daisy-host.cpp ../../../src/daisy-patch-sm-host.cpp
CPP_SOURCES = ../../../src/signaletic-daisy-host.cpp ../../../src/sig-daisy-patch-sm.cpp src/${TARGET}.cpp

USE_FATFS = 0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "daisy.h"
#include <libsignaletic.h>
#include "../../../../include/daisy-patch-sm-host.h"
#include "../../../../include/electrosmith-patch-init-device.hpp"

#define SAMPLERATE 48000
#define HEAP_SIZE 1024 * 256 // 256KB
#define MAX_NUM_SIGNALS 32

Expand All @@ -16,31 +16,31 @@ struct sig_Allocator allocator = {
.heap = &heap
};

daisy::patch_sm::DaisyPatchSM patchInit;

struct sig_dsp_Signal* listStorage[MAX_NUM_SIGNALS];
struct sig_List signals;
struct sig_dsp_SignalListEvaluator* evaluator;
struct sig_daisy_Host* host;
sig::libdaisy::DaisyHost<electrosmith::patchinit::PatchInitDevice> host;

struct sig_dsp_ConstantValue* ampScale;
struct sig_daisy_SwitchIn* button;
struct sig_daisy_CVIn* cv1In;
struct sig_host_SwitchIn* button;
struct sig_host_CVIn* cv1In;
struct sig_dsp_Calibrator* cv1Calibrator;
struct sig_dsp_Oscillator* sine1;
struct sig_dsp_LinearToFreq* sine1Voct;
struct sig_daisy_AudioOut* audio1Out;
struct sig_daisy_AudioOut* audio2Out;
struct sig_host_AudioOut* audio1Out;
struct sig_host_AudioOut* audio2Out;


void buildGraph(struct sig_SignalContext* context, struct sig_Status* status) {
button = sig_daisy_SwitchIn_new(&allocator, context, host);
button = sig_host_SwitchIn_new(&allocator, context);
button->hardware = &host.device.hardware;
sig_List_append(&signals, button, status);
button->parameters.control = sig_daisy_PatchSM_SWITCH_1;
button->parameters.control = sig_host_TOGGLE_1;

cv1In = sig_daisy_CVIn_new(&allocator, context, host);
cv1In = sig_host_CVIn_new(&allocator, context);
cv1In->hardware = &host.device.hardware;
sig_List_append(&signals, cv1In, status);
cv1In->parameters.control = sig_daisy_PatchInit_CV_IN_1;
cv1In->parameters.control = sig_host_CV_IN_1;
cv1In->parameters.scale = 5.0f;

cv1Calibrator = sig_dsp_Calibrator_new(&allocator, context);
Expand All @@ -59,16 +59,17 @@ void buildGraph(struct sig_SignalContext* context, struct sig_Status* status) {
sine1->inputs.freq = sine1Voct->outputs.main;
sine1->inputs.mul = ampScale->outputs.main;

audio1Out = sig_daisy_AudioOut_new(&allocator, context, host);
audio1Out = sig_host_AudioOut_new(&allocator, context);
audio1Out->hardware = &host.device.hardware;
sig_List_append(&signals, audio1Out, status);
audio1Out->parameters.channel = sig_daisy_AUDIO_OUT_1;
audio1Out->parameters.channel = sig_host_AUDIO_OUT_1;
audio1Out->inputs.source = sine1->outputs.main;

audio2Out = sig_daisy_AudioOut_new(&allocator, context, host);
audio2Out = sig_host_AudioOut_new(&allocator, context);
audio2Out->hardware = &host.device.hardware;
sig_List_append(&signals, audio2Out, status);
audio2Out->parameters.channel = sig_daisy_AUDIO_OUT_2;
audio2Out->parameters.channel = sig_host_AUDIO_OUT_2;
audio2Out->inputs.source = sine1->outputs.main;

}

int main(void) {
Expand All @@ -79,21 +80,19 @@ int main(void) {
sig_List_init(&signals, (void**) &listStorage, MAX_NUM_SIGNALS);

struct sig_AudioSettings audioSettings = {
.sampleRate = 48000,
.sampleRate = SAMPLERATE,
.numChannels = 2,
.blockSize = 48
};

struct sig_SignalContext* context = sig_SignalContext_new(&allocator,
&audioSettings);
evaluator = sig_dsp_SignalListEvaluator_new(&allocator, &signals);
host = sig_daisy_PatchSMHost_new(&allocator,
&audioSettings, &patchInit,
(struct sig_dsp_SignalEvaluator*) evaluator);
sig_daisy_Host_registerGlobalHost(host);
host.Init(&audioSettings, (struct sig_dsp_SignalEvaluator*) evaluator);

buildGraph(context, &status);

host->impl->start(host);
host.Start();

while (1) {}
}
4 changes: 2 additions & 2 deletions hosts/daisy/examples/patch_init/chorus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ DEBUG = 0
OPT = -O3

# 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 ../../../src/signaletic-daisy-host.cpp ../../../src/daisy-patch-sm-host.cpp
CPP_SOURCES = ../../../src/signaletic-daisy-host.cpp ../../../src/sig-daisy-patch-sm.cpp src/${TARGET}.cpp

USE_FATFS = 0

Expand Down
84 changes: 43 additions & 41 deletions hosts/daisy/examples/patch_init/chorus/src/patch-init-chorus.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "daisy.h"
#include <libsignaletic.h>
#include "../../../../include/daisy-patch-sm-host.h"
#include "../../../../include/electrosmith-patch-init-device.hpp"

#define SAMPLERATE 96000
#define DELAY_LINE_LENGTH SAMPLERATE
Expand Down Expand Up @@ -41,27 +40,25 @@ struct sig_Allocator allocator = {
struct sig_dsp_Signal* listStorage[MAX_NUM_SIGNALS];
struct sig_List signals;
struct sig_dsp_SignalListEvaluator* evaluator;

daisy::patch_sm::DaisyPatchSM patchInit;
struct sig_daisy_Host* host;
sig::libdaisy::DaisyHost<electrosmith::patchinit::PatchInitDevice> host;

struct sig_dsp_ConstantValue* blend;
struct sig_dsp_ConstantValue* feedforward;
struct sig_dsp_ConstantValue* feedback;
struct sig_dsp_ConstantValue* delayTime;
struct sig_dsp_ConstantValue* modulationSpeed;
struct sig_dsp_ConstantValue* modulationWidth;
struct sig_daisy_FilteredCVIn* blendKnob;
struct sig_daisy_FilteredCVIn* feedForwardKnob;
struct sig_daisy_FilteredCVIn* feedbackKnob;
struct sig_daisy_FilteredCVIn* delayTimeKnob;
struct sig_host_FilteredCVIn* blendKnob;
struct sig_host_FilteredCVIn* feedForwardKnob;
struct sig_host_FilteredCVIn* feedbackKnob;
struct sig_host_FilteredCVIn* delayTimeKnob;
struct sig_dsp_Chorus* leftChorus;
struct sig_dsp_Chorus* rightChorus;
struct sig_daisy_AudioIn* leftIn;
struct sig_daisy_AudioIn* rightIn;
struct sig_daisy_AudioOut* leftOut;
struct sig_daisy_AudioOut* rightOut;
struct sig_daisy_CVOut* modulatorLEDOut;
struct sig_host_AudioIn* leftIn;
struct sig_host_AudioIn* rightIn;
struct sig_host_AudioOut* leftOut;
struct sig_host_AudioOut* rightOut;
struct sig_host_CVOut* modulatorLEDOut;

void buildSignalGraph(struct sig_SignalContext* context,
struct sig_Status* status) {
Expand All @@ -79,27 +76,32 @@ void buildSignalGraph(struct sig_SignalContext* context,
modulationWidth = sig_dsp_ConstantValue_new(&allocator, context,
0.007936507936508f); // ~8ms. Dattoro Part 2 p776.

blendKnob = sig_daisy_FilteredCVIn_new(&allocator, context, host);
blendKnob = sig_host_FilteredCVIn_new(&allocator, context);
blendKnob->hardware = &host.device.hardware;
sig_List_append(&signals, blendKnob, status);
blendKnob->parameters.control = sig_daisy_PatchInit_KNOB_1;
blendKnob->parameters.control = sig_host_KNOB_1;

delayTimeKnob = sig_daisy_FilteredCVIn_new(&allocator, context, host);
delayTimeKnob = sig_host_FilteredCVIn_new(&allocator, context);
delayTimeKnob->hardware = &host.device.hardware;
sig_List_append(&signals, delayTimeKnob, status);
delayTimeKnob->parameters.control = sig_daisy_PatchInit_KNOB_2;
delayTimeKnob->parameters.control = sig_host_KNOB_2;

feedForwardKnob = sig_daisy_FilteredCVIn_new(&allocator, context, host);
feedForwardKnob = sig_host_FilteredCVIn_new(&allocator, context);
feedForwardKnob->hardware = &host.device.hardware;
sig_List_append(&signals, feedForwardKnob, status);
feedForwardKnob->parameters.control = sig_daisy_PatchInit_KNOB_3;
feedForwardKnob->parameters.control = sig_host_KNOB_3;

feedbackKnob = sig_daisy_FilteredCVIn_new(&allocator, context, host);
feedbackKnob = sig_host_FilteredCVIn_new(&allocator, context);
feedbackKnob->hardware = &host.device.hardware;
sig_List_append(&signals, feedbackKnob, status);
feedbackKnob->parameters.control = sig_daisy_PatchInit_KNOB_4;
feedbackKnob->parameters.control = sig_host_KNOB_4;
feedbackKnob->parameters.scale = 2.0f;
feedbackKnob->parameters.offset = -1.0f;

leftIn = sig_daisy_AudioIn_new(&allocator, context, host);
leftIn = sig_host_AudioIn_new(&allocator, context);
leftIn->hardware = &host.device.hardware;
sig_List_append(&signals, leftIn, status);
leftIn->parameters.channel = 0;
leftIn->parameters.channel = sig_host_AUDIO_IN_1;

leftChorus = sig_dsp_Chorus_new(&allocator, context);
sig_List_append(&signals, leftChorus, status);
Expand All @@ -113,9 +115,10 @@ void buildSignalGraph(struct sig_SignalContext* context,
leftChorus->inputs.speed = modulationSpeed->outputs.main;
leftChorus->inputs.width = modulationWidth->outputs.main;

rightIn = sig_daisy_AudioIn_new(&allocator, context, host);
rightIn = sig_host_AudioIn_new(&allocator, context);
rightIn->hardware = &host.device.hardware;
sig_List_append(&signals, rightIn, status);
rightIn->parameters.channel = 1;
rightIn->parameters.channel = sig_host_AUDIO_IN_2;

rightChorus = sig_dsp_Chorus_new(&allocator, context);
sig_List_append(&signals, rightChorus, status);
Expand All @@ -129,19 +132,22 @@ void buildSignalGraph(struct sig_SignalContext* context,
rightChorus->inputs.speed = modulationSpeed->outputs.main;
rightChorus->inputs.width = modulationWidth->outputs.main;

leftOut = sig_daisy_AudioOut_new(&allocator, context, host);
leftOut = sig_host_AudioOut_new(&allocator, context);
leftOut->hardware = &host.device.hardware;
sig_List_append(&signals, leftOut, status);
leftOut->parameters.channel = sig_daisy_AUDIO_OUT_1;
leftOut->parameters.channel = sig_host_AUDIO_OUT_1;
leftOut->inputs.source = leftChorus->outputs.main;

rightOut = sig_daisy_AudioOut_new(&allocator, context, host);
rightOut = sig_host_AudioOut_new(&allocator, context);
rightOut->hardware = &host.device.hardware;
sig_List_append(&signals, rightOut, status);
rightOut->parameters.channel = sig_daisy_AUDIO_OUT_2;
rightOut->parameters.channel = sig_host_AUDIO_OUT_2;
rightOut->inputs.source = rightChorus->outputs.main;

modulatorLEDOut = sig_daisy_CVOut_new(&allocator, context, host);
modulatorLEDOut = sig_host_CVOut_new(&allocator, context);
modulatorLEDOut->hardware = &host.device.hardware;
sig_List_append(&signals, modulatorLEDOut, status);
modulatorLEDOut->parameters.control = sig_daisy_PatchInit_LED;
modulatorLEDOut->parameters.control = sig_host_CV_OUT_2;
modulatorLEDOut->inputs.source = leftChorus->outputs.modulator;
modulatorLEDOut->parameters.scale = 0.5f;
modulatorLEDOut->parameters.offset = 0.5f;
Expand All @@ -160,18 +166,14 @@ int main(void) {
sig_Status_init(&status);
sig_List_init(&signals, (void**) &listStorage, MAX_NUM_SIGNALS);

evaluator = sig_dsp_SignalListEvaluator_new(&allocator, &signals);
host = sig_daisy_PatchSMHost_new(&allocator,
&audioSettings, &patchInit,
(struct sig_dsp_SignalEvaluator*) evaluator);
sig_daisy_Host_registerGlobalHost(host);

struct sig_SignalContext* context = sig_SignalContext_new(&allocator,
&audioSettings);
evaluator = sig_dsp_SignalListEvaluator_new(&allocator, &signals);
host.Init(&audioSettings, (struct sig_dsp_SignalEvaluator*) evaluator);

buildSignalGraph(context, &status);
host->impl->start(host);

while (1) {
host.Start();

}
while (1) {}
}
4 changes: 2 additions & 2 deletions hosts/daisy/examples/patch_init/fm-osc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ DEBUG = 0
OPT = -O3

# 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 ../../../src/signaletic-daisy-host.cpp ../../../src/daisy-patch-sm-host.cpp
CPP_SOURCES = ../../../src/signaletic-daisy-host.cpp ../../../src/sig-daisy-patch-sm.cpp src/${TARGET}.cpp

USE_FATFS = 0

Expand Down
Loading

0 comments on commit 40dc209

Please sign in to comment.