Correction for testMode==1 - Thanks Jonathan

master
boblark 1 year ago
parent 48db1010c4
commit 330959b30d
  1. 35
      examples/PlayQueueDemo/PlayQueueDemo.ino

@ -12,6 +12,8 @@
* *
* Jonathan Oakley, November 2021 * Jonathan Oakley, November 2021
* Converted from I16 to F32 - Bob Larkin Feb 2023. Thanks, Jonathan * Converted from I16 to F32 - Bob Larkin Feb 2023. Thanks, Jonathan
* 18 Mar 2023: Includes corrections to testMode==1, NON-STALLING from
* https://github.com/h4yn0nnym0u5e/Audio/commit/9fce95edb634891ce6d28288e87f54f4994096e8
*/ */
#include "OpenAudio_ArduinoLibrary.h" #include "OpenAudio_ArduinoLibrary.h"
@ -52,8 +54,8 @@ void setup() {
// Comment the following out (or set to ORIGINAL) for old stall behaviour; // Comment the following out (or set to ORIGINAL) for old stall behaviour;
// set to NON_STALLING for return with status if audio blocks not available, // set to NON_STALLING for return with status if audio blocks not available,
// or no room in queue for another audio block. // or no room in queue for another audio block.
queue1.setBehaviour(AudioPlayQueue_F32::NON_STALLING); queue1.setBehaviour(AudioPlayQueue_F32::NON_STALLING); // <=== Set
//queue1.setBehaviour(AudioPlayQueue_F32::ORIGINAL); // queue1.setBehaviour(AudioPlayQueue_F32::ORIGINAL); // or this
queue1.setMaxBuffers(4); queue1.setMaxBuffers(4);
} }
@ -78,10 +80,12 @@ float32_t nextSample()
int loops; int loops;
int nulls,nulls2; int nulls,nulls2;
int testMode = 2; // 1: getBuffer / playBuffer; 2: play(), mix of samples and buffers int testMode = 2; // 1: getBuffer / playBuffer; 2: play(), mix of samples and buffers <<<SET
int playMode; // 1: generate individual samples and send; 2: generate buffer of samples and send int playMode; // 1: generate individual samples and send; 2: generate buffer of samples and send
float32_t samples[512],*sptr; // space for samples when using play() float32_t samples[512],*sptr; // space for samples when using play()
uint32_t len; // number of buffered samples (remaining) uint32_t len; // number of buffered samples (remaining)
int noQueueSpace; // did call to AudioPlayQueue::playBuffer() fail? If so, re-try
int noQcount; // count of times we had to wait to queue a block
void loop() { void loop() {
@ -89,16 +93,23 @@ void loop() {
{ {
case 1: // use getBuffer / playBuffer case 1: // use getBuffer / playBuffer
{ {
float32_t* buf = queue1.getBuffer(); if (0 != noQueueSpace)
noQueueSpace = queue1.playBuffer();
if (NULL == buf)
nulls++;
else else
{ {
for (int i=0;i<AUDIO_BLOCK_SAMPLES;i++) float32_t* buf = queue1.getBuffer();
buf[i] = nextSample();
queue1.playBuffer(); if (NULL == buf)
nulls++;
else
{
for (int i=0; i<AUDIO_BLOCK_SAMPLES; i++)
buf[i] = nextSample();
noQueueSpace = queue1.playBuffer();
}
} }
if (noQueueSpace)
noQcount++;
} }
break; break;
@ -166,7 +177,7 @@ void loop() {
// In NON_STALLING mode this loops really fast, and the millis() value goes up by // In NON_STALLING mode this loops really fast, and the millis() value goes up by
// 100 on every output line. In ORIGINAL mode the loop is slow, and the internal // 100 on every output line. In ORIGINAL mode the loop is slow, and the internal
// stall results in slightly unpredictable timestamps. // stall results in slightly unpredictable timestamps.
Serial.printf("%d: millis = %d, loops = %d, nulls = %u, nulls2 = %u, samples = %u\n", Serial.printf("%d: millis = %d, loops = %d, nulls = %u, nulls2 = %u, samples = %u, wait count = %d\n",
playMode,millis(),loops,nulls,nulls2,genLen); playMode, millis(),loops, nulls, nulls2, genLen, noQcount);
} }
} }

Loading…
Cancel
Save