Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioRecordQueue behaves incorrectly with no input #403

Open
h4yn0nnym0u5e opened this issue Aug 22, 2021 · 0 comments
Open

AudioRecordQueue behaves incorrectly with no input #403

h4yn0nnym0u5e opened this issue Aug 22, 2021 · 0 comments

Comments

@h4yn0nnym0u5e
Copy link
Contributor

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

h4yn0nnym0u5e pushed a commit to h4yn0nnym0u5e/Audio that referenced this issue Aug 22, 2021
… with no input

record_queue.cpp - don't release() NULL or flag queue entries in ::clear(); allocate and blank a new audio block (if available) in ::readBuffer(), if we have a flag to say NULL (silence)  was received; also keep returning same block until it's discarded by calling ::freeBuffer(); put flag in queue if record is activated by ::begin() but receiving only NULL pointers
record_queue.h - define the "silent data" flag pointer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant