PaulStoffregen / Audio

Teensy Audio Library
http://www.pjrc.com/teensy/td_libs_Audio.html
1.08k stars 401 forks source link

AudioRecordQueue behaves incorrectly with no input #403

Open h4yn0nnym0u5e opened 3 years ago

h4yn0nnym0u5e commented 3 years ago

Description

As in title, and discussed at https://forum.pjrc.com/threads/68000-AudioRecordQueue-behaves-incorrectly-with-no-input

The Audio library design rules state that a NULL received audio block (from receiveReadOnly()) should be treated as if a silent block had been received. AudioRecordQueue does not do this, but simply fails to count or queue the NULL, even when it has been enabled by queue.begin().

Steps To Reproduce Problem

Create any audio topology which uses AudioRecordQueue, where the input to the queue can be NULL audio blocks: a good candidate is AudioPlaySdWav. Without calling AudioPlaySdWav::begin(), call AudioRecordQueue::begin() and observe that AudioRecordQueue::available() never reports available (silent) data.

Hardware & Software

Teensy 4.1 Audio module Arduino IDE version 1.8.15 Teensyduino version 1.54 Operating system & version not relevant

Arduino Sketch

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveform       waveform1;      //xy=374,336
AudioOutputI2S           i2s;           //xy=566,356
AudioRecordQueue         queue1;         //xy=567,313
AudioConnection          patchCord1(waveform1, 0, i2s, 0);
AudioConnection          patchCord2(waveform1, queue1);
AudioControlSGTL5000     sgtl5000_1;     //xy=558,398
// GUItool: end automatically generated code

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;
  AudioMemory(10);
}

void loop() {
  int n = 5;

  queue1.begin(); // start monitoring
  delay(10);      // should get a few silent blocks
  waveform1.begin(0.5f,261.0f,WAVEFORM_SINE);

  while (n>0)
  {
    if (queue1.available())
    {
      int16_t* qd = queue1.readBuffer();

      for (int i=0;i<128;i++)
        Serial.println(qd[i]);

      queue1.freeBuffer();
      n--;
    }
  }
  while (1)
    ;

}

Errors or Incorrect Output

image

should look like

image