Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 25 of 78

Thread: USB Audio for Teensy 3.0

  1. #1
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163

    USB Audio for Teensy 3.0

    Hello, this topic should contain every useful information about an USB Audio implementation. I'm adding all of my recent work in the field here, as a starting point for everyone.

    Teensy 3.0 USB Audio Github repo

    In this repo, you'll find modded files from the Teensyduino library, with support for a simple audio device implementation, actually it makes your Teensy result as a mono microphone.

    The Readme file on GitHub birefly explains how the code is structured. For a better understanding of what's going on, you should take a look to the USB Audio Class 1.0 specification, with the Formats and Terminal Types docs, USB Specification chapters 5-8-9, and Kinetis K20 datasheet chapter 40. There's also another topic where I started discussing the problems found in the USB "stack" of the Teensy library, I'll try to keep that stuff in that topic because most of it has nothing to do with USB Audio.

    WARNING: This stuff modifies your standard Teensyudino library and it's in very early development stage, I strongly suggest to install a fresh copy of Arduino and Teensyduino, and then add the modified code to it.

    The end result should be a generic project template to add data to a buffer (on Teensy) to be sent to the PC as a microphone, the opposite for sending audio from the PC to the Teensy as a speaker, and another template for simultaneous output and input.

    UPDATE 3/10/2013 15:56 GMT +1:Now the device works in Synchronous Mode, which means that the sample generation is slaved to the USB Start Of Frame clock. The sampling frequency has been updated to 16 KHz, and the bSubFrameSize field in the Type I Format Descriptor has been corrected to 2 bytes;

    UPDATE 10/10/2013 02:25 GMT +1:The Teensy USB library has been modded to support buffers bigger than 64 bytes, and the data type stored inside the buffer can be changed (right now it's fixed with a #define to uint16_t). This in turn paved the way to support sampling frequencies bigger than 32 KHz, in fact the library currently handles stereo input at 48 KHz.
    Last edited by MickMad; 10-10-2013 at 01:37 AM. Reason: updated changelog

  2. #2
    Junior Member MLM's Avatar
    Join Date
    Sep 2013
    Posts
    9
    I am really looking forward on getting this fully project fully operational and running for all 3 template goals. I recently got my Teensy 3.0 and have already verified and ran the current project on GitHub (8-bit 8000hz mono microphone, generates tone).

    I have been super interested in making a USB Audio device and have made topics before on this sort of thing.


    Some really good resources to learn about USB Audio Class 1.0 that I have found:
    Last edited by MLM; 10-03-2013 at 12:15 AM.

  3. #3
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Big update: I found an error in the config descriptor, namely in the Type I format descriptor, at line 484 of usb_desc.c; the bSubFrameSize was set to 1 byte, when it must be 2 for 16 bits audio. Now I can produce real square waves that can be recorded on the PC. I'm adjusting the code to use an 8 bit unsigned sine table to produce 16 bit signed data to stream a sinewave. I'll make another sketch for the sine. I'll edit the main post as soon as I update the github repo.

    edit:here's the recorded audio from Audacity, it clearly shows the sine wave. The code generates a 250 Hz sinewave right now.

    Click image for larger version. 

Name:	sine test teensy audio.jpg 
Views:	573 
Size:	81.8 KB 
ID:	986
    Last edited by MickMad; 10-03-2013 at 02:37 PM.

  4. #4
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Guys, I added a pot in the sinewave example to control the note transmitted by the Teensy. I'm also starting some mods to the memory management to let packets bigger than 64 bytes to be used, for example to handle stereo 48 KHz stuff in the future. Check the github repo, I started to commit single files only, this way I can clearly show the modifications I've made

  5. #5
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Guys I got stereo input at 48 KHz working like a charm! Thanks to MLM there are also new, more precise, sine tables; you can really see the difference between 256 and 8192 samples per table

    The next thing I want to try is putting an I2S stream (from an ADC) into the USB stream Stay tuned.

  6. #6
    Quote Originally Posted by MickMad View Post
    The next thing I want to try is putting an I2S stream (from an ADC) into the USB stream Stay tuned.
    I already do this with the teensy 3 as a USB serial device. Let me know if you get stuck.

  7. #7
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Little update: I can't get I2S RX stuff to work properly, in the meanwhile I'm configuring the Teensy to work with both input and output through USB. Right now I'm trying to implement a playthru sketch, something that gets audio from the PC and sends it back. I'll keep you up

  8. #8
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Big news people! I got the Teensy to do concurrent input/output of stereo 16 bit @ 48 KHz. The playthru sketch works perfectly.

    I also got the i2s library working together with USB streaming, but I still have some issues to deal with.

    I wanna make this library even more user-friendly, and I have to resolve these latter issues with I2S, this is goint to take some time. I'll update the Github repo asap.

  9. #9
    Senior Member
    Join Date
    Jun 2013
    Location
    Montréal
    Posts
    467
    Nice ! Could this eventually work with Paul's upcoming audio library ?

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,210
    Quote Originally Posted by nlecaude View Post
    Nice ! Could this eventually work with Paul's upcoming audio library ?
    I sure hope so!

    MickMad, please email me directly, paul at pjrc dot com. Let's talk about API stuff.....

  11. #11
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Quote Originally Posted by nlecaude View Post
    Nice ! Could this eventually work with Paul's upcoming audio library ?
    Why not? We only have to test them together

    Quote Originally Posted by PaulStoffregen View Post
    MickMad, please email me directly, paul at pjrc dot com. Let's talk about API stuff.....
    Sent you an email with current version of library

    Guys, I'm sorry I still haven't put this on GitHub, will do asap. I've reached my current main goal in this project, that means I will concentrate on documentation in the next weeks, because I'm graduating in Computer Engineering in a few weeks and this project is going to be my graduation project! YAY! Moreover, some modifications I had to make to usb_mem.c and usb_mem.h, along with usb_dev.c, may break other USB types. When this version of the library gets fail-safe I will post everything on GitHub for everyone to try! Stay tuned!

  12. #12
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Quick update: sorry for the delay, this thesis stuff is keeping me busier than ever. I updated the repo with the new full-duplex version of the code, along with the playthru demo sketch. Will post a sketch with I2S support later.

    WARNING: the old sketches will be unuseable with this new version of the library. This happens because when you declare a streaming interface in the descriptor, it MUST function properly, or else your operating system will screw up big time (it happened to me a few times). You've been warned

  13. #13
    Senior Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    122
    Exciting project! It would be fantastic if my teensy would show up as a USB audio device... If I could get the teensy to report that it only needs 50mA then I could build an audio/midi interface for my ipad

  14. #14
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Quote Originally Posted by bloodline View Post
    Exciting project! It would be fantastic if my teensy would show up as a USB audio device... If I could get the teensy to report that it only needs 50mA then I could build an audio/midi interface for my ipad

    The library works, it is still in beta though. To change the power consumption parameter, you must change the "bMaxPower" field of the Configuration Descriptor (you can find this descriptor in the file usb_desc.c inside the teensy core library, at line 303). The field takes a value that represents the total power consumption of the device in 2 mA units. To report 50 mA you would set this value to 25.

  15. #15
    Thanks for this. Got an idea this weekend to connect chat audio from PS4 to PC over usb with teensy. Thanks to you now i dont need to try make custom USB code for teensy myself
    Now i would just need to connect 2 teensys together and bridge audio data.

    I hope at some day this becomes part of the teensyduino and would work with the new audio library.

  16. #16
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Hey there, I just dropped in to say that I'm not disappeared In fact I will get my audio board really soon and I will continue working on the USB audio implementation in the audio library. I found a full time job after my graduation and now I have so little spare time to work on my personal projects stay tuned guys!!

  17. #17
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    Quote Originally Posted by MickMad View Post
    Hey there, I just dropped in to say that I'm not disappeared In fact I will get my audio board really soon and I will continue working on the USB audio implementation in the audio library. I found a full time job after my graduation and now I have so little spare time to work on my personal projects stay tuned guys!!
    Welcome in the real world. If you think you have no time now, wait until you have kids

  18. #18
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    166
    This is a great project but I've been having some difficulty getting it to work. It compiles, but won't come up as a USB device when plugged in. I suspect it may be because we are using different versions of the teensy core. I am using teensyduino 1.19 (latest stable) and it has some updates that aren't reflected in your files (like teensy 3.1 support). What version are you using? I will try to compile with that.

  19. #19
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Quote Originally Posted by ftrias View Post
    This is a great project but I've been having some difficulty getting it to work. It compiles, but won't come up as a USB device when plugged in. I suspect it may be because we are using different versions of the teensy core. I am using teensyduino 1.19 (latest stable) and it has some updates that aren't reflected in your files (like teensy 3.1 support). What version are you using? I will try to compile with that.
    Hey, thanks for your appreciation. This project has been tested with Teensyduino 1.16 or 1.17, with Arduino IDE 1.0.4. Please try again using a separate fresh arduino+teensyduino install.

    I also take the opportunity to give a quick update on the project, which is still on hold: I still have to test the functionality with the Teensy Audio Board, mainly because I still have to implement the AudioStreaming interfaces using the AudioStream class provided with the new Teensyduino IDE.

    Should anyone here have any suggestion, feel free to suggest

  20. #20
    Now that the Audio API has stabilized, are there any plans to move this code to the main trunk?

  21. #21
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,210
    Yes, it's on the roadmap.

    At the moment, I'm working on a couple hardware projects and a LONG list of stuff that got delayed or put off while so much work went into Audio 1.0. It'll probably be a couple months (or more) until I'm working heavily on new audio features. Of course, all the code is open source, so in theory anyone can fiddle and contribute. In practice, things move along much better when I'm actively putting a lot of work in. That'll happen again, but not for at least a couple months, because a ton of other important stuff all got pushed aside while I was doing the audio lib this year.

  22. #22
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    Quote Originally Posted by daperl View Post
    Now that the Audio API has stabilized, are there any plans to move this code to the main trunk?
    As Paul said, yes. My idea was to wait for a stable API indeed, and also work got in my way so I currently have circa 20 hours a week to work on my personal projects; I'm currently actively working on another project, more hardware-oriented, that I'd like to sell in kits, but I will definitely merge the USB Audio code with the Audio Lib.

    The idea is to implement 3 input channels (mic, line in), and 2 output channels (line out/headphones); the line channels will be coupled (one object to manipulate both); they will be fixed to 44.1 KHz 16 bit, just like every other audio object in the lib. I plan to make these very straighforward: the USB Input channels will present one (or two) output "pins", the USB Output channels will present one (or two) input "pins", to be matched connected with other objects in the audio lib.

    There's a bit of work to be done on the USB descriptors and control requests handling, then there's more work to do on the USB streaming part, that is pushing audio data as formed in the audio lib to USB packets, then there's to implement sync endpoints to synchronize the data stream. This will involve not only a mod on the lib, but also a mod to the USB code of the Teensy.

    Paul, whenever you have the time, let's talk about API stuff, for real this time ( how should I call the objects? what methods should they present to the user? what about the USB-specific part, how should we merge it with the teensyduino lib? etc etc etc; write me an email at michele.perla.90 AT gmail )

  23. #23
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    very nice. this combined with the new audio library will be a lot of fun

  24. #24
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,210
    Quote Originally Posted by MickMad View Post
    Paul, whenever you have the time, let's talk about API stuff, for real this time
    At the moment, I'm working on a hardware project, and also fixing issues with about a dozen libraries that were neglected while working on audio so much earlier this year.

    Realistically, I won't be doing much with audio stuff until early 2015.

  25. #25
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Italy
    Posts
    163
    I have some stuff to work on too, but when the time is right this will become my priority. If I have any update I'll keep you up.

Posting Permissions

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