From fcf70e3392f5f0e1f24f535ca32bfabe4206654f Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 5 Jul 2021 14:01:49 +0200 Subject: [PATCH] Added global midi_bpm and synced delay (to midi_bpm). --- MicroDexed.ino | 95 ++++++++++++++++++++++++++------------------------ config.h | 16 +++++---- synth_dexed.h | 1 - 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 14b0445..ccdbea6 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -220,13 +220,12 @@ void create_audio_engine_chain(uint8_t instance_id) uint8_t sd_card = 0; Sd2Card card; SdVolume volume; -uint8_t midi_ticks[10] = {0, 6, 9, 12, 18, 24, 36, 48, 72, 96}; +float midi_ticks_factor[10] = {0.0, 0.0625, 0.09375, 0.125, 0.1875, 0.25, 0.375, 0.5, 0.75 , 1.0}; uint8_t midi_bpm_counter = 0; -elapsedMillis midi_bpm; -#ifdef USE_FX -uint8_t midi_timing_counter[NUM_DEXED] = {0, 0}; -elapsedMillis midi_timing_timer[NUM_DEXED]; -#endif +uint8_t midi_bpm = 0; +int16_t _midi_bpm = -1; +bool midi_clock_running = false; +elapsedMillis midi_bpm_timer; elapsedMillis long_button_pressed; elapsedMillis control_rate; uint8_t active_voices[NUM_DEXED]; @@ -1374,71 +1373,75 @@ void handleTuneRequest(void) void handleClock(void) { -#ifdef DEBUG + if (midi_clock_running != true) + return; + if (midi_bpm_counter % 24 == 0) { - Serial.print(F("MIDI Clock: ")); - Serial.print(60000.0f / midi_bpm, 2); - Serial.print(F("bpm (")); - Serial.print(midi_bpm, DEC); - Serial.println(F("ms per quarter)")); - midi_bpm = 0; - midi_bpm_counter = 0; - } - midi_bpm_counter++; + midi_bpm = (60000.0f / float(midi_bpm_timer) + 0.5); + + if (_midi_bpm > -1 && _midi_bpm != midi_bpm) + { +#ifdef DEBUG + Serial.print(F("MIDI Clock: ")); + Serial.print(midi_bpm); + Serial.print(F(" bpm (")); + Serial.print(midi_bpm_timer, DEC); + Serial.println(F("ms per quarter)")); #endif #ifdef USE_FX - for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) - { - if (midi_ticks[configuration.fx.delay_sync[instance_id]] > 0) - { /* - 1 1/16 = 6 ticks - 2 1/16T = 9 ticks - 3 1/8 = 12 ticks - 4 1/8T = 18 ticks - 5 1/4 = 24 ticks - 6 1/4T = 36 ticks - 7 1/2 = 48 ticks - 8 1/2T = 72 ticks - 9 1/1 = 96 ticks + 1 1/16 = 6 ticks / 0.0625 + 2 1/16T = 9 ticks / 0.09375 + 3 1/8 = 12 ticks / 0.125 + 4 1/8T = 18 ticks / 0.1875 + 5 1/4 = 24 ticks / 0.25 + 6 1/4T = 36 ticks / 0.375 + 7 1/2 = 48 ticks / 0.5 + 8 1/2T = 72 ticks / 0.75 + 9 1/1 = 96 ticks / 1.0 */ - if (midi_timing_counter[instance_id] % midi_ticks[configuration.fx.delay_sync[instance_id]] == 0) + for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { - int32_t t = midi_timing_timer[instance_id]; - delay_fx[instance_id]->delay(0, constrain(t*10, DELAY_TIME_MIN*10, DELAY_TIME_MAX*10)); + if (configuration.fx.delay_sync[instance_id] > 0) + { + uint16_t t = uint16_t(60.0 / float(midi_bpm) * 1000.0 * midi_ticks_factor[configuration.fx.delay_sync[instance_id]] + 0.5); + delay_fx[instance_id]->delay(0, constrain(t, DELAY_TIME_MIN * 10, DELAY_TIME_MAX * 10)); #ifdef DEBUG - Serial.print(F("Delay-Sync to ")); - Serial.print(constrain(t, DELAY_TIME_MIN, DELAY_TIME_MAX), DEC); - Serial.print(F(" ms / ")); - Serial.print(midi_timing_counter[instance_id], DEC); - Serial.println(F(" ticks")); + Serial.print(F("Setting Delay-Sync to ")); + Serial.print(constrain(t, DELAY_TIME_MIN * 10, DELAY_TIME_MAX * 10), DEC); + Serial.println(F(" ms")); #endif - midi_timing_counter[instance_id] = 0; - midi_timing_timer[instance_id] = 0; + } } - midi_timing_counter[instance_id]++; +#endif } + + _midi_bpm = midi_bpm; + midi_bpm_counter = 0; + midi_bpm_timer = 0; } -#else - ; -#endif + + midi_bpm_counter++; } void handleStart(void) { - ; + midi_clock_running = true; + midi_bpm_timer = 0; + midi_bpm_counter = 0; + _midi_bpm = -1; } void handleContinue(void) { - ; + midi_clock_running = true; } void handleStop(void) { - ; + midi_clock_running = false; } void handleActiveSensing(void) diff --git a/config.h b/config.h index 98b91aa..3dade09 100644 --- a/config.h +++ b/config.h @@ -32,7 +32,7 @@ // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from // 128 to 64 in /cores/teensy3/AudioStream.h -// For this audio buffers (AUDIO_MEM) are doubled! +// For this you have manually change audio buffers (AUDIO_MEM) to the doubled value! // If you want to test the system with Linux and without any keyboard and/or audio equipment, you can do the following: // 1. In Arduino-IDE enable "Tools->USB-Type->Serial + MIDI + Audio" @@ -59,7 +59,7 @@ // sed -i.orig 's/^#define USB_MIDI_SYSEX_MAX 290/#define USB_MIDI_SYSEX_MAX 4104/' /usr/local/arduino-teensy/hardware/teensy/avr/cores/teensy4/usb_midi.h //#define USB_MIDI_SYSEX_MAX 4104 -#define VERSION "1.0.18" +#define VERSION "1.0.19" //************************************************************************************************* //* DEVICE SETTINGS @@ -131,8 +131,7 @@ //#if AUDIO_BLOCK_SAMPLES == 64 //#define AUDIO_MEM 256 //#else -#define AUDIO_MEM 128 -#define AUDIO_MEM_F32 10 +#define AUDIO_MEM 750 //#endif #ifdef TEENSY_AUDIO_BOARD @@ -164,17 +163,20 @@ #if defined(TEENSY3_6) #define DELAY_MAX_TIME 250 #elif defined(TEENSY4) -#define DELAY_MAX_TIME 750 +#define DELAY_MAX_TIME 500 #else #define DELAY_MAX_TIME 125 #endif #else #if defined(TEENSY3_6) #define DELAY_MAX_TIME 500 +#define AUDIO_MEM 360 #elif defined(TEENSY4) -#define DELAY_MAX_TIME 1500 +#define DELAY_MAX_TIME 1000 +#define AUDIO_MEM 750 #else #define DELAY_MAX_TIME 250 +#define AUDIO_MEM 200 #endif #endif @@ -420,7 +422,7 @@ #define DELAY_SYNC_MIN 0 #define DELAY_SYNC_MAX 9 -#define DELAY_SYNC_DEFAULT 7 +#define DELAY_SYNC_DEFAULT 0 #define REVERB_ROOMSIZE_MIN 0 #define REVERB_ROOMSIZE_MAX 100 diff --git a/synth_dexed.h b/synth_dexed.h index 2fd961f..9a56761 100644 --- a/synth_dexed.h +++ b/synth_dexed.h @@ -1,6 +1,5 @@ #include #include -#include #include "config.h" /*****************************************************