From 493240126fd43808a2af28f88d772b9ede75c6db Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 23 Jul 2018 09:19:40 +0200 Subject: [PATCH] Fixed xrun calculation from fixed size to a size which is calculated from AUDIO_BLOCK_SAMPLES. Hint in config.h with a location where to change AUDIO_BLOCK_SAMPLES from 128 to 64 to get better latency. --- MicroDexed.ino | 10 +++++++--- config.h | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 8eec052..e291f02 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -168,7 +168,10 @@ void setup() #endif Serial.print(F("AUDIO_BLOCK_SAMPLES=")); - Serial.println(AUDIO_BLOCK_SAMPLES); + Serial.print(AUDIO_BLOCK_SAMPLES); + Serial.print(F(" (Time per block=")); + Serial.print(1000000/(SAMPLE_RATE/AUDIO_BLOCK_SAMPLES)); + Serial.println(F("ms)")); #ifdef TEST_NOTE Serial.println(F("MIDI test enabled")); @@ -200,7 +203,8 @@ void setup() void loop() { int16_t* audio_buffer; // pointer to 128 * int16_t (=256 bytes!) - + const uint16_t audio_block_time_ms=1000000/(SAMPLE_RATE/AUDIO_BLOCK_SAMPLES); + while (42 == 42) // DON'T PANIC! { #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) @@ -225,7 +229,7 @@ void loop() elapsedMicros t1; dexed->getSamples(AUDIO_BLOCK_SAMPLES, audio_buffer); uint32_t t2 = t1; - if (t2 > 2900) // everything greater 2.9ms is a buffer underrun! + if (t2 > audio_block_time_ms) // everything greater 2.9ms is a buffer underrun! xrun++; if (t2 > render_time_max) render_time_max = t2; diff --git a/config.h b/config.h index 6ec4520..aba5c18 100644 --- a/config.h +++ b/config.h @@ -25,6 +25,9 @@ #include "midinotes.h" +// ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from +// 128 to 64 in /cores/teensy3/AudioStream.h + // Initial values #define MIDI_DEVICE Serial1 #define USE_ONBOARD_USB_HOST 1