Extracting the highest quality audio performance from the Teensy 4.1?

polaris26

Member
After a long hiatus away from Teensy (and microcontrollers in general) I am again tinkering with DSP ideas using the Teensy 4.x and Audio Shield. Now with Claude AI assistance I am finally realizing some satisfying audio effects designs that can sound really good, and I want to extract the best (lowest noise / full bandwidth) audio from this system.

My question is, does the current Audio Shield have the potential to allow for what could be considered pro or studio-grade audio quality (or, maybe I'm using it "wrong"), or do I need to look to other codecs? What is the best way to extract the highest performance from the existing hardware?

To explain my specific setup - I am buffering the line inputs with a clean low gain / high impedance input amp for guitar (an old Alesis NanoComp with no compression or gain), and on the output side I am using the Audio Shield headphone jack out through an isolation transformer into a separate Class-D amp driving a pair of small monitor speakers.

Sometimes I get some light high-frequency whistles or "birdies" especially with a lot of gain and high-end boost. I have tried various methods to clean up the sound but it never completely goes away. The Class D amp board on its own usually makes no noise but I wasn't sure if there was some conflict or mixing going on with it's clock and the output of the headphone jack. Also there is occasional buzz or hum but this could just be normal guitar type of stuff.

In any case, are there better codecs at this point than the SGTL5000, or is it my setup that needs fixing first to realize its true potential? Or a bit of both?

Regards,
Dave
 
Hi,
In my experience it is difficult to keep noise low for guitar fx, because of the extreme dynamic range, if you have a lot of OD and compression in the software.
It is not mainly the codec but ground issues, or digital noise coming into the signal. In one setup a connection to a display gave a lot of trouble.
My way to go is to have an analogue compressor before the adc input. A noise gate is also easy to do and does also help a lot.
The teensy audio software does work with 16bit.
Christof
 
> It is not mainly the codec but ground issues, or digital noise coming into the signal. In one setup a connection to a display gave a lot of trouble.

Exactly that. I can confirm that popular China SPI LCD displays are super noisy. I was surprised when I disconnected power supply from the display the noise on PCM5102A (output!) has dropped by 10dB. Now inputs are even more susceptible. So to get less noise you need to move away all digital noisy stuff from ADC - preferably have separate board for analog part, large ground planes, shielding around analog part, use separate power supplies, ferrite beads to attenuate high frequency noise on supplies. Note that class-D amplifiers can emit HF electromagnetic noise. In fact even ordinary LED lamp with poorly designed power supply can be HF EMF source.
 
I've been contemplating trying to design my own all-in-one audio board that incorporates the teensy, having high quality separate ADC and DAC plus the needed buffers / filters for high quality ins and outs.

Then I discovered that the teensy also does SPDIF (something I know very little about) and I thought maybe the way to go is to use that functon along with an external, optically isolated ADC and DAC for audio... so many options...

But anyway it feels like there is a genuine need for a high quality stereo in and out system for the Teensy, something a little more plug and play or fully realized than the bare audio board, but I'm surprised nobody offers a system like that. It has so much potential.

Is it because once you get comfortable doing DSP with Teensy, and you want to get a little more 'serious' with audio DSP, you move on to some other ecosystem, like a SHARC processor?

I'm still learning so I'm not sure how far a Teensy can be pushed into that realm (As I said, my goal is to make some really nice sounding effects that are reasonably quiet, mostly for guitar or general live or recording use).

Also on the subject of I2S codec options - what about using an outboard 'helper DSP' codec like an ADAU - series chip for the ADC/DAC functions, which could also offload some of the other DSP stuff like speaker simulation/EQ etc ?

Just some rambling thoughts this morning...

Regards,
Dave
 
Most I2S-based DAC/ADC cards can be used—they aren't exactly “plug-and-play,” but they're easy to connect, pretty straightforward. There aren't that many signals, after all. There are plenty available on AliExpress, with varying levels of quality. But you can find them elsewhere, too.

Take a look here, too:
 
Last edited:
In any case, are there better codecs at this point than the SGTL5000?
Yes, its pretty low-end - designed for cheapest mobile phones and the like (but is a full codec). Its known to have spurs on the microphone input for instance. My immediate suspicion for noise is that class-D amp, they have an oscillator that may be heterodyning with the codec's I2S clocks down into the audio band... Maybe listen to the SGTL5000's headphone output (on headphones only) to see what the base level of spurious noises is.

Ironically class D amps work best for analog sources and vice versa - unless the digital source and class D clock are synced - this might be possible for you?

Isolation transformer is also a poor choice - why not use the line outs and avoid the need for the transformer(s)? Transformers are non-linear and pick up interference (unless very well made and expensive).
 
A couple more things to keep in mind:

1.

For lots of complex DSP work, you REALLY need more than 16 bits! By itself, a 16-bit A-D-A conversion with no DSP at all, is completely inaudible. There have been tests for that, with really good analog gear that doesn't mask the conversion artifacts (difficult, but possible for 16 bits), so it really is testing human perception, and that was the result. But when you build up enough round-off error to make the upper N bits incorrect, where N is somewhere between 6 and 14 or so, depending on your application, then you hear it.

Even the cheap end of (semi) pro gear uses a lot of bits for the DSP part. For example, the Behringer X32 and its "little brother" X-Air both use 40-bit floating-point internally. 24-bit ADC's that no analog preamp could ever dream of keeping up with, then upconvert immediately to 40-bit FP to do all the processing. Then last-moment truncation/rounding (doesn't matter which) to 24-bit DAC's that no analog line driver could ever dream of keeping up with. (which is why it doesn't matter which)

For a small utility DSP, like a system processor for a PA or home stereo, it might be okay to use 32-bit integers internally (just tack a few more bits on, without a major format conversion), but as the workload grows, it quickly becomes worth the additional layer of conversion to use FP! Astronomical headroom, and constant signal to quantization noise, regardless of level. Just make sure the final outputs are sensible before converting back to integer, and you're good.

2.

All DSP's add some latency/delay. Mixing an undelayed signal with its delayed counterpart, creates a comb filter, which is often described as "metallic", "robotic", "weird", etc., when that latency/delay is somewhere between insignificant (first notch is at the very top end of the spectrum) and separately perceptible as an echo/repeat. Normally you'd want to avoid that, but I've also seen it used intentionally as a guitar effect...

At 48kHz, the converter chips themselves contribute about 1ms of latency, so if you directly connected an ADC's output to a DAC's input and ran their clocks, that's what you'd get. At the speed of sound in air, that equates to the speakers being about 1 foot farther away than they really are. Anything the DSP itself does, is on top of that. Faster sample rates reduce that 1ms, both because the time between samples is less, and because the converters use more gradual anti-aliasing filters that have fewer samples of delay.

(Note: Faster sampling does NOT preserve ultrasonics unchanged! The anti-aliasing turnover is still about 21kHz regardless. Only the slope is changed.)

Last time I looked at the ADAU series of easy-to-use dedicated DSP chips, they used a 64-sample buffer. At 48kHz, that's 1.3ms of additional latency, for a total of 2.3ms including the converters. Maybe that's okay, but do be aware of it. Most serious dedicated DSP things (like the Behringer mixers above) run a single sample all the way through before grabbing the next one, so no buffer, and only one sample of DSP latency added to what the converters do.

If you're comparing to a PC, then even a 64-sample buffer will actually be an improvement! A multitasking operating system like Windows, Mac, or Linux, needs the soundcard to buffer a lot more than 64 samples while it does everything else, then it processes that buffer all at once, and lets the soundcard play it out while it takes care of everything else again. If you're connecting different apps, then each connection is likely another buffer.

(Don't ask to increase the Teensy's sample rate. It would likely require a complete rewrite of every function *for every supported rate*, because the math changes for each one. DSP's actually have no concept of time or frequency, only samples, so everything must be expressed as so-many samples.)
 
Last edited:
Don't ask to increase the Teensy's sample rate. It would likely require a complete rewrite of every function *for every supported rate*, because the math changes for each one.
The code uses the AUDIO_SAMPLE_RATE_EXACT macro. So, can you explain that in more detail? (Esp. which "every function" or whatever?) I'd be interested to know, because I'm currently porting the library. 90% of the code even does'nt use the frequency.-..
Changing the frequency is pretty easy.
DSPs: They need the frequency too, when used as synth.

To put 16-bit audio into perspective:
Even a really well-produced vinyl record typically offers less than 12 bits’ worth of dynamic range (70db) . Some audiophiles invest in turntable setups costing €10,000 or more to get the very best possible sound from their records. But ultimately, there are limits to what the source material can deliver. That’s also why I’m a little skeptical of some high-end accessories, such as gold-plated power plugs.

For everyday listening at home, 16-bit audio is more than sufficient. Internally, however, when mixing, processing, and performing calculations, higher precision can certainly be beneficial in some situations.

But that’s a software issue. There are 32-bit and even floating-point ports of the library available.
 
Last edited:
Yes, its pretty low-end
It's just consumer-grade. Since most people aren't musicians or audiophiles, it's good enough for everyday use—I think the quality is pretty decent. Of course, it's not top-of-the-line technology—but that's not what it's meant to be anyway.
 
The code uses the AUDIO_SAMPLE_RATE_EXACT macro. So, can you explain that in more detail? (Esp. which "every function" or whatever?) I'd be interested to know, because I'm currently porting the library. 90% of the code even does'nt use the frequency.-..
Changing the frequency is pretty easy.
According to my file content search, it appears that that macro only adjusts the data-shoveling rate on line 81 of AudioStream.cpp (near the end of AudioStream::initialize_memory), and the CPU load indicator on lines 115, 117, 118, and 150 of AudioStream.h.

If there's any frequency- or time-dependent processing like EQ's, compressors, etc., then they're not affected when they need to be. Take a filter that works correctly at 48kHz, and run it at 96kHz instead, and all of what it does will be shifted up an octave. Not like a chipmunk, but a boost at 100Hz now boosts at 200Hz. To get the original function back at twice the sample rate, you need to tell it an octave lower. Likewise for attack, release, and delay times, and pretty much everything else except for a flat gain.

DSPs: They need the frequency too, when used as synth.
The user setting might have units of Hz or seconds, but it must be translated to a number of samples before the DSP code can use it. That translation might be buried in the math to determine the coefficients of a particular algorithm, usually as a (F/Fs) term where F is the user's setting and Fs is the sample rate, but it's always there. If you can't find it, then it's probably either hard-coded so you'll have to back it out and then adjust it to make a different rate work correctly, or done elsewhere so you'll have to find *that*.

To put 16-bit audio into perspective:
Even a really well-produced vinyl record typically offers less than 12 bits’ worth of dynamic range (70db) . Some audiophiles invest in turntable setups costing €10,000 or more to get the very best possible sound from their records. But ultimately, there are limits to what the source material can deliver. That’s also why I’m a little skeptical of some high-end accessories, such as gold-plated power plugs.

For everyday listening at home, 16-bit audio is more than sufficient. Internally, however, when mixing, processing, and performing calculations, higher precision can certainly be beneficial in some situations.
The point of gold-plating is not to improve anything, but to keep it from corroding and losing a connection entirely. Very common in electronics, and often over-applied because it's cheap insurance. But yes, the audiophool world is very much alive and well too!

Vanishingly small price to pay nowadays, to do what seems like overkill on the digital side, just to not have a technical argument *at all*, in *any* situation, about quality degradation. (yet some people do anyway, just because "it's digital") Yes, 16-bit integer processing (the original Teensyduino Audio Library) is probably inaudible for a lot of projects, but a true general-purpose thing should have more. The primary (real) argument is cumulative round-off error.

---

And to add to that perspective, I actually have an almost pure analog 40-channel PA console and outboard processing rack on a cart, inherited and cobbled together from several church upgrades. The "almost" part is because of a 24-track 24-bit recorder to a hard drive: TRS phone plugs for I/O, and firmware switch between ADC's and ADAT inputs, the output of which always drives the DAC's, ADAT outs, and recording. (so it can also be used as a converter between ADAT and analog) No analog bypass, but no DSP either. So no format conversion at all: its built-in file server offers 24-bit WAV's, and a community reverse-engineered extraction app does the same.

Anyway, I'd estimate that rig's noise performance to be around 8- to 12-bit equivalent (it's analog, so that determination is independent for every little part of it), which is plenty for the live band that it's presently running. In fact, I've gotten some comments on how good it sounds, and if the M32 that it's temporarily replacing (X32 with expensive preamps and line drivers) could be made to sound like that.
 
Regarding your points about the library: Please take a look at the code before making assertions.
You're all wrong.
 
Last edited:
Back
Top