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

Thread: AudioRecordQueue never available after Windows records once

  1. #1

    AudioRecordQueue never available after Windows records once

    I have two Teensy 4.0 as Audio devices connected on Serial1 to send and receive audio.

    AudioInputUSB -> AudioRecordQueue -> Serial1.write

    Serial1.read -> AudioPlayQueue -> AudioOutputUSB

    Everything works until I record audio once or I have a Windows application monitor the received audio in the Teensy recording device.

    AudioRecordQueue.available is always zero.

    I can play audio on Teensy playback device and audio monitors have activity.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,864
    You're going to have to post an example sketch which demonstrates the problem.

    Pete

  3. #3
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    AudioInputI2S i2s2; //xy=105,63
    AudioInputUSB usb1; //xy=200,69  (must set Tools > USB Type to Audio)
    AudioOutputUSB usb2;
    AudioPlayQueue pqueue4;
    AudioRecordQueue rqueue1;
    AudioOutputI2S i2s1; //xy=365,94
    
    AudioConnection patchCord1(usb1, 0, rqueue1, 0);
    AudioConnection patchCord4(pqueue4, 0, usb2, 0);
    
    int ret = 0;
    int i = 0;
    int j = 0;
    
    short array1[AUDIO_BLOCK_SAMPLES];
    short array2[AUDIO_BLOCK_SAMPLES];
    
    byte *bytearray1 = (byte *)array1;
    byte *bytearray2 = (byte *)array2;
    
    byte s1RxBuffer[25600];
    byte s1TxBuffer[25600];
    
    void setup()
    {
        // Serial.begin(9600);
        Serial.println("Begin");
    
        Serial1.addMemoryForRead(s1RxBuffer, sizeof(s1RxBuffer));
        Serial1.addMemoryForWrite(s1TxBuffer, sizeof(s1TxBuffer));
        Serial1.begin(2000000);
        Serial1.clear();
    
        AudioMemory(64);
    
        rqueue1.begin();
    
        // pqueue4.setBehaviour(AudioPlayQueue::NON_STALLING);
        // pqueue4.setMaxBuffers(128);
        // pqueue4.setBehaviour(AudioPlayQueue::ORIGINAL);
    }
    
    void loop()
    {
        Serial.print("loop: ");
    
        ret = rqueue1.available();
    
        Serial.print(" rqueue ");
        Serial.print(ret);
    
        while (ret >= 1)
        {
            Serial.print(" write ");
            Serial.print(ret);
    
            void *rb = rqueue1.readBuffer();
            Serial.print(" rb ");
            Serial.print((long)rb, HEX);
            memcpy(&array1[j * 128], rb, 2 * AUDIO_BLOCK_SAMPLES);
            rqueue1.freeBuffer();
    
            for (int i = 0; i < AUDIO_BLOCK_SAMPLES * 2; i++)
            {
                Serial1.write((byte)bytearray1[i]);
            }
    
            ret = rqueue1.available();
        }
    
        ret = Serial1.available();
    
        Serial.print(" | serial ");
        Serial.print(ret);
    
        while (ret >= 2 * AUDIO_BLOCK_SAMPLES)
        {
            Serial.print(" read ");
            Serial.print(ret);
    
            for (int i = 0; i < AUDIO_BLOCK_SAMPLES * 2; i++)
            {
                if (Serial1.available())
                {
                    bytearray2[i] = (byte)Serial1.read();
                }
            }
    
            if (pqueue4.available())
            {
                void *pb = pqueue4.getBuffer();
                Serial.print(" pb ");
                Serial.print((long)pb, HEX);
                memcpy(pb, &array2[j * 128], 2 * AUDIO_BLOCK_SAMPLES);
                pqueue4.playBuffer();
            }
    
            ret = Serial1.available();
        }
    
        Serial.print(" | mem ");
        Serial.print(AudioMemoryUsage());
        Serial.print(" max ");
        Serial.print(AudioMemoryUsageMax());
        Serial.println();
        delay(10);
    }

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,864
    Remove the delay at the end of the loop function. It is slowing down the processor's response to incoming audio and serial data.

    Pete

  5. #5
    Quote Originally Posted by el_supremo View Post
    Remove the delay at the end of the loop function. It is slowing down the processor's response to incoming audio and serial data.

    Pete
    It didn't make a difference. I need the delay to see Serial.print messages. Serial Monitor hits a buffer limit without the delay.

  6. #6
    Start recording on the receiving Teensy.

    Play a sound from the transmitting Teensy.

    Receiving Teensy records the sound.

    Sound ends.

    Play a sound from the transmitting Teensy.

    Receiving Teensy receives nothing.

    Transmitting Teensy AudioRecordQueue.available is always zero.

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,864
    Are you running the same sketch in both Teensys? If so, try separating the sketches so that the recording teensy only records from AudioInputUSB and writes to Serial1. The receiving teensy only reads bytes from Serial1 and plays them to AudioOutputUSB.

    Which program(s) are you using to send USB audio to the receiver and receive audio from the receiving Teensy?

    Pete

  8. #8
    Quote Originally Posted by el_supremo View Post
    Are you running the same sketch in both Teensys? If so, try separating the sketches so that the recording teensy only records from AudioInputUSB and writes to Serial1. The receiving teensy only reads bytes from Serial1 and plays them to AudioOutputUSB.

    Which program(s) are you using to send USB audio to the receiver and receive audio from the receiving Teensy?

    Pete
    Separating the sketches had no affect.

    I moved one Teensy to another PC. The problem now is I can send audio from PC1 to PC2, but the Teensy can't send audio from PC2 to PC1.

    It's the same if I swap the Teensies. PC1 can send to PC2 and PC2 cannot send to PC1.

    AudioRecordQueue.available is always zero on PC2.

    Moving both on PC2 reproduces the problem on PC1.
    Last edited by btspp; 12-22-2021 at 04:08 AM.

  9. #9
    I can send and receive from two PCs now.

    On one PC, I could only receive when the Teensy was connected to a USB hub. I could send and receive when the Teensy was connected directly to the USB port.

    On another PC, I could send and receive after moving the Teensy to another USB hub port.

  10. #10
    Has anyone run into this? I could not find it by searching.

    For one device, my Teensy as Audio (using the source above) can receive audio, but stops sending when another Teensy (as keyboard mouse joystick) is plugged in to the same USB hub. The Teensy will eventually receive and send if I disconnect and reconnect it many times to the USB hub until it works.

Posting Permissions

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