No USB Audio when selecting Serial + Midi + Audio. (OK when only Audio selected)

Mike5000

Well-known member
I need Serial and Midi and audio via USB. When selecting Serial + Midi + Audio in Tools/UsbType in the Arduino IDE this code sends no Audio to the PC via USB.
When selecting only Audio in Tools/UsbType in the Arduino IDE the audio is sent to the PC just fine. However now we have no serial port or MIDI. We need both Audio, serial port and MIDI via USB.
Board: Teensy 3.6. Audio shield with microphone soldered in. ILI9341 display connected on alternative pins since there is an Audio shield mounted.
Compiled with Teensy lib version 1.58.1 (also tested some earlier versions, but same problem)

I have raised this issue https://github.com/PaulStoffregen/cores/issues/705

Code:
// Audio is sent to the PC only when Audio is selected under Tools/UsbType in Arduino IDE. 
// Does not send audio when Serial + Midi + Audio is selected under Tools/UsbType in Arduino IDE. 
// We need Audio and Midi and serial via USB. This has worked before, however some years since I tested. 
// The below code DOES send audio thru from the mic on the Audio shield when only Audio is selected under 
// Tools/UsbType in the Arduino IDE so the hardware works.

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

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=165,171
AudioOutputUSB           usb1;           //xy=502,170
AudioConnection          patchCord1(i2s1, 0, usb1, 0);
AudioConnection          patchCord2(i2s1, 1, usb1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=314,496
// GUItool: end automatically generated code

void setup(void) 
{
    Serial.begin(9600);
    Serial.print("running");

    AudioMemory(5);
 
    sgtl5000_1.enable();
    sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
    //sgtl5000_1.volume(0.5);
    //sgtl5000_1.micGain(10);
    //sgtl5000_1.audioPreProcessorEnable();
    
}

void loop(void) 
{
    Serial.print("Inside the loop");
}
 
Not enough audio blocks allocated.

I dont think that is the problem. Only when using the tool USBDeview to delete the USB registrations in Windows and un/re plugging the usb cable several times I somehow got audio thru.
There are others reporting similar problems. Here is a quote from the low latency CW keyer project over at https://github.com/recri/hasak/ "This release is somewhat inconsistent on my prototype. Sometimes I get no audio at all after downloading code, sometimes I get a continuous tone, and sometimes I get a working keyer. Not sure what causes it, but it generally goes away with a few rounds of unplugging and replugging the USB cable or a fresh download."
 
I dont think that is the problem.

Are you sure? It is easy to verify.
AFAIK, I2S input allocates 4 blocks for input and you have only 5. You need IMO at least 6 to allow allocation of new blocks while data are still written to USB.
Keep in mind that USB transfer is async to I2S so you need more buffers available than in synchronous mode.
 
Back
Top