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

Thread: Linux audio device bug? + toslink on T4

  1. #1
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    728

    Linux audio device bug? + toslink on T4

    When I run this program with the USB type set to Serial/MIDI/Audio, there is silence. I change to USB type "Audio" and it works well. T4, OS is Linux Mint, Teensyduino 1.53. Is it possible to have Serial and Audio?

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputUSB            usb1;           //xy=143,207
    AudioOutputSPDIF3        spdif3;         //xy=502,202
    AudioConnection          patchCord1(usb1, 0, spdif3, 0);
    AudioConnection          patchCord2(usb1, 1, spdif3, 1);
    
    // GUItool: end automatically generated code
    
    
    void setup() {
      AudioMemory(10);
    }
    
    void loop() {
      
    }

    People like pictures, so this shows just how easy it is to get good quality audio from a teensy. Toslink module is a few dollars from ebay.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	T4-audio.jpeg 
Views:	22 
Size:	36.7 KB 
ID:	22060  

  2. #2
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    728
    Has anyone used T4 Serial+Midi+Audio with Linux? DD4WH (OS unknown) reported the opposite problem (Audio alone didn't work).

  3. #3
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    728
    That wiring worked, but wasn't bright enough for some DACs. This works correctly.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	T4-toslink2.jpeg 
Views:	15 
Size:	86.8 KB 
ID:	22069  

  4. #4
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    681
    Maybe we should open a separate thread with this phenomenon?

    * Windows 10, Arduino 1.8.13 TD 1.53
    * Teensy 4.0 with Teensy audio shield REV D
    * USB - Audio in / I2S Audio out
    * Compiling with USB-type "Audio" does not give any audio output from PC to Teensy
    * Compiling with USB-type "Serial + MIDI + Audio" does give perfect audio output (headphone out on the Audio shield) from PC to Teensy with the very same sketch

    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) --> DOES NOT WORK, HAVE TO SET USB TYPE TO SERIAL + MIDI + AUDIO IN ORDER TO WORK PROPERLY: WHY ?
    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() {
    
      delay(100);
    }

  5. #5
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    728
    Another issue/bug: any call to usb1.volume() causes the audio device on linux to stop working.

    * Linux Mint, Arduino 1.8.13, TD 1.53
    * Teensy 4.0 with toslink/spdif3 output
    * USB Audio in

  6. #6
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    728
    Forget volume() issue in #5 - volume() is working OK now that I found the alsa control in Linux.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,041
    I tried to reproduce this problem today, using the code in msg #4 and Ubuntu 18.04, running on Teensy 4.1 and an audio shield connected to a monitor speaker.

    At first it seemed like Audio wasn't working but Serial+MIDI+Audio worked fine. But then I realized Audio was working, just playing very softly. Looks like the system keeps a separate volume setting for each. I tried Serial+MIDIx16+Audio too. All were working.

    Also strange is the behavior in the Gnome Sound Settings when Teensy reboots. Two audio interfaces appear and one gets automatically selected. But the sound I have playing from YouTube in a browser window keeps playing through my PC's speakers. But if I click the other Teensy audio interface, sound switches from my PC to Teensy.

    I tried reprogramming several time. All 3 ways, Audio, Serial+MIDI+Audio, and Serial+MIDIx16+Audio all seem to work fine.

    Then I plugged in a USB microphone to try to record a screencast demo. While the USB mic is plugged in, Teensy can't play audio at all. The mic also has monitoring output. I plugged headphones into the mic, and indeed the PC's audio can play through the mic's headphone monitoring. But clicking on either of Teensy's interfaces gives no sound at all.

    If I unplug the USB mic, Teensy still can't play output. But then if I unplug and reconnect Teensy, it can play sound again! I think what may be happening here is a USB host controller bandwidth allocation, where the USB mic gets allocated bandwidth and then there isn't enough for Teensy. But Teensy 4.1 is supposed to be using 480 Mbit speed, so it seems like there ought to be plenty of bandwidth. Very confusing....

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,041
    I tried plugging that USB mic into a USB3 hub, and apparently my PC can't see it at all through that hub. Grrr...

    I crawled under my desk and plugged the mic into a USB controller card I have in one of the PCIe slots, so it's not sharing the same bandwidth as the controller Teensy uses. Indeed that lets my PC see the USB mic and I can play audio to my PC speakers or to Teensy or to mic's headphone monitoring output.

    So it does seem that have 2 USB audio devices on the same USB controller causes problems. Both show up in the Gnome Sound Settings window, but only 1 of them is able to work.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,041
    I tried to create a screencast demo with the USB mic, but reprogramming Teensy causes my Linux machine to sometimes automatically switch the audio input from the USB mic to Teensy's silent incoming data. Making a video demo of this is going to require using another machine to record the audio and then video editing to sync it up. More work than I'm looking to do for a quick test!

    I really did try all 3 settings many times. There are lots of confusing situations, where the arrival of Teensy's audio device doesn't always cause the PC's already playing audio to switch even though it gets highlighted automatically in the settings panel. Each interface gets its own volume setting and sometimes it can be turned down so low that the interface seems to not work. And if the USB mic is plugged into the same USB controller, Teensy shows up in the settings window but they really does not work. All 3 types did the same thing though.

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,041
    Whether anything is wrong on the Teensy side, I'm not 100% sure. I was able to find lots of cases where the Linux / Ubuntu / Gnome experience is confusing & frustrating. My gut feeling is these problems aren't Teensy's doing.

    When volume settings were the same, all 3 interfaces types seem to work. I could not reproduce problems where Audio works but Serial+MIDI+Audio fails.

  11. #11
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    728
    I unplugged all USB devices and then plugged in only the teensy. Indeed, this worked!

    Thanks, this will make debugging much easier.

    I suppose ideally there would be some way for the teensy to detect a lack of bandwidth allocation and report an error.

    FWIW, dmesg on linux shows this error when the teensy is plugged in.

    Code:
    Warning! Unlikely big volume range (=4095), cval->res is probably wrong.
    usb 2-1.5: [49] FU [PCM Playback Volume] ch = 2, val = 0/4095/1

Posting Permissions

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