Cheap Audio output on Teensy 4.x ?

Status
Not open for further replies.

blakeAlbion

Well-known member
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.)


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!
 
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.
 
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:
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!
 
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.
 
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.
 
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).
 
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.
 
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)
 
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?
 
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.
 
Status
Not open for further replies.
Back
Top