From 0a56d743882d912016d197716d239ce70f50b78e Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Fri, 3 Feb 2023 17:29:08 +0100 Subject: [PATCH] daisy seed fx should be good, implemented for bw_wah --- examples/common/daisy-seed/daisy-seed.mk | 10 ++- examples/common/daisy-seed/fx.cpp | 82 ++++++++++++++----- examples/fx_wah/daisy-seed/Makefile | 3 +- .../fx_wah/daisy-seed/config_daisy_seed.h | 35 ++++++++ 4 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 examples/fx_wah/daisy-seed/config_daisy_seed.h diff --git a/examples/common/daisy-seed/daisy-seed.mk b/examples/common/daisy-seed/daisy-seed.mk index ed7ac51..9bab550 100644 --- a/examples/common/daisy-seed/daisy-seed.mk +++ b/examples/common/daisy-seed/daisy-seed.mk @@ -1,9 +1,9 @@ LIBDAISY_DIR := ${ROOT_DIR}/../../../../libDaisy ifdef SYNTH -CPP_SOURCES = ${ROOT_DIR}/../../common/daisy-seed/synth.cpp +CPP_SOURCES = ${ROOT_DIR}/../../common/daisy-seed/synth.cpp ${CPP_SOURCES_EXTRA} else -CPP_SOURCES = ${ROOT_DIR}/../../common/daisy-seed/fx.cpp +CPP_SOURCES = ${ROOT_DIR}/../../common/daisy-seed/fx.cpp ${CPP_SOURCES_EXTRA} endif LDFLAGS += -u _printf_float @@ -12,5 +12,11 @@ SYSTEM_FILES_DIR = ${LIBDAISY_DIR}/core include ${SYSTEM_FILES_DIR}/Makefile CPPFLAGS += \ + -I${ROOT_DIR} \ + -I${ROOT_DIR}/../src \ + -I${ROOT_DIR}/../../../include + +CFLAGS += \ + -I${ROOT_DIR} \ -I${ROOT_DIR}/../src \ -I${ROOT_DIR}/../../../include diff --git a/examples/common/daisy-seed/fx.cpp b/examples/common/daisy-seed/fx.cpp index da249e4..1783907 100644 --- a/examples/common/daisy-seed/fx.cpp +++ b/examples/common/daisy-seed/fx.cpp @@ -1,52 +1,96 @@ #include "daisy_seed.h" #include "config.h" +#include "config_daisy_seed.h" + +#define BLOCK_SIZE 32 using namespace daisy; DaisySeed hardware; +CpuLoadMeter loadMeter; P_TYPE instance; +float buf[2][BLOCK_SIZE]; +float *bufs[2] = { buf[0], buf[1] }; + +static void setParams() { + for (int i = 0; i < NUM_PINS; i++) + P_SET_PARAMETER(&instance, config_pins[i].param_index, hardware.adc.GetFloat(i)); +} + static void AudioCallback( AudioHandle::InterleavingInputBuffer in, AudioHandle::InterleavingOutputBuffer out, size_t size) { - // set params - // update coeffs ctrl - for (size_t i = 0; i < size; i++) - // update coeffs audio - out[i] = in[i]; + loadMeter.OnBlockStart(); + setParams(); + const size_t n = size >> 1; +#if NUM_CHANNELS_IN != 0 + for (size_t i = 0; i < n; i++) { + const size_t j = i << 1; + buf[0][i] = in[j]; +# if NUM_CHANNELS_IN > 1 + buf[1][i] = in[j + 1]; +# endif + } +#endif + P_PROCESS(&instance, (const float **)bufs, bufs, n); + for (size_t i = 0; i < n; i++) { + const size_t j = i << 1; +#if NUM_CHANNELS_OUT > 0 + out[j] = buf[0][i]; +#else + out[j] = 0.f; +#endif +#if NUM_CHANNELS_OUT > 1 + out[j + 1] = buf[1][i]; +#else + out[j + 1] = 0.f; +#endif + } + loadMeter.OnBlockEnd(); } int main() { hardware.Configure(); hardware.Init(); - // ... - AdcChannelConfig adcConfig; - adcConfig.InitSingle(hardware.GetPin(21)); + AdcChannelConfig adcConfig[NUM_PINS]; + for (int i = 0; i < NUM_PINS; i++) + adcConfig[i].InitSingle(hardware.GetPin(config_pins[i].pin)); - hardware.adc.Init(&adcConfig, 1); + hardware.adc.Init(adcConfig, NUM_PINS); hardware.adc.Start(); - // ... - hardware.SetAudioBlockSize(32); + hardware.SetAudioBlockSize(BLOCK_SIZE); float sample_rate = hardware.AudioSampleRate(); - // init - // set sample rate + P_INIT(&instance); + P_SET_SAMPLE_RATE(&instance, sample_rate); hardware.StartLog(); - // set params - // reset coeffs - // reset state + loadMeter.Init(sample_rate, BLOCK_SIZE); + + setParams(); + P_RESET(&instance); hardware.StartAudio(AudioCallback); while (1) { - //hardware.adc.GetFloat(0); - //hardware.PrintLine("%f",x); - //System::Delay(x); + const float avgLoad = loadMeter.GetAvgCpuLoad(); + const float maxLoad = loadMeter.GetMaxCpuLoad(); + const float minLoad = loadMeter.GetMinCpuLoad(); + hardware.PrintLine("---"); + for (int i = 0; i < NUM_PARAMETERS; i++) + if (config_parameters[i].out) + hardware.PrintLine("%s: %f", config_parameters[i].name, P_GET_PARAMETER(&instance, i)); + hardware.PrintLine("---"); + hardware.PrintLine("Processing Load %:"); + hardware.PrintLine("Max: " FLT_FMT3, FLT_VAR3(maxLoad * 100.0f)); + hardware.PrintLine("Avg: " FLT_FMT3, FLT_VAR3(avgLoad * 100.0f)); + hardware.PrintLine("Min: " FLT_FMT3, FLT_VAR3(minLoad * 100.0f)); + System::Delay(500); } } diff --git a/examples/fx_wah/daisy-seed/Makefile b/examples/fx_wah/daisy-seed/Makefile index 958ca97..49c78cc 100644 --- a/examples/fx_wah/daisy-seed/Makefile +++ b/examples/fx_wah/daisy-seed/Makefile @@ -1,6 +1,7 @@ ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) TARGET = bw_example_fx_wah -CPP_SOURCES += ${ROOT_DIR}/../src/bw_example_fx_wah.c + +C_SOURCES += ${ROOT_DIR}/../src/bw_example_fx_wah.c include ${ROOT_DIR}/../../common/daisy-seed/daisy-seed.mk diff --git a/examples/fx_wah/daisy-seed/config_daisy_seed.h b/examples/fx_wah/daisy-seed/config_daisy_seed.h new file mode 100644 index 0000000..c93a1f8 --- /dev/null +++ b/examples/fx_wah/daisy-seed/config_daisy_seed.h @@ -0,0 +1,35 @@ +/* + * Brickworks + * + * Copyright (C) 2023 Orastron Srl unipersonale + * + * Brickworks is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * Brickworks is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Brickworks. If not, see . + * + * File authors: Stefano D'Angelo, Paolo Marrone + */ + +#ifndef _CONFIG_DAISY_SEED_H +#define _CONFIG_DAISY_SEED_H + +struct config_pin { + int param_index; + int pin; +}; + +#define NUM_PINS 1 + +static struct config_pin config_pins[NUM_PINS] = { + { 0, 15 } +}; + +#endif