🛠 Chaîne audio 44,1 kHz : Audio Library, Design Tool, I2S, S/PDIF et sortie MQS
Objectives
The Teensy is the reference platform for DIY pedals and synths thanks to the Teensy Audio Library and its graphical Audio System Design Tool (https://www.pjrc.com/teensy/gui/): you draw a signal flow graph by drag-and-drop, and the tool EXPORTs functional Arduino code. The 600 MHz M7 and its DSP instructions enable real 44.1 kHz stereo. On the hardware side: 2 I2S/TDM ports (8 I2S channels / 16 TDM), independent S/PDIF inputs/outputs, and the MQS "Medium Quality Sound" output for direct speaker connection. Watch out for Audio Shield revisions: this is THE historical pitfall when moving from 3.x to 4.0.
Hardware
- 1 Teensy 4.0
- Choice of: Audio Shield (Rev D recommended — see below), PT8211 DAC kit (https://www.pjrc.com/store/pt8211_kit.html), or the MQS output on a pin
- Headphones or amplifier; Audio library (included in Teensyduino)
The Shield Revision Trap
Audio signals changed pins between Teensy 3.x and 4.0: the original Rev B shields do NOT work directly — you must add wires AND a 100 Ω series resistor on MCLK; Rev C only added the resistor; only Rev D natively routes the Teensy 4.0 (source: forum thread, Paul Stoffregen).
Complete Code (Generatable by the Design Tool)
// 440 Hz stéréo via l'Audio Shield — le graphe décrit ici est
// exactement ce que produit le Design Tool par glisser-déposer.
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
AudioSynthWaveformSine sine;
AudioOutputI2S sortie;
AudioConnection patchDroite(sine, 0, sortie, 0);
AudioConnection patchGauche(sine, 0, sortie, 1);
AudioControlSGTL5000 codec;
void setup {
AudioMemory(10); // pool de blocs audio — sans lui, rien ne sort
codec.enable;
codec.volume(0.5);
sine.frequency(440.0);
sine.amplitude(0.3);
}
void loop { } // tout tourne dans les interruptions audio
Expected Verification
A clean 440 Hz tone comes out in the headphones. Open the Design Tool: add an EffectReverb, an EffectFilterLowPass, a WAV file read from the SD card (the 8 SDIO pads on the back, SD.begin(BUILTIN_SDCARD)), export, and compare the generated code with yours — that is the whole point of the tool. Under load, check the remaining CPU headroom (the tool estimates the graph load): the M7 handles reverb + EQ + delay simultaneously.
Common Errors
- Forgetting AudioMemory(n): the code compiles, runs, and produces only polite silence — the block pool is mandatory.
- Plugging a Rev B shield "as on the Teensy 3.2": no sound or choppy sound — additional wiring + 100 Ω on MCLK are required; check the silkscreen on your shield.
- Believing the microphone input is connected to the internal ADC: the SGTL5000 codec on the Audio Shield goes through I2S; the edge ADC, on the other hand, is not meant for audio (~10 effective bits).
- Confusing MQS and I2S: MQS = filtered PWM output for a small speaker (decent quality, zero critical components); I2S = to a real DAC (PT8211, Audio Shield codec).
- Saturating the audio pool: each effect block costs; AudioMemory too small = crackling, too large = RAM starvation for the rest.
- S/PDIF: the input/output pins are independent of the I2S ports — do not configure them twice.
Other tutorials for this board
- Premiers pas sur le Teensy 4.0 : Teensyduino, Loader et premier Blink
- GPIO et PWM sous 3,3 V : les règles d'or du Teensy 4.0
- Entrées analogiques et capteur de température interne : le ADC et ses limites
- Piloter un ruban WS2812 sans bloquer le CPU : WS2812Serial et OctoWS2811
- Contrôleur MIDI USB : un potard qui joue du piano (MIDIx4/MIDIx16)
- Comprendre la mémoire : 2 Mo de flash, 1 Mo de RAM TCM/DMA, EEPROM émulée et LittleFS
Code examples for this board
clignotante.inoArduinotouche-capacitive.inoArduinoanalogique-12-bits.inoArduinomidi-piano.inoArduinopwm-respiration.inoArduinoservo-angle.inoArduino