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

Thread: Cheap Audio output on Teensy 4.x ?

  1. #1
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28

    Cheap Audio output on Teensy 4.x ?

    Hello,
    Apologies if this is a redundant question. What are my options for audio output for Teensy 4 if I am trying to avoid an audio adapter board for this particular project? (Pinky-swear, I will get some more Teensies and some audio adapters very soon, eager to do this the right way.)

    • Can I use PWM? The documentation implies this won't work for a Teensy 4, but I am not sure. (The pins seem to have been hard-coded for older boards. )
    • Can I use "the onboard DAC" often referenced in discussion? I found this forum post that implies yes/no:https://forum.pjrc.com/threads/57673...4-0-make-sense


    So the real general question is, can I just get some low-fi sound out of 1 or 2 pins on the Teensy 4 but still use the Teensy Audio library (extra points: can I send multiple lo-fi audio streams from 1, 2, or 3 different hardware channels so all my synth inputs get what they want)? I started to write my own sound generator functions from scratch and that seems silly.

    I need some raw audio to feed into an analog percussion synthesizer circuit. Some kind of white noise and some (TR-606-like) metal noise. If I could get a few more audio samples for free, that would be nice. The sound quality is not an issue; I would use 8 bit sound if it was easy to implement. It seems like getting an audio adapter for this project would be casting some nice pearls before the swine that is my primitive analog percussion circuit.

    Hindsight is 20/20. Next time, I will begin my project leveraging the Audio Library.

    Thanks!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,513
    Try MQS. It's pulses similar to PWM but with noise shaping focused on audio.

    You can use the audio library without the audio shield. Almost all the examples are for the audio shield, but just replace the I2S output with MQS, and delete any SGTL5000 stuff.

    The other cheap way, but not quite as cheap as built-in MQS, would be the PT8211 chip.

  3. #3
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,834
    As Paul says, there is the MQS Audio Output. Note, MQS uses pins 10 and 12, which means you might not be able use the main SPI port (pin 12 is MISO, and pin 10 is the common CS pin). There is a secondary SPI port available, but on the Teensy 4.0 the MOSI1/SCK1 pins are on solder pads underneath the Teensy. I put through several examples of using the Tonesweep example using different outputs on the unofficial wiki. Here is the example for MQS:


    Another alternative is to use the second I2S bus along with a cheap I2S output device. For I2S2, you need pins 2, 3, and 4 for a simple I2S device that doesn't need a master clock or input (you would need solder pad 33 if the device required MCLK, and pin 5 for input). Here is an example using cheap I2S outputs that I've gotten on the internet, along with a few examples:


    You can hook up the above devices to the normal I2S bus as well.

    As Paul mentions PJRC sells a cheaper PT8211 kit that includes 2 PCBs, one for the Teensy 3.x boards and one for the Teensy 4.x boards using I2S2. While I have bought the kit, I haven't used it yet, but there should be an example in the Teensy release (Audio -> HardwareTesting -> PT8211Sine):


    The audio tool does have an output method (pt8211_2) if you use the I2S2 pins instead of the I2S pins.

    Another sound output alternative is S/PDIF. I haven't built one yet, but from the Teensy end, I believe a common method is hooking up a LED and using a fiber optic S/PDIF to analog output device. Under the Audio Tool, there are 3 different S/PDIF methods:
    • SPDIF: Uses I2S pins (Teensy 3.x/4.x);
    • SPDIF2: Uses I2S2 pins (Teensy 4.x);
    • SPDIF3: Uses Pins 14/15 which are the Serial3 pins (Teensy 4.x).


    The first 2 S/PDIF methods use the I2S support within the Teensy, while the third method uses a different subsystem dedicated to S/PDIF.

    If you hook up the USB host output, you might have more options, but it looks like the audio tool doesn't have menu items for the USB host output support (or I may be missing it).
    Last edited by MichaelMeissner; 09-07-2020 at 03:31 PM.

  4. #4
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28
    Thanks Michael & Paul!

    For this project I won't be needing i2C or SPI, just tx/rx for some MIDI. Any chance I can use another pair of SPI output pins for a second pair of MQS output channels?

    Thing is, I know it would be easier to just get an audio adapter, but that's a slippery slope! I'll never finish this project because I'll be noodling with the whole audio library!

  5. #5
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,834
    AFAIK, there is only one MQS sub-system in the processor used in the Teensy 4.0/4.1. The only pins that are brought out in the Teensy are pins 10/12.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,513
    Quote Originally Posted by blakeAlbion View Post
    Thing is, I know it would be easier to just get an audio adapter, but that's a slippery slope! I'll never finish this project because I'll be noodling with the whole audio library!
    To use MQS, you'll either need the audio library or a *lot* of work to write your own code to use the MQS output.

  7. #7
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28
    I'm good with that. Thanks.

  8. #8
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28
    Good to know. Thank you for your help. I am certain you saved me many hours.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,513
    Just in case there's any confusion, MQS and SPI are completely unrelated, other than they happen to both be options on the same pins.

    Each pin has a mux which allows it to be controlled by 1 of several peripherals. Ordinary GPIO (digitalRead, digitalWrite) is considered one of those peripherals. So is PWM. Inside the chip, the GPIO, timers which generate PWM, SPI and MQS/SAI are completely different and independent peripherals. The mux on each pin determines which peripheral gets to have control over that pin. When using MQS, the normal GPIO, PWM and SPI are not able to access those pins (unless you reconfigure the mux).

  10. #10
    Junior Member
    Join Date
    Aug 2020
    Posts
    14
    If you want dirt cheap but reasonable audio you could use the Sparkfun i2s audio breakout which would save you a lot of work (even comes with amp). It should work with the Teensy Audio library and I intend to do just that for a project. Might have to fiddle with some initialisation code but it's an Arduino thing so there's lots of library and sample code out there. Nothing wrong with trying to be as cheap as possible to achieve a particular outcome. I get a lot of pleasure out of that.

  11. #11
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28
    I found the data sheet reference for MQS in this thread.
    https://forum.pjrc.com/threads/57840...they-supported

    What I specifically wanted to know is what resistor/capacitor values should I use with an amplifier circuit, but I'll find out soon.

  12. #12
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28
    Okay! I have MQS up and running and if this is ďmediumĒ quality I am impressed. (Iím from the cassette tape era so I am easily impressed). But nobody warned me about how truly awesome this library is for a modular synth person. I was able to get a 4-oscillator-XOR model of DR-110 cymbals working with a state variable filter in a few minutes. ( I have the pcbs to build the analog implementation of this very circuit and this is going to save me a lot of solder in the short term.) I am sold. Sign me up. I will carry the card.
    (Tested on Teensy 4.0)

  13. #13
    Junior Member
    Join Date
    Nov 2014
    Posts
    5
    Quote Originally Posted by PaulStoffregen View Post
    Each pin has a mux which allows it to be controlled by 1 of several peripherals.
    I'm in a similar position to OP here, where I can't fit the audio board into my design. I've made things work with the Teensy 3.2, using PWM output and ADC input. But I'd like to have the extra processing power of the 4.0. I get that MQS needs pins 10 and 12, but is it possible to move the SPI off of 10 and 12, to use both MQS and SPI at the same time?

  14. #14
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28
    Yes, you canít move MQS to other pins but you do get auxiliary SPI pins on a Teensy 4.

  15. #15
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    28
    BTW I did pick up a couple of Audio Adapters, and being able to prototype my sounds with headphones is a joy.

  16. #16
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,834
    Quote Originally Posted by blakeAlbion View Post
    Yes, you can’t move MQS to other pins but you do get auxiliary SPI pins on a Teensy 4.
    IIRC, except for MISO1 (either pin 39 or pin 1), I didn't think the Teensy 4.x had alternate pins, like the Teensy 3.x microprocessors have.

    Maybe it is matter of terminology. The Teensy 4.x have multiple SPI buses with different pins. So you could use SPI1 instead of SPI. I have set up a Teensy 4.0 with 2 displays running uncanny eyes, one display used the main SPI bus, and the second display was on the second SPI bus (called SPI1).

    The Teensy 4.0 has 3 SPI buses:
    • SPI0: MOSI0 is 11, MISO0 is 12, SCLK0 is 13
    • SPI1: MOSI1 is 26 (underneath the Teensy 4.0), MISO1 is 1 (not listed in the pinout), SCLK1 is 27 (underneath the Teensy 4.0)
    • SPI2 (pins are in the SD pin group under the Teensy): MOSI2 is 35, MISO2 is 34, SCLK2 is 37.


    The Teensy 4.1 has 3 SPI buses, plus FlexSPI support underneath the Teensy 4.1:
    • SPI0: MOSI0 is 11, MISO0 is 12, SCLK0 is 13
    • SPI1: MOSI1 is 26, MISO1 is 1 (pin 31 is an alternate), SCLK1 is 27
    • SPI2 (pins are in the SD and you would need to bring it out): MOSI2 is 43, MISO2 is 42, SCLK2 is 45.

Posting Permissions

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