ESP32-C3: support audio file playback (SPI SD card and I2S audio out) (QEMU-297)#158
Draft
dragonx wants to merge 4 commits into
Draft
ESP32-C3: support audio file playback (SPI SD card and I2S audio out) (QEMU-297)#158dragonx wants to merge 4 commits into
dragonx wants to merge 4 commits into
Conversation
added 3 commits
February 24, 2026 21:44
Currently only verified support for 16 bit output, in mono and stereo, and at 44.1kHz and 48kHz.
- Enable SPI2 DMA for reading from SD card - fix issue with GDMA int register stride - fix issue with deferred delivery in intmatrix - Pull up SPI MISO line when idle, setting it to 0x0 caused driver to interpret as SD card being busy.
# Conflicts: # hw/riscv/esp32c3_intmatrix.c # hw/ssi/meson.build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds just enough support to emulate audio playback from SD card on an emulated esp32-c3, specifically with MicroPython 1.26/1.27 (haven't tested 1.28 yet).
We add GDMA support for SPI2 read, and verified that mounting and reading a FAT16 SD card image works in MicroPython.
I2S0 output has been tested using the MicroPython
I2Sclass, and has been tested with very limited scenarios: 16-bit, 44.1/48kHz, mono and stereo, that's all.The emulated I2S0 device has an optional chardev sink for the PCM it drains from the I2S TX DMA stream. Attach any QEMU chardev with:
Capture to a file for offline inspection:
Or stream live over a (websocket-capable) socket, e.g.:
The stream is raw interleaved signed 16-bit little-endian PCM at the configured sample rate / channel count. Buffer consumption is paced to ~real time from the I2S clock registers, so the capture runs at roughly the audio's natural duration.
Testing
Tested with micropython 1.26/1.27. A FAT SD Card image was created with multiple MP3 files, and mounted using:
I2S was initialized in MicroPython:
MP3 files were decoded and played back using the
esp-adflibrary.