Using Teensy USB audio input object

Status
Not open for further replies.

jshooks

Well-known member
I am trying to use the USB object from the Audio System Design Tool as one of three possible audio inputs selections using mixers as soon below. The "USB audio" would be inputted using the Teensy 3.2 or 3.5 serial monitor/programming connector from a computer music file (pre-recorded). I presume the pre-recorded audio stream would have less issues of jitter as pointed out in a recent post.

Audio Recording Line_USB_SD.PNG

The output audio is then fed to the Teensy for FFT processing. The SD and audio line are pretty straightforward using the Audio Shield Board. However, I presume that the Teensy processes the USB audio directly as a serial input (master Serial port). The question is, if I want to use the Audio Shield to "play" the audio through the audio line output, how would that be done if the SQTL5000 chip is not part of the USB audio processing chain? Maybe I am wrong with my assumptions here. Since Are there any code examples for doing this? Any assistance would be greatly appreciated.
 
if I want to use the Audio Shield to "play" the audio through the audio line output, how would that be done if the SQTL5000 chip is not part of the USB audio processing chain?

Normally 3 objects use the SGTL5000, the control one (no audio connections) which just configures the hardware over SDA & SCL, and the 2 I2S objects which actually stream the audio data.

In your diagram, the USB goes into mixer, which feeds into another mixer, which then goes to I2S output. So to get whatever sound your PC is sending to come out of the SGTL5000, you'd just configure the gain on those 2 mixer to pass the signal, and of course enable the SGTL5000 and set the volume to something you can hear.

There aren't any examples very specific to what you're asking. The HardwareTesting has a few that pass data through for simple testing. And of course the main tutorial covers using the SGTL5000 in every part. But there's no mention of the USB, because when that tutorial was written the USB audio features didn't exist.
 
Thanks Paul for the quick response. In configuring the patch cords and declaring the usb1 object, I'm getting these errors stating usb1 was not declared in this scope:

API_Version_Serial14:41: error: 'usb1' was not declared in this scope
AudioConnection patchCord5(usb1, 0, mixer1, 2);


API_Version_Serial14:42: error: 'usb1' was not declared in this scope
AudioConnection patchCord6(usb1, 1, mixer1, 3);

Include & GUItool patches:

#include <Arduino.h>
#include <XPT2046_Touchscreen.h> //New
#include <ILI9341_t3.h>
#include <font_Arial.h> // from ILI9341_t3
#include <font_ArialBold.h> // from ILI9341_t3
#include <Audio.h> //Audio Library
#include <Wire.h>
#include <SPI.h> //For LCD display
#include <SD.h> //For SD Card
#include <SerialFlash.h>
#include <EEPROM.h>
#include <XBee.h> //Using serial for XBee instead
//#include <TimeLib.h> //For internal Real Time Clock
#include <Bounce.h>


// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; //xy=251,269
AudioPlaySdRaw playRaw1; //xy=261,417
AudioInputUSB usb1; //xy=266,336
AudioMixer4 mixer1; //xy=465,306
AudioMixer4 mixer2; //xy=465,380
AudioInputI2S i2s2; //xy=469,508
AudioRecordQueue queue1; //xy=655,502
AudioMixer4 mixer3; //xy=774,326
AudioOutputI2S i2s1; //xy=972,255
AudioAnalyzeFFT1024 fft1024_1; //xy=973,326
AudioConnection patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection patchCord2(playSdWav1, 1, mixer1, 1);
AudioConnection patchCord3(playRaw1, 0, mixer2, 0);
AudioConnection patchCord4(playRaw1, 0, mixer2, 1);
AudioConnection patchCord5(usb1, 0, mixer1, 2);
AudioConnection patchCord6(usb1, 1, mixer1, 3);
AudioConnection patchCord7(mixer1, 0, mixer3, 0);
AudioConnection patchCord8(mixer1, 0, mixer3, 1);
AudioConnection patchCord9(mixer2, 0, mixer3, 2);
AudioConnection patchCord10(mixer2, 0, mixer3, 3);
AudioConnection patchCord11(i2s2, 0, queue1, 0);
AudioConnection patchCord12(mixer3, fft1024_1);
AudioConnection patchCord13(mixer3, 0, i2s1, 0);
AudioConnection patchCord14(mixer3, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=467,449
// GUItool: end automatically generated code

Do I need to declare usb1 as equating to some input device like the Serial port or something else? I thought the GUItool declaration was enough, but obviously I'm missing something. The mixer gain control takes place in a subroutine below:

void configMixer() {
if (Audio_Input == 0) { //Change audio input selection to SD Card
tft.setCursor(140, 175);
tft.print("SD"); //Display SD card input setting
mixer1.gain(0, 0.7); //SD left input
mixer1.gain(1, 0.7); //SD right input
mixer1.gain(2, 0.0); //Turn off left USB input
mixer1.gain(3, 0.0); //Turn off right USB input
mixer2.gain(0, 0.0); //Turn off playRaw left input
mixer2.gain(1, 0.0); //Turn off playRaw right input
mixer3.gain(0, 0.7); //SD combined playRaw input
mixer3.gain(1, 0.7); //Turn off playRaw input
mixer3.gain(2, 0.0); //SD combined playRaw input
mixer3.gain(3, 0.0); //Turn off playRaw input

Serial.println("SD input");
}
else if (Audio_Input == 1) { //Change audio input selection to Line
tft.setCursor(130, 175);
tft.print("LINE"); //Display audio line input setting
mixer1.gain(0, 0.0); //SD left input
mixer1.gain(1, 0.0); //SD right input
mixer1.gain(2, 0.0); //Turn off left USB input
mixer1.gain(3, 0.0); //Turn off right USB input
mixer2.gain(0, 0.7); //Turn off playRaw left input
mixer2.gain(1, 0.7); //Turn off playRaw right input
mixer3.gain(0, 0.0); //SD combined playRaw input
mixer3.gain(1, 0.0); //Turn off playRaw input
mixer3.gain(2, 0.7); //SD combined playRaw input
mixer3.gain(3, 0.7); //Turn off playRaw input
Serial.println("Line input");
}
else { //Else audio input must be USB
tft.setCursor(135, 175);
tft.print("USB"); //Display USB input setting
mixer1.gain(0, 0.0); //SD left input
mixer1.gain(1, 0.0); //SD right input
mixer1.gain(2, 0.7); //Turn off left USB input
mixer1.gain(3, 0.7); //Turn off right USB input
mixer2.gain(0, 0.0); //Turn off playRaw left input
mixer2.gain(1, 0.0); //Turn off playRaw right input
mixer3.gain(0, 0.0); //SD combined playRaw input
mixer3.gain(1, 0.0); //Turn off playRaw input
mixer3.gain(2, 0.7); //SD combined playRaw input
mixer3.gain(3, 0.7); //Turn off playRaw input
Serial.println("USB input");
}
}

I would post the code, but the sketch is almost 7,000 lines. The SD input works fine, but the audio line input has not been tested yet (I'm sure it will).
 
Last edited:
Did you look at the whole error message in the bottom window of the Arduino IDE? Did it perhaps include something like this:
TestVersion:8: error: 'AudioInputUSB' does not name a type
To make an USB Audio device, use the Tools > USB Type menu
 
AudioInputUSB' does not name a type

Yes, you are right. That message was at the bottom of the error list. If I enable Serial/MIDI/Audio as a type under the IDE Tools menu, then the program does compile without errors. In the past, assigning this port type has caused some program lock-ups, but I thought maybe that was because the computer was pinging the Teensy port as a USB device. I don't think this is the case as the computer identifies the Teensy port as com port (serial). I assume that the Teensy can auto-detect if the port input is serial or audio when assigned either/or by the IDE Tool. However, does the usb1 object equate to audio automatically?
 
Status
Not open for further replies.
Back
Top