diff --git a/MicroDexed.ino b/MicroDexed.ino index 13e9de0..a79689c 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -119,6 +119,7 @@ uint8_t effect_delay_time = 0; uint8_t effect_delay_feedback = 0; uint8_t effect_delay_volume = 0; bool effect_delay_sync = 0; +elapsedMicros fill_audio_buffer; #ifdef MASTER_KEY_MIDI bool master_key_enabled = false; @@ -332,16 +333,18 @@ void setup() void loop() { int16_t* audio_buffer; // pointer to AUDIO_BLOCK_SAMPLES * int16_t - const uint16_t audio_block_time_ms = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); + const uint16_t audio_block_time_us = 1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES); // Main sound calculation - if (queue1.available()) + if (queue1.available() && fill_audio_buffer > audio_block_time_us - 10) { + fill_audio_buffer = 0; + audio_buffer = queue1.getBuffer(); elapsedMicros t1; dexed->getSamples(AUDIO_BLOCK_SAMPLES, audio_buffer); - if (t1 > audio_block_time_ms) // everything greater 2.9ms is a buffer underrun! + if (t1 > audio_block_time_us) // everything greater 2.9ms is a buffer underrun! xrun++; if (t1 > render_time_max) render_time_max = t1; @@ -366,6 +369,7 @@ void loop() // MIDI input handling handle_input(); + #ifdef I2C_DISPLAY // UI if (master_timer >= TIMER_UI_HANDLING_MS) @@ -654,6 +658,7 @@ bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) mixer2.gain(1, mapfloat(effect_delay_volume, 0, ENC_DELAY_VOLUME_STEPS, 0.0, 1.0)); // delay tap1 signal (with added feedback) break; default: + ret = dexed->processMidiMessage(type, data1, data2); break; } } diff --git a/UI.cpp b/UI.cpp index 5aa2abb..9c878f2 100644 --- a/UI.cpp +++ b/UI.cpp @@ -74,6 +74,7 @@ void handle_ui(void) #ifdef DEBUG Serial.print(F("Long button pressing detected for button ")); Serial.println(i, DEC); +#endif switch (i) { @@ -103,7 +104,6 @@ void handle_ui(void) } break; } -#endif } else { @@ -559,7 +559,7 @@ void ui_show_effects_delay(void) lcd.show(1, 8, 5, "Vol:"); } - lcd.show(0, 9, 4, map(effect_delay_time, 0, ENC_DELAY_TIME_STEPS, 0, 1200)); + lcd.show(0, 9, 4, map(effect_delay_time, 0, ENC_DELAY_TIME_STEPS, 0, DELAY_MAX_TIME)); lcd.show(1, 4, 2, map(effect_delay_feedback, 0, ENC_DELAY_FB_STEPS, 0, 99)); lcd.show(1, 13, 2, map(effect_delay_volume, 0, ENC_DELAY_VOLUME_STEPS, 0, 99)); diff --git a/config.h b/config.h index 3f6ebf0..dd2d6db 100644 --- a/config.h +++ b/config.h @@ -44,8 +44,10 @@ //#define DEXED_ENGINE DEXED_ENGINE_MODERN #ifndef TEENSY_AUDIO_BOARD #define AUDIO_MEM 450 +#define DELAY_MAX_TIME 600.0 #else #define AUDIO_MEM 900 +#define DELAY_MAX_TIME 1200.0 #endif #define SAMPLE_RATE 44100 #define MAX_BANKS 100 @@ -62,7 +64,6 @@ // EFFECTS #define FILTER_MAX_FREQ 10000 -#define DELAY_MAX_TIME 1200.0 // Master key handling (comment for disabling) //#define MASTER_KEY_MIDI MIDI_C7 @@ -70,7 +71,7 @@ // Debug output #define SERIAL_SPEED 38400 -#define DEBUG 1 +//#define DEBUG 1 #define SHOW_MIDI_EVENT 1 #define SHOW_XRUN 1 #define SHOW_CPU_LOAD_MSEC 5000 diff --git a/doc/MicroDexed_Latency.png b/doc/MicroDexed_Latency.png new file mode 100644 index 0000000..fc5301d Binary files /dev/null and b/doc/MicroDexed_Latency.png differ