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.
pull/4/head
Holger Wirtz 6 years ago
parent b8015f455f
commit 493240126f
  1. 10
      MicroDexed.ino
  2. 3
      config.h

@ -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;

@ -25,6 +25,9 @@
#include "midinotes.h"
// ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from
// 128 to 64 in <ARDUINO-IDE-DIR>/cores/teensy3/AudioStream.h
// Initial values
#define MIDI_DEVICE Serial1
#define USE_ONBOARD_USB_HOST 1

Loading…
Cancel
Save