Correction for testMode==1 - Thanks Jonathan

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

@ -12,6 +12,8 @@
*
* Jonathan Oakley, November 2021
* 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"
@ -52,8 +54,8 @@ void setup() {
// 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,
// or no room in queue for another audio block.
queue1.setBehaviour(AudioPlayQueue_F32::NON_STALLING);
//queue1.setBehaviour(AudioPlayQueue_F32::ORIGINAL);
queue1.setBehaviour(AudioPlayQueue_F32::NON_STALLING); // <=== Set
// queue1.setBehaviour(AudioPlayQueue_F32::ORIGINAL); // or this
queue1.setMaxBuffers(4);
}
@ -78,10 +80,12 @@ float32_t nextSample()
int loops;
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
float32_t samples[512],*sptr; // space for samples when using play()
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() {
@ -89,16 +93,23 @@ void loop() {
{
case 1: // use getBuffer / playBuffer
{
float32_t* buf = queue1.getBuffer();
if (NULL == buf)
nulls++;
if (0 != noQueueSpace)
noQueueSpace = queue1.playBuffer();
else
{
for (int i=0;i<AUDIO_BLOCK_SAMPLES;i++)
buf[i] = nextSample();
queue1.playBuffer();
float32_t* buf = queue1.getBuffer();
if (NULL == buf)
nulls++;
else
{
for (int i=0; i<AUDIO_BLOCK_SAMPLES; i++)
buf[i] = nextSample();
noQueueSpace = queue1.playBuffer();
}
}
if (noQueueSpace)
noQcount++;
}
break;
@ -166,7 +177,7 @@ void loop() {
// 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
// stall results in slightly unpredictable timestamps.
Serial.printf("%d: millis = %d, loops = %d, nulls = %u, nulls2 = %u, samples = %u\n",
playMode,millis(),loops,nulls,nulls2,genLen);
Serial.printf("%d: millis = %d, loops = %d, nulls = %u, nulls2 = %u, samples = %u, wait count = %d\n",
playMode, millis(),loops, nulls, nulls2, genLen, noQcount);
}
}

Loading…
Cancel
Save