Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Audio Library Synth Generator to AudioRecordQueue, Teensy 4.0 w/ Audio Shield

  1. #1
    Junior Member
    Join Date
    Dec 2019

    Audio Library Synth Generator to AudioRecordQueue, Teensy 4.0 w/ Audio Shield

    Hi all,

    For a school project I'm working on, I need to be able to generate a waveform with the Teensy 4.0 and copy to AudioRecordQueue to do some manipulations of the array before outputting sound (white noise, sine, etc., it doesn't matter at this point what type).
    I've had success in the past using AudioRecordQueue with mic inputs (i2s input). I'd like to do the same thing, but I'm not getting results as I would expect.

    My code is below. I'm just generating white noise, sending it to an AudioRecordQueue object, copying the values from the record queue object to the play queue object, and repeating.

    What I get is maybe 200ms of noise and then silence. I also added in some Serial.print lines to debug where it's hanging up, but I'm not getting consistent outputs with this.

    Am I misunderstanding how AudioSynthNoiseWhite works by assuming I can use it with AudioRecordQueue the same as the i2s mic input?

    #include <Audio.h>
    #include <Wire.h>
    #include <SD.h>
    #include <SPI.h>
    #include <SerialFlash.h>
    AudioSynthNoiseWhite noise; //white noise source
    AudioRecordQueue Q_1_rec_noise; //object for recording white noise source to array
    AudioPlayQueue Q_1_play;  //object to write array to for output
    AudioOutputI2S i2s_out; //Audio output
    AudioConnection patchcord0(noise,0,Q_1_rec_noise,0);
    AudioConnection patchcord1(Q_1_play,0,i2s_out,0);
    AudioConnection patchcord2(Q_1_play,0,i2s_out,1);
    AudioControlSGTL5000 sgtl5000;
    const uint32_t blockSize=AUDIO_BLOCK_SAMPLES;
    int16_t * ptr_in_noise;
    int16_t * ptr_out;
    void setup() {
    void loop() {
        Serial.print("loop \n");
        int knob2 = analogRead(A2); //Setting volume of output with potentiometer
        float vol = knob2 / 1023.0;
        ptr_in_noise = Q_1_rec_noise.readBuffer();
        ptr_out = Q_1_play.getBuffer();
        for(uint8_t i=0;i<blockSize;i++){ //Copy input buffer to output buffer
          ptr_out[i] = ptr_in_noise[i];
        Serial.print("end loop \n");
    Last edited by jjvande; 02-21-2020 at 07:23 PM.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    I commented all the Serial.print statements and your code works for me on a T3.6 with Arduino 1.8.12 and TD 1.51 beta1.
    The code looks good too - you are handling the audio buffers correctly.


  3. #3
    Junior Member
    Join Date
    Dec 2019

    Wow, you're right. Thanks for looking into that. I did the same commenting out all the serial prints and now it works. I didn't think the serial prints would cause an issue like this.
    Do you have any ideas on why this is the case?


  4. #4
    Junior Member
    Join Date
    Dec 2019
    It seems like some sort of bug with Serial.print().
    If I only keep the Serial.print("loop \n"); line uncommented, the sketch will run like I expect ONLY if the serial monitor is open. When I close the serial monitor, the noise stops being outputted. This is really strange behavior.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts