From 07f232fd30416f3e51fe94c50a4c3e364d09c657 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 28 Jun 2021 13:48:05 +0200 Subject: [PATCH] . --- MicroDexed.ino | 28 ++++++++--------- UI.hpp | 1 + config.h | 2 +- dexed_sd.h | 1 + synth_dexed.h | 84 ++++++++++++++++++++++++++++++++++++++------------ 5 files changed, 82 insertions(+), 34 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 82b286b..9d70815 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -24,12 +24,12 @@ #include #include "config.h" #include +#include #include #include #include #include #include -#include "OpenAudio_ArduinoLibrary.h" #include "midi_devices.hpp" #include "synth_dexed.h" #include "dexed_sd.h" @@ -44,6 +44,7 @@ #include "UI.hpp" // Audio engines +//AudioSynthDexed* MicroDexed[NUM_DEXED]; AudioSynthDexed_F32* MicroDexed[NUM_DEXED]; AudioConvert_F32toI16* convertf32toi16[NUM_DEXED]; #if defined(USE_FX) @@ -178,6 +179,7 @@ AudioConnection * dynamicConnections[NUM_DEXED * 5]; #endif void create_audio_engine_chain(uint8_t instance_id) { + //MicroDexed[instance_id] = new AudioSynthDexed(SAMPLE_RATE); MicroDexed[instance_id] = new AudioSynthDexed_F32(SAMPLE_RATE); convertf32toi16[instance_id] = new AudioConvert_F32toI16(); mono2stereo[instance_id] = new AudioEffectMonoStereo(); @@ -193,15 +195,15 @@ void create_audio_engine_chain(uint8_t instance_id) delay_mixer[instance_id] = new AudioMixer4(); #endif - //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, microdexed_peak_mixer, instance_id); - dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *convertf32toi16[instance_id], 0); - dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, microdexed_peak_mixer, instance_id); + dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, microdexed_peak_mixer, instance_id); + //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *convertf32toi16[instance_id], 0); + //dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, microdexed_peak_mixer, instance_id); #if defined(USE_FX) - //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *chorus_mixer[instance_id], 0); - //dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *modchorus[instance_id], 0); - dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, *chorus_mixer[instance_id], 0); - dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, *modchorus[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *chorus_mixer[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *modchorus[instance_id], 0); + //dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, *chorus_mixer[instance_id], 0); + //dynamicConnections[nDynamic++] = new AudioConnection(*convertf32toi16[instance_id], 0, *modchorus[instance_id], 0); #if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT dynamicConnections[nDynamic++] = new AudioConnection(*chorus_modulator[instance_id], 0, *modchorus_filter[instance_id], 0); dynamicConnections[nDynamic++] = new AudioConnection(*modchorus_filter[instance_id], 0, *modchorus[instance_id], 1); @@ -283,11 +285,6 @@ extern void getNoteName(char* noteName, uint8_t noteNumber); ***********************************************************************/ void setup() { - // Start audio system - //AudioNoInterrupts(); - AudioMemory(AUDIO_MEM); - AudioMemory_F32(AUDIO_MEM_F32); - #ifdef DISPLAY_LCD_SPI pinMode(SDCARD_CS_PIN, OUTPUT); pinMode(U8X8_CS_PIN, OUTPUT); @@ -308,7 +305,6 @@ void setup() #endif #endif - #ifdef DEBUG generate_version_string(version_string, sizeof(version_string)); @@ -330,6 +326,10 @@ void setup() setup_midi_devices(); + // Start audio system + AudioMemory_F32(AUDIO_MEM_F32, {44117.0, 128}); + AudioMemory(AUDIO_MEM); + #if defined(TEENSY_AUDIO_BOARD) sgtl5000_1.enable(); sgtl5000_1.lineOutLevel(SGTL5000_LINEOUT_LEVEL); diff --git a/UI.hpp b/UI.hpp index ee360e3..bc663e7 100644 --- a/UI.hpp +++ b/UI.hpp @@ -70,6 +70,7 @@ extern void change_disp_sd(bool d); #endif extern AudioControlSGTL5000 sgtl5000_1; +//extern AudioSynthDexed* MicroDexed[NUM_DEXED]; extern AudioSynthDexed_F32* MicroDexed[NUM_DEXED]; #if defined(USE_FX) extern AudioSynthWaveform* chorus_modulator[NUM_DEXED]; diff --git a/config.h b/config.h index 9748a5f..01b1749 100644 --- a/config.h +++ b/config.h @@ -131,7 +131,7 @@ //#if AUDIO_BLOCK_SAMPLES == 64 //#define AUDIO_MEM 256 //#else -#define AUDIO_MEM 300 +#define AUDIO_MEM 128 #define AUDIO_MEM_F32 10 //#endif diff --git a/dexed_sd.h b/dexed_sd.h index f18364d..7720bce 100644 --- a/dexed_sd.h +++ b/dexed_sd.h @@ -30,6 +30,7 @@ #define DEXED_SYSEX_H_INCLUDED extern uint8_t sd_card; +//extern AudioSynthDexed* MicroDexed[NUM_DEXED]; extern AudioSynthDexed_F32* MicroDexed[NUM_DEXED]; extern void show_patch(uint8_t instance_id); diff --git a/synth_dexed.h b/synth_dexed.h index 2cbd5ab..1046095 100644 --- a/synth_dexed.h +++ b/synth_dexed.h @@ -4,7 +4,7 @@ #include "config.h" /***************************************************** - CODE; orig_code/synth.h + CODE: orig_code/synth.h *****************************************************/ /* Copyright 2012 Google Inc. @@ -78,7 +78,7 @@ inline static T max(const T& a, const T& b) { //===================================================== /***************************************************** - CODE; orig_code/aligned_buf.h + CODE: orig_code/aligned_buf.h *****************************************************/ /* Copyright 2013 Google Inc. @@ -113,7 +113,7 @@ class AlignedBuf { //===================================================== /***************************************************** - CODE; orig_code/sin.h + CODE: orig_code/sin.h *****************************************************/ /* Copyright 2012 Google Inc. @@ -180,7 +180,7 @@ int32_t Sin::lookup(int32_t phase) { //===================================================== /***************************************************** - CODE; orig_code/exp2.h + CODE: orig_code/exp2.h *****************************************************/ /* Copyright 2012 Google Inc. @@ -265,7 +265,7 @@ int32_t Tanh::lookup(int32_t x) { //===================================================== /***************************************************** - CODE; orig_code/fast_log.h + CODE: orig_code/fast_log.h *****************************************************/ /* ---------------------------------------------------------------------- https://community.arm.com/tools/f/discussions/4292/cmsis-dsp-new-functionality-proposal/22621#22621 @@ -320,7 +320,7 @@ inline float dbToUnit(float db) { //===================================================== /***************************************************** - CODE; orig_code/freqlut.h + CODE: orig_code/freqlut.h *****************************************************/ /* Copyright 2012 Google Inc. @@ -346,7 +346,7 @@ class Freqlut { //===================================================== /***************************************************** - CODE; orig_code/lfo.h + CODE: orig_code/lfo.h *****************************************************/ /* Copyright 2013 Google Inc. @@ -394,7 +394,7 @@ class Lfo { //===================================================== /***************************************************** - CODE; orig_code/env.h + CODE: orig_code/env.h *****************************************************/ /* Copyright 2017 Pascal Gauthier. @@ -474,7 +474,7 @@ class Env { //===================================================== /***************************************************** - CODE; orig_code/pitchenv.h + CODE: orig_code/pitchenv.h *****************************************************/ /* Copyright 2013 Google Inc. @@ -527,7 +527,7 @@ extern const int8_t pitchenv_tab[]; //===================================================== /***************************************************** - CODE; orig_code/controllers.h + CODE: orig_code/controllers.h *****************************************************/ /* Copyright 2013 Google Inc. @@ -666,7 +666,7 @@ class Controllers { //===================================================== /***************************************************** - CODE; orig_code/PluginFx.h + CODE: orig_code/PluginFx.h *****************************************************/ /** @@ -740,7 +740,7 @@ class PluginFx { //===================================================== /***************************************************** - CODE; orig_code/fm_op_kernel.h + CODE: orig_code/fm_op_kernel.h *****************************************************/ /* Copyright 2012 Google Inc. @@ -788,7 +788,7 @@ class FmOpKernel { //===================================================== /***************************************************** - CODE; orig_code/fm_core.h + CODE: orig_code/fm_core.h *****************************************************/ /* Copyright 2012 Google Inc. @@ -841,7 +841,7 @@ class FmCore { //===================================================== /***************************************************** - CODE; orig_code/dx7note.h + CODE: orig_code/dx7note.h *****************************************************/ /* Copyright 2016-2017 Pascal Gauthier. @@ -920,7 +920,7 @@ class Dx7Note { //===================================================== /***************************************************** - CODE; orig_code/dexed.h + CODE: orig_code/dexed.h *****************************************************/ /* MicroDexed @@ -1139,7 +1139,7 @@ class Dexed //===================================================== /***************************************************** - CODE; orig_code/porta.h + CODE: orig_code/porta.h *****************************************************/ /* Copyright 2019 Jean Pierre Cimalando. @@ -1166,8 +1166,54 @@ struct Porta { //===================================================== /***************************************************** - CODE; orig_code/source_microdexed.h + CODE: orig_code/synth_microdexed.h *****************************************************/ +class AudioSynthDexed : public AudioStream, public Dexed { + public: + const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); + uint32_t xrun = 0; + uint16_t render_time_max = 0; + + AudioSynthDexed(uint16_t sample_rate) : AudioStream(0, NULL), Dexed(sample_rate) { }; + + void update(void) + { + if (in_update == true) + { + xrun++; + return; + } + else + in_update = true; + + elapsedMicros render_time; + audio_block_t *lblock; + + lblock = allocate(); + + if (!lblock) + { + in_update = false; + return; + } + + getSamples(AUDIO_BLOCK_SAMPLES, lblock->data); + + if (render_time > audio_block_time_us) // everything greater audio_block_time_us (2.9ms for buffer size of 128) is a buffer underrun! + xrun++; + + if (render_time > render_time_max) + render_time_max = render_time; + + transmit(lblock, 0); + release(lblock); + + in_update = false; + }; + + private: + volatile bool in_update = false; +}; class AudioSynthDexed_F32 : public AudioStream_F32, public Dexed { public: @@ -1206,8 +1252,8 @@ class AudioSynthDexed_F32 : public AudioStream_F32, public Dexed { if (render_time > render_time_max) render_time_max = render_time; - AudioStream_F32::transmit(lblock, 0); - AudioStream_F32::release(lblock); + transmit(lblock, 0); + release(lblock); in_update = false; };