3 ms·
I wanted to create an mp3 player (not just wav) using a pico and found this repository very instructive: https://github.com/ikjordan/picosounds https://github.c
by beala 2y ago
I wanted to create an mp3 player (not just wav) using a pico and found this repository very instructive: https://github.com/ikjordan/picosounds https://github.com/ikjordan/picosounds
To handle decoding and the overhead of moving bits around, it uses a dual-buffer DMA approach. It reads data from an SD card, running the decoding routine on the main CPU. The decoded samples are written into one of two buffers. While one buffer is being written to, the other is read via DMA and sent to the PWM buffer (more on PWM audio here: https://x.com/beala/status/1826147833168408738 https://x.com/beala/status/1826147833168408738). Because DMA is used, data transfer can occur in parallel with decoding, without involving the main processor. When the bits have all been written to the PWM buffer, an interrupt triggers a buffer swap, and the process repeats.
I'm leaving out many details. Tuning the pwm speed to achieve correct playback speed was quite an adventure. And when I needed to increase the clock speed to play higher sample rates, this caused I/O errors with the SD card that I never managed to solve. Although I learned a lot from this process, I ultimately opted to use an MP3 module in my final build: https://store-usa.arduino.cc/products/dfplayer-a-mini-mp3-player https://store-usa.arduino.cc/products/dfplayer-a-mini-mp3-pl...
This is probably routine for an experienced embedded engineer, but it was quite a learning experience for me!
- JKCalhoun 2y agoI've got music-player on my short list of projects as well. I anticipate using a Teensy though. I'm pretty sure there are good libraries to handle everything you would need.
- mlyle 2y ago> And when I needed to increase the clock speed to play higher sample rates, this caused I/O errors with the SD card that I never managed to solve. Presumably if a RP2040 could almost do it, a RP2350 could do it no problem. Unless you were limited by PWM speed. Even then you might be able to accept less resolution and filter and dither.