Subfanatic
Member
When AudioPlayQueue.getBuffer() and AudioPlayQueue.playBuffer() are used in an audio rate ISR, they slowly consume AudioMemory buffers and T4.0 crashes when all buffers are used (default 80 for IMXRT1062). The same code works flawlessly on Teensy 3.6 for hours, on 4.0 it cracks up in ~570s. I tried everything I could to bypass this issue, but no luck so far.
Here's a code to test/reproduce this issue. I would be thankful if someone could run this on T4.0 and report back. If you reduce to AudioMemory(16) in Setup, it will freeze in ~100s.
Reports from Serial Monitor:
Teensy 4.0, no AudioPlayBuffer
Teensy 4.0, one AudioPlayBuffer
Teensy 4.0, two AudioPlayBuffers
Teensy 3.6, two AudioPlayBuffers
Thanks in advance for your kind answers!
Here's a code to test/reproduce this issue. I would be thankful if someone could run this on T4.0 and report back. If you reduce to AudioMemory(16) in Setup, it will freeze in ~100s.
Code:
#include <Audio.h>
#include <SerialFlash.h>
AudioPlayQueue audio;
AudioPlayQueue audio2;
AudioOutputI2S i2s1;
AudioConnection patchCord1(audio, 0, i2s1, 0);
AudioConnection patchCord2(audio2, 0, i2s1, 1);
uint8_t cycle=0;
elapsedMillis tme;
void audioISR() //dummy ISR routine to test getBuffer()/playBuffer()
{
if((cycle % 128) == 127){ //for 128 int16 array
int16_t *p1 = audio.getBuffer();
p1 = p1; // to avoid unused variable compiler warning
audio.playBuffer();
}
cycle++;
}
void setup()
{
AudioNoInterrupts();
noInterrupts();
AudioMemory(512);
Serial.begin(9600);
IntervalTimer *t1 = new IntervalTimer();
t1->begin(audioISR, 1000000.0f / 44100.0f);
interrupts();
AudioInterrupts();
}
void loop()
{
if (tme>10000)
{
tme=0;
Serial.printf("Run time: %i s \n", (millis()/1000));
Serial.printf("CPU: %.2f (%.2f), MEM: %i (%i)\n",
AudioProcessorUsage(), AudioProcessorUsageMax(),
AudioMemoryUsage(), AudioMemoryUsageMax());
AudioProcessorUsageMaxReset();
AudioMemoryUsageMaxReset();
}
}
Reports from Serial Monitor:
Teensy 4.0, no AudioPlayBuffer
Run time: 10s
CPU: 0.51 (0.54), MEM: 2 (2)
Run time: 200s
CPU: 0.51 (0.54), MEM: 2 (2)
Run time: 2340s
CPU: 0.51 (0.54), MEM: 2 (2)
Teensy 4.0, one AudioPlayBuffer
Run time: 10s
CPU: 0.52 (0.57), MEM: 3 (4)
Run time: 20s
CPU: 0.52 (0.56), MEM: 4 (5)
Run time: 30s
CPU: 0.52 (0.57), MEM: 6 (7)
Run time: 200s
CPU: 0.52 (0.57), MEM: 29 (30)
Run time: 560s
CPU: 0.52 (0.57), MEM: 79 (80)
Run time: 570s
CPU: 0.52 (0.57), MEM: 80 (81)
======= CRASH =======
Teensy 4.0, two AudioPlayBuffers
Run time: 10s
CPU: 0.52 (0.55), MEM: 4 (6)
Run time: 20s
CPU: 0.52 (0.55), MEM: 6 (8)
Run time: 30s
CPU: 0.52 (0.55), MEM: 10 (12)
Run time: 200s
CPU: 0.52 (0.55), MEM: 56 (58)
Run time: 560s
CPU: 0.52 (0.56), MEM: 156 (158)
Run time: 570s
CPU: 0.52 (0.56), MEM: 158 (160)
======= CRASH =======
Teensy 3.6, two AudioPlayBuffers
Run time: 10s
CPU: 0.89 (0.96), MEM: 4 (4)
Run time: 200s
CPU: 0.89 (0.97), MEM: 2 (4)
Run time: 2340s
CPU: 0.89 (0.95), MEM: 2 (4)
Thanks in advance for your kind answers!