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

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

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    2

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

    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:

    }

  2. #2
    Member
    Join Date
    Feb 2020
    Location
    South Africa
    Posts
    38
    You need AudioControlSGTL5000 sgtl5000_1; object
    I am assuming you are using the audioshield?

  3. #3
    Senior Member
    Join Date
    Jun 2018
    Posts
    127
    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

  4. #4
    Junior Member
    Join Date
    Aug 2020
    Posts
    2
    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().

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,662
    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.

    Click image for larger version. 

Name:	file.png 
Views:	12 
Size:	34.5 KB 
ID:	21432

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

    Click image for larger version. 

Name:	file2.png 
Views:	12 
Size:	26.6 KB 
ID:	21433

    Sure looks to me like it's working.

Posting Permissions

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