USB input to I2S output does not work for Teensy4.1

Status
Not open for further replies.

devond76180

New member
Not sure why, finally just sent it through queues, but would like this to work.


Here is the source code for what does not work. I have patched a since wave to the I2S and can see that it works. I have also done notefrequency on the USB input and know that it works, and since I have used queues and that works it is just the AudioConnection.

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

// GUItool: begin automatically generated code
AudioInputUSB usb1; //xy=226,133
AudioOutputI2S i2s1; //xy=399,126
AudioConnection patchCord1(usb1, 0, i2s1, 0);
AudioConnection patchCord2(usb1, 1, i2s1, 1);
// GUItool: end automatically generated code

void setup() {
// put your setup code here, to run once:
AudioMemory(60);
}

void loop() {
// put your main code here, to run repeatedly:

}
 
You need AudioControlSGTL5000 sgtl5000_1; object
I am assuming you are using the audioshield?
 
File>Examples>Audio>Hardware Testing>PassThroughUSB.

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

AudioInputUSB            usb1;           //xy=200,69  (must set Tools > USB Type to Audio)
AudioOutputI2S           i2s1;           //xy=365,94
AudioConnection          patchCord1(usb1, 0, i2s1, 0);
AudioConnection          patchCord2(usb1, 1, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=302,184

void setup() {                
  AudioMemory(12);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.6);
}

void loop() {
  // read the PC's volume setting
  float vol = usb1.volume();

  // scale to a nice range (not too loud)
  // and adjust the audio shield output volume
  if (vol > 0) {
    // scale 0 = 1.0 range to:
    //  0.3 = almost silent
    //  0.8 = really loud
    vol = 0.3 + vol * 0.5;
  }

  // use the scaled volume setting.  Delete this for fixed volume.
  sgtl5000_1.volume(vol);

  delay(100);
}

// Teensyduino 1.35 & earlier had a problem with USB audio on Macintosh
// computers.  For more info and a workaround:
// https://forum.pjrc.com/threads/34855-Distorted-audio-when-using-USB-input-on-Teensy-3-1?p=110392&viewfull=1#post110392
 
Not using any audio shield. This is needed as a generic USB i2s converter in both directions. The I2S input to USB output does not need anything.
Is there really a dependency in the code so that USB input to I2S out only works with the SGTL5000?
A waveform to i2s output works. USB input to notefrequency confirms that data comes in through the USB so that only leaves audioconnection().
 
SGTL5000 is not needed.

I'm running your code (from msg #1) on a Teensy 4.1 and my PC is playing a MP3 file. Here's what my scope sees on pins 8 and 20.

file.png

If I press the media pause button on my keyboard, the waveforms turn into this:

file2.png

Sure looks to me like it's working.
 
Status
Not open for further replies.
Back
Top