🛠 DSP audio temps réel sur le Teensy 4.1 : bibliothèque Audio, I2S/TDM, S/PDIF et MQS
Objectives
The audio ecosystem is the Teensy's forte: the 16-bit / 44.1 kHz multi-channel Audio Streams library leverages the DSP instructions of the Cortex-M7 and is programmed graphically using the Audio System Design Tool (drag-and-drop of objects: oscillators, filters, effects, mixers), which generates the corresponding C++ code. The 4.1 pushes this advantage further: 2 I2S/TDM ports (up to 8 I2S channels / 16 TDM channels per port), independent S/PDIF input and output, and MQS output for a small speaker.
Hardware
- 1 Teensy 4.1 + micro-USB data cable
- The official Audio Shield (it overlaps the I2S ports) for stereo analog input/output
- Without the shield: the MQS pin drives a small speaker directly; a PT8211 kit provides a simple DAC output
Key Points
- The official tutorial runs within the IDE: File > Examples > Audio > Tutorial — follow it in order.
- The graphical tool (https://www.pjrc.com/teensy/gui/) generates the configuration of objects and channels; the produced code compiles like an ordinary sketch.
- The 600 MHz M7, with its DSP extensions and hardware FPU (single AND double precision), runs complete filter chains in real time.
- The QuadTimer4 channels are reserved by the ADC timing of the Audio library: do not use them for your PWM.
- No internal DAC on the 4.1 (unlike the 3.5/3.6): any analog output goes through I2S (shield), MQS, or PT8211.
Procedure
- Open the Audio Design Tool, place a Waveform object (440 Hz sine wave), an Output object (I2S), connect them, and export.
- Paste the generated code into a sketch, select Tools > Board > Teensy 4.1, and upload.
- Listen via the Audio Shield (headphone output) or the MQS speaker.
- Enhance: biquad filter, delay reverb, multi-object mixing — the tool displays the consumed CPU budget.
Expected Verification
A clean 440 Hz tone comes out of the chosen output, without audible artifacts despite added filters: the CPU budget displayed by the tool remains very low on the 600 MHz M7. By connecting a microphone to the line input, you can chain filter + delay and hear the effect live.
Common Errors
- Looking for
analogWritefor audio output: the 4.1 has no DAC; use MQS or I2S only. - Stacking the Audio Shield (designed for Teensy 3.x/4.0 ports) without reading the pin adaptation notice for the 4.1's long format.
- Forgetting that S/PDIF is independent of the I2S ports: you can sample via S/PDIF while playing over I2S, but you must configure both clocks.
- Overloading a single I2S port: distribute across the two ports (and up to 16 channels in TDM) before saturating.
Other tutorials for this board
- Premiers pas sur le Teensy 4.1 : Teensyduino, Teensy Loader et premier Blink
- GPIO et PWM sur le Teensy 4.1 : 55 broches en 3,3 V, ni 5 V tolérées ni traîne
- Entrées analogiques du Teensy 4.1 : 18 broches, 2 ADC, 0-3,3 V fixes et zéro DAC
- Logger sur carte SD via le port SDIO natif du Teensy 4.1
- Serveur web embarqué : l'Ethernet natif 10/100 du Teensy 4.1 (DP83825)
- Boîte à rythmes USB MIDI : classes MIDI, MIDIx16 et port hôte USBHost_t36
Code examples for this board
clignotante.inoArduinotouche-capacitive.inoArduinoanalogique-12-bits.inoArduinomidi-piano.inoArduinopwm-respiration.inoArduinoservo-angle.inoArduino