🛠 Network I2S Audio Streaming with MAX98357A
Objectifs
This advanced tutorial aims to build an autonomous network audio node. The goal is to receive PCM audio streams over a local network (Wi-Fi or Ethernet) and transmit them via the I2S bus to the MAX98357A stereo amplifier board for direct speaker output. We will explore DMA buffer management to avoid audio artifacts and precise I2S configuration without an MCLK signal.
Matériel nécessaire
- Adafruit Stereo I2S 3W Amplifier Breakout (MAX98357A)
- Microcontroller with I2S and Wi-Fi/Ethernet support (e.g., ESP32-S3 or Teensy 4.1)
- 4Ω or 8Ω Speakers (max 3W)
- Stable external 5V power supply (quiescent current is low, but 3W peaks require a robust source)
- Connecting wires and resistors if needed for gain adjustment
Étapes
- Hardware Configuration: Connect the microcontroller's I2S pins to the MAX98357A's corresponding inputs: BCLK (Bit Clock), LRC (Left/Right Clock, also called WS), and DIN (Data In). Note that the MAX98357A does not require MCLK (Master Clock), simplifying wiring. Connect speaker outputs (SPK+ and SPK-) directly to the speaker terminals. Ensure supply voltage is between 2.7V and 5.5V.
- Gain Adjustment: By default, gain is fixed. For this use case, we aim for standard line level. Check the board's jumpers or resistors to select 9dB or 12dB gain, offering a good compromise between dynamics and noise floor (25µV RMS).
- I2S Software Configuration: Configure the microcontroller's I2S peripheral in master mode. Set the sampling frequency (e.g., 44.1kHz or 48kHz) and bit depth (16-bit or 24-bit). Enable DMA (Direct Memory Access) to transfer audio data from the network buffer to the I2S line without CPU intervention, crucial for stream stability.
- Network Implementation: Set up a UDP or TCP server on the microcontroller. Write a routine that listens for incoming audio packets, fills a circular buffer (FIFO), and triggers DMA transfer once the buffer is full. Handle network errors with silent padding (mute) to avoid clicks.
- Protection and Commissioning: The MAX98357A has thermal and short-circuit protections. Never short-circuit the outputs. Power on the system, send a test audio stream via your local network, and adjust source volume if necessary.
Vérification
Listen to a known audio file. The sound should be clear, with no distortion at moderate volume (Class D efficient at 92%). Verify the absence of background noise when silence is sent. Use an oscilloscope to confirm that BCLK and LRC signals are stable and synchronized with DIN data.
Pour aller plus loin
Integrate an external DAC to compare quality, or add digital volume control (DSP) before the I2S stage. You can also explore multiplexing multiple I2S channels for a multi-room system.