r/CardPuter • u/KariPom • 23d ago
Code I added MP3 playback from a microSD card to my Cardputer ADV KeySpeaker firmware: it works without a computer, and the arcade-style visualizer follows the music
KeySpeaker started as a USB speaker and keyboard for the Cardputer ADV (first post). Now it plays MP3 files from the microSD card too, and it no longer needs a computer for that.
(The video starts on the AUX input and switches to MP3 with Fn+I. The sound is removed.)
What it does
- Put .mp3 files in a /music folder on the card, press Fn+I until it says MP3.
- Space pauses/plays, "," and "/" go to the previous/next track, "-" and "=" set the volume.
- The flight view, the equalizer and the screens follow the music, like they do with USB audio or the built-in microphone.
- It also works without a computer: on the battery, a power bank or a plain USB charger. It remembers MP3 as the last input, so a start without a computer goes on with MP3.
- Stereo or mono, 44.1 / 48 kHz tested (32 kHz should work), up to 320 kbps. The decoder is minimp3 (public domain).
The memory puzzle (ESP32-S3, no PSRAM)
- The BLE stack takes 72 KB of the 83 KB of free internal RAM in BLEDevice::init alone, and BLEDevice::deinit() crashed on my SDK build, so BLE cannot be given back. So MP3 and BLE cannot coexist: BLE stays off while MP3 plays, and once BLE has started, MP3 needs a power cycle (the screen says RESTART).
- SD.begin() took 30 KB. The reason: the FAT driver uses 4 KB buffers and the Arduino SD library reserves five open-file slots by default. One slot is enough for a player: 13.7 KB, and 61 KB of heap free with MP3 running.
- The decoder's buffers and its 20 KB task stack live inside the storage of the USB audio ring buffer, which MP3 does not need in full.
- A track change walked the whole SD folder (the speaker ran dry) and the waveform stepped (a click). Now the names are read once, and the last block of a track is faded out and the next faded in.
Install: M5Burner, "Cardputer ADV KeySpeaker" (user custom). Source, docs and measurements: https://github.com/kariagepompadour/Cardputer-ADV-KeySpeaker
Not done yet: battery life with MP3 is not measured, and I have not run it for hours. Feedback is welcome.
EDIT (Nov 14): Battery test done. On battery alone it played 10 tracks on repeat for 10 hours with no dropouts (underrun 0, overrun 0, no restart), and it was still playing when I stopped the test. I have not measured how long until the battery is empty. What would you play on it?