Teensy 4.1 and Audio Shield I2S Group Delay

Blaser123

New member
I have a Teensy 4.1 with Audio Adapter and a project configured as an ultra basically I2S passthrough.

I am measuring a delay from the input to the output of ~6.5ms by applying audio and measuring the in/out with a scope.

Is there anyway to improve this delay as it seems strangely long.

Based on the AudioStream.h the audio library is running on 128 samples at 44.1kHz. This would account for 2.9ms.
Where is the remaining 3.6ms going?
 
Use smaller audio block size. The Audio Lib reads, by default, 128 samples before processing anything, then releases a 128 sample block to the output device (which itself will have a delay due to DMA buffering). Your 6.5ms agrees with a two block delay plus the overhead of the ADC/DAC (Audio DACs have significant delays built in as they are pipelined sigma-delta devices with internal digital filtering.

6.5ms is equivalent to about 2 metres sound propagation in air, BTW.
 
Indeed, you can get less delay by configuring small block size.

However, the trade-off is higher overall CPU usage. The default of 128 samples aims to give efficient CPU usage but still keep delay reasonable.
 
I did a blog post on measuring the latency, including the effect of the audio block size, sample rate, and the inherent latency of the audio codec. It's for the Tympan Rev C, which was a Teensy 3.6, but it'd be the same for the Teensy 4.x, too.


As said above, the latency is dominated by the length of the audio block size divided by the sample rate. So, changing either of these will get you the biggest change in latency.

So, if you can run with half the the block size, you'd (almost) halve the latency. Keep making the block size smaller, the latency will keep shrinking. There's a graph in my blog post above. In parallel, you could double the sample rate (possible on Tympan but not on the Teensy audio board) and you'd halve the latency yet again. Powerful!

As others have said, you can change the Teensy audio library's block size by digging into their code and changing a #define line. Or, if you use one of the Teensy-derived audio libraries (for example: OpenAudio library or Tympan library) you can change the block size without digging down into the guts of the Teensy stuff. Here's an example from the Tympan library:


Chip
 
Back
Top