From 9a2cb85bf6b96d73fa72e931302db312c8a8be2a Mon Sep 17 00:00:00 2001 From: Dirk Niggemann Date: Fri, 25 Oct 2019 10:44:58 +0100 Subject: [PATCH 1/3] Reorder config.h inclusion --- MicroDexed.ino | 2 +- config.h | 1 + dexed.cpp | 2 +- dexed_sysex.cpp | 2 +- effect_modulated_delay.cpp | 2 +- fm_op_kernel.cpp | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 99b767b..d3c5ef3 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -22,8 +22,8 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "config.h" #include +#include "config.h" #include #include #include diff --git a/config.h b/config.h index c42f371..224070c 100644 --- a/config.h +++ b/config.h @@ -26,6 +26,7 @@ #ifndef CONFIG_H_INCLUDED #define CONFIG_H_INCLUDED +#include #include "midinotes.h" // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from diff --git a/dexed.cpp b/dexed.cpp index b12eb77..31617af 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -23,9 +23,9 @@ */ +#include "config.h" #include "synth.h" #include "dexed.h" -#include "config.h" #include "EngineMkI.h" #include "EngineOpl.h" #include "fm_core.h" diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index 126af77..daeccd2 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -24,12 +24,12 @@ */ #include +#include "config.h" #include #include #include #include "dexed.h" #include "dexed_sysex.h" -#include "config.h" extern Dexed* MicroDexed[NUM_DEXED]; diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index d9a1f99..afb3697 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -22,10 +22,10 @@ */ #include +#include "config.h" #include #include "arm_math.h" #include "effect_modulated_delay.h" -#include "config.h" extern config_t configuration; diff --git a/fm_op_kernel.cpp b/fm_op_kernel.cpp index d3bd0cf..f730d63 100644 --- a/fm_op_kernel.cpp +++ b/fm_op_kernel.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "config.h" #include #include @@ -25,7 +26,6 @@ #include "synth.h" #include "sin.h" #include "fm_op_kernel.h" -#include "config.h" #ifdef HAVE_NEON static bool hasNeon() { From ee70a84fcb0642652494760bb80bc8855c1a0344 Mon Sep 17 00:00:00 2001 From: Dirk Niggemann Date: Sat, 26 Oct 2019 23:10:10 +0100 Subject: [PATCH 2/3] Added Dexed audio source --- MicroDexed.ino | 57 ++++++++++++++++++++++++++++----------------- dexed_sysex.cpp | 2 +- dexed_sysex.h | 4 +++- source_microdexed.h | 39 +++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 source_microdexed.h diff --git a/MicroDexed.ino b/MicroDexed.ino index 178545e..3453404 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -39,9 +39,13 @@ #include "PluginFx.h" #include "SoftenValue.hpp" #include "UI.hpp" +#include "source_microdexed.h" -AudioPlayQueue queue1; AudioAnalyzePeak peak1; + +AudioSourceMicroDexed microdexed1; +//AudioPlayQueue queue1; + AudioEffectDelay delay1; AudioEffectModulatedDelay modchorus; AudioSynthWaveform modulator; @@ -54,11 +58,11 @@ AudioAmplifier volume_l; AudioOutputUSB usb1; #endif AudioEffectStereoMono stereomono1; -AudioConnection patchCord0(queue1, peak1); -AudioConnection patchCord1(queue1, 0, delay_fb_mixer, 0); -AudioConnection patchCord2(queue1, 0, modchorus, 0); -AudioConnection patchCord3(queue1, 0 , master_mixer_r, 0); -AudioConnection patchCord4(queue1, 0 , master_mixer_l, 0); +AudioConnection patchCord0(microdexed1, peak1); +AudioConnection patchCord1(microdexed1, 0, delay_fb_mixer, 0); +AudioConnection patchCord2(microdexed1, 0, modchorus, 0); +AudioConnection patchCord3(microdexed1, 0 , master_mixer_r, 0); +AudioConnection patchCord4(microdexed1, 0 , master_mixer_l, 0); AudioConnection patchCord5(modulator, 0, modchorus, 1); #if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT AudioFilterBiquad modchorus_filter; @@ -71,8 +75,8 @@ AudioConnection patchCord10(modchorus, 0, master_mixer_l, 3); #endif #if defined(USE_REVERB) AudioEffectFreeverbStereo freeverbs1; -AudioConnection patchCord11(queue1, 0, freeverbs1, 0); -AudioConnection patchCord12(queue1, 0, freeverbs1, 1); +AudioConnection patchCord11(microdexed1, 0, freeverbs1, 0); +AudioConnection patchCord12(microdexed1, 0, freeverbs1, 1); AudioConnection patchCord13(freeverbs1, 0, master_mixer_r, 1); AudioConnection patchCord14(freeverbs1, 1, master_mixer_l, 1); #endif @@ -122,10 +126,7 @@ AudioConnection patchCord37(stereomono1, 1, dacOut, 1); Dexed* MicroDexed[NUM_DEXED]; bool sd_card_available = false; -uint32_t xrun = 0; -uint32_t overload = 0; -uint32_t peak = 0; -uint16_t render_time_max = 0; + uint8_t max_loaded_banks = 0; char bank_name[BANK_NAME_LEN]; char voice_name[VOICE_NAME_LEN]; @@ -139,12 +140,15 @@ elapsedMillis long_button_pressed; SoftenValue soften_volume; SoftenValue soften_filter_res[NUM_DEXED]; SoftenValue soften_filter_cut[NUM_DEXED]; -elapsedMicros fill_audio_buffer; +//elapsedMicros fill_audio_buffer; elapsedMillis control_rate; uint8_t active_voices = 0; #ifdef SHOW_CPU_LOAD_MSEC elapsedMillis cpu_mem_millis; #endif +uint32_t overload = 0; +uint32_t peak = 0; + config_t configuration; bool eeprom_update_flag = false; @@ -152,6 +156,7 @@ bool eeprom_update_flag = false; // Allocate the delay lines for left and right channels short delayline[MOD_DELAY_SAMPLE_BUFFER]; + #ifdef ENABLE_LCD_UI /*********************************************************************** LCDMenuLib2 @@ -188,8 +193,9 @@ void setup() Serial.print(F("Creating MicroDexed engine ")); Serial.println(i, DEC); MicroDexed[i] = new Dexed(SAMPLE_RATE); + } - + microdexed1.setDexeds(NUM_DEXED, MicroDexed); delay(220); Serial.println(F("MicroDexed based on https://github.com/asb2m10/dexed")); @@ -394,11 +400,14 @@ void setup() void loop() { +#ifdef OLD int16_t* audio_buffer; // pointer to AUDIO_BLOCK_SAMPLES * int16_t const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); +#endif - while (42 == 42) - { + //while (42 == 42) + //{ +#ifdef OLD // Main sound calculation if (queue1.available() && fill_audio_buffer > audio_block_time_us - 10) { @@ -422,6 +431,7 @@ void loop() } queue1.playBuffer(); } +#endif // EEPROM update handling if (autostore >= AUTOSTORE_MS && active_voices == 0 && eeprom_update_flag == true) @@ -504,11 +514,16 @@ void loop() #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) if (cpu_mem_millis >= SHOW_CPU_LOAD_MSEC) { + if (peak1.available()) + { + if (peak1.read() > 0.99) + peak++; + } cpu_mem_millis -= SHOW_CPU_LOAD_MSEC; show_cpu_and_mem_usage(); } #endif - } + //} } /****************************************************************************** @@ -526,7 +541,7 @@ void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity) { if (checkMidiChannel(inChannel)) { - MicroDexed[0]->keyup(inNumber); + MicroDexed[0]->keyup(inNumber); } } @@ -1139,9 +1154,9 @@ void show_cpu_and_mem_usage(void) Serial.print(F(" MEM MAX: ")); Serial.print(AudioMemoryUsageMax(), DEC); Serial.print(F(" RENDER_TIME_MAX: ")); - Serial.print(render_time_max, DEC); + Serial.print(microdexed1.render_time_max, DEC); Serial.print(F(" XRUN: ")); - Serial.print(xrun, DEC); + Serial.print(microdexed1.xrun, DEC); Serial.print(F(" OVERLOAD: ")); Serial.print(overload, DEC); Serial.print(F(" PEAK: ")); @@ -1153,7 +1168,7 @@ void show_cpu_and_mem_usage(void) Serial.println(); AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); - render_time_max = 0; + microdexed1.render_time_max = 0; } #endif diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index daeccd2..010e79f 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -349,7 +349,7 @@ bool get_sysex_voice(File sysex, uint8_t voice_number, uint8_t* data) return (false); } - render_time_max = 0; + microdexed1.render_time_max = 0; return (true); } diff --git a/dexed_sysex.h b/dexed_sysex.h index e26bea1..88f0d1d 100644 --- a/dexed_sysex.h +++ b/dexed_sysex.h @@ -24,13 +24,15 @@ */ #include "config.h" +#include "source_microdexed.h" #ifndef DEXED_SYSEX_H_INCLUDED #define DEXED_SYSEX_H_INCLUDED extern bool sd_card_available; extern Dexed* dexed; -extern uint16_t render_time_max; +extern AudioSourceMicroDexed microdexed1; +//extern uint16_t render_time_max; extern uint8_t bank; extern uint8_t voice; extern char bank_name[BANK_NAME_LEN]; diff --git a/source_microdexed.h b/source_microdexed.h new file mode 100644 index 0000000..3bd5615 --- /dev/null +++ b/source_microdexed.h @@ -0,0 +1,39 @@ +#pragma once +#include "config.h" +#include "dexed.h" + +#include + +class AudioSourceMicroDexed : public AudioStream { + public: + const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); + uint32_t xrun = 0; + uint16_t render_time_max = 0; + AudioAnalyzePeak * peak1 =NULL; + int num_dexeds = 0; + Dexed ** dexeds = NULL; + AudioSourceMicroDexed() : AudioStream(0, NULL) { + }; + void setDexeds(int num, Dexed ** pdexed) { + dexeds = pdexed; + num_dexeds = num; + } + void update(void) { + elapsedMicros render_time; + audio_block_t *lblock; + lblock = allocate(); + if (!lblock) return; + for (uint8_t i = 0; i < num_dexeds; i++) + { + dexeds[i]->getSamples(AUDIO_BLOCK_SAMPLES, lblock->data); + } + if (render_time > audio_block_time_us) // everything greater 2.9ms is a buffer underrun! + xrun++; + if (render_time > render_time_max) + render_time_max = render_time; + + transmit(lblock, 0); + release(lblock); + }; +private: +}; From a3f9b646dec2d59b963157e6e85754ef84088d87 Mon Sep 17 00:00:00 2001 From: Dirk Niggemann Date: Sun, 27 Oct 2019 00:44:31 +0100 Subject: [PATCH 3/3] Now Dexed is a parent class of AudioSourceMicroDexed --- MicroDexed.ino | 43 ++++++++++++++++++++++++++----------------- UI.hpp | 2 +- dexed.h | 3 ++- dexed_sysex.cpp | 4 ++-- dexed_sysex.h | 2 +- source_microdexed.h | 16 +++------------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 3453404..95289a0 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -43,9 +43,10 @@ AudioAnalyzePeak peak1; -AudioSourceMicroDexed microdexed1; //AudioPlayQueue queue1; +AudioSourceMicroDexed* MicroDexed[NUM_DEXED]; + AudioEffectDelay delay1; AudioEffectModulatedDelay modchorus; AudioSynthWaveform modulator; @@ -58,11 +59,6 @@ AudioAmplifier volume_l; AudioOutputUSB usb1; #endif AudioEffectStereoMono stereomono1; -AudioConnection patchCord0(microdexed1, peak1); -AudioConnection patchCord1(microdexed1, 0, delay_fb_mixer, 0); -AudioConnection patchCord2(microdexed1, 0, modchorus, 0); -AudioConnection patchCord3(microdexed1, 0 , master_mixer_r, 0); -AudioConnection patchCord4(microdexed1, 0 , master_mixer_l, 0); AudioConnection patchCord5(modulator, 0, modchorus, 1); #if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT AudioFilterBiquad modchorus_filter; @@ -75,8 +71,6 @@ AudioConnection patchCord10(modchorus, 0, master_mixer_l, 3); #endif #if defined(USE_REVERB) AudioEffectFreeverbStereo freeverbs1; -AudioConnection patchCord11(microdexed1, 0, freeverbs1, 0); -AudioConnection patchCord12(microdexed1, 0, freeverbs1, 1); AudioConnection patchCord13(freeverbs1, 0, master_mixer_r, 1); AudioConnection patchCord14(freeverbs1, 1, master_mixer_l, 1); #endif @@ -123,7 +117,22 @@ AudioConnection patchCord36(stereomono1, 0, dacOut, 0); AudioConnection patchCord37(stereomono1, 1, dacOut, 1); #endif -Dexed* MicroDexed[NUM_DEXED]; +//Dexed* MicroDexed[NUM_DEXED]; +AudioConnection * dynamicConnections[NUM_DEXED * 7]; +int nDynamic = 0; + +void create_audio_connections(AudioSourceMicroDexed &d) +{ + dynamicConnections[nDynamic++] = new AudioConnection(d, peak1); + dynamicConnections[nDynamic++] = new AudioConnection(d, 0, delay_fb_mixer, 0); + dynamicConnections[nDynamic++] = new AudioConnection(d, 0, modchorus, 0); + dynamicConnections[nDynamic++] = new AudioConnection(d, 0 , master_mixer_r, 0); + dynamicConnections[nDynamic++] = new AudioConnection(d, 0 , master_mixer_l, 0); +#if defined(USE_REVERB) + dynamicConnections[nDynamic++] = new AudioConnection(d, 0, freeverbs1, 0); + dynamicConnections[nDynamic++] = new AudioConnection(d, 0, freeverbs1, 1); +#endif +} bool sd_card_available = false; @@ -146,7 +155,7 @@ uint8_t active_voices = 0; #ifdef SHOW_CPU_LOAD_MSEC elapsedMillis cpu_mem_millis; #endif -uint32_t overload = 0; +//uint32_t overload = 0; uint32_t peak = 0; config_t configuration; @@ -192,10 +201,10 @@ void setup() { Serial.print(F("Creating MicroDexed engine ")); Serial.println(i, DEC); - MicroDexed[i] = new Dexed(SAMPLE_RATE); - + MicroDexed[i] = new AudioSourceMicroDexed(SAMPLE_RATE); + create_audio_connections(*MicroDexed[i]); } - microdexed1.setDexeds(NUM_DEXED, MicroDexed); + //microdexed1.setDexeds(NUM_DEXED, MicroDexed); delay(220); Serial.println(F("MicroDexed based on https://github.com/asb2m10/dexed")); @@ -1154,11 +1163,11 @@ void show_cpu_and_mem_usage(void) Serial.print(F(" MEM MAX: ")); Serial.print(AudioMemoryUsageMax(), DEC); Serial.print(F(" RENDER_TIME_MAX: ")); - Serial.print(microdexed1.render_time_max, DEC); + Serial.print(MicroDexed[0]->render_time_max, DEC); Serial.print(F(" XRUN: ")); - Serial.print(microdexed1.xrun, DEC); + Serial.print(MicroDexed[0]->xrun, DEC); Serial.print(F(" OVERLOAD: ")); - Serial.print(overload, DEC); + Serial.print(MicroDexed[0]->overload, DEC); Serial.print(F(" PEAK: ")); Serial.print(peak, DEC); Serial.print(F(" BLOCKSIZE: ")); @@ -1168,7 +1177,7 @@ void show_cpu_and_mem_usage(void) Serial.println(); AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); - microdexed1.render_time_max = 0; + MicroDexed[0]->render_time_max = 0; } #endif diff --git a/UI.hpp b/UI.hpp index a56673c..db5be9d 100644 --- a/UI.hpp +++ b/UI.hpp @@ -74,7 +74,7 @@ extern AudioMixer4 master_mixer_l; extern AudioAmplifier volume_r; extern AudioAmplifier volume_l; extern AudioEffectStereoMono stereomono1; -extern Dexed* MicroDexed[NUM_DEXED]; +extern AudioSourceMicroDexed * MicroDexed[NUM_DEXED]; /*********************************************************************** GLOBAL diff --git a/dexed.h b/dexed.h index a3bdaf0..24f69fb 100644 --- a/dexed.h +++ b/dexed.h @@ -38,7 +38,7 @@ #include #include "config.h" -extern uint32_t overload; +//extern uint32_t overload; extern bool load_sysex(uint8_t bank, uint8_t voice_number); extern AudioControlSGTL5000 sgtl5000_1; extern float vol; @@ -187,6 +187,7 @@ class Dexed 16 // number of voices }; // FM-Piano + uint32_t overload = 0; protected: static const uint8_t MAX_ACTIVE_NOTES = MAX_NOTES; uint8_t max_notes = MAX_ACTIVE_NOTES; diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index 010e79f..109d718 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -31,7 +31,7 @@ #include "dexed.h" #include "dexed_sysex.h" -extern Dexed* MicroDexed[NUM_DEXED]; +extern AudioSourceMicroDexed * MicroDexed[NUM_DEXED]; void create_sysex_filename(uint8_t b, char* sysex_file_name) { @@ -349,7 +349,7 @@ bool get_sysex_voice(File sysex, uint8_t voice_number, uint8_t* data) return (false); } - microdexed1.render_time_max = 0; + MicroDexed[0]->render_time_max = 0; return (true); } diff --git a/dexed_sysex.h b/dexed_sysex.h index 88f0d1d..8900008 100644 --- a/dexed_sysex.h +++ b/dexed_sysex.h @@ -31,7 +31,7 @@ extern bool sd_card_available; extern Dexed* dexed; -extern AudioSourceMicroDexed microdexed1; +extern AudioSourceMicroDexed * MicroDexed[NUM_DEXED]; //extern uint16_t render_time_max; extern uint8_t bank; extern uint8_t voice; diff --git a/source_microdexed.h b/source_microdexed.h index 3bd5615..bcd6b81 100644 --- a/source_microdexed.h +++ b/source_microdexed.h @@ -4,29 +4,19 @@ #include -class AudioSourceMicroDexed : public AudioStream { +class AudioSourceMicroDexed : 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; - AudioAnalyzePeak * peak1 =NULL; - int num_dexeds = 0; - Dexed ** dexeds = NULL; - AudioSourceMicroDexed() : AudioStream(0, NULL) { + AudioSourceMicroDexed(int sample_rate) : AudioStream(0, NULL), Dexed(sample_rate) { }; - void setDexeds(int num, Dexed ** pdexed) { - dexeds = pdexed; - num_dexeds = num; - } void update(void) { elapsedMicros render_time; audio_block_t *lblock; lblock = allocate(); if (!lblock) return; - for (uint8_t i = 0; i < num_dexeds; i++) - { - dexeds[i]->getSamples(AUDIO_BLOCK_SAMPLES, lblock->data); - } + getSamples(AUDIO_BLOCK_SAMPLES, lblock->data); if (render_time > audio_block_time_us) // everything greater 2.9ms is a buffer underrun! xrun++; if (render_time > render_time_max)