An MP3 player core for the Analogue Pocket (openFPGA). The decoder is pure hardware. There is no soft CPU and no firmware. The core reads the bit stream, decodes the Huffman data, requantizes it, does the stereo processing, the IMDCT and the polyphase synthesis, and resamples the result — all of it in SystemVerilog on the Cyclone V.
Version 0.3.2 — tested on hardware.
- MPEG-1 Layer III decoder, 32–320 kbps, CBR and VBR
- 48 kHz plays natively; 44.1 kHz is resampled to 48 kHz
- Mono, stereo, joint stereo (MS) and dual channel
- Transport control: play, pause, stop, seek with acceleration, repeat
- ID3v2.3, ID3v2.4 and ID3v1 tags on screen
- On-screen display with time, progress bar and codec data
- File size up to 64 MB (the file goes into SDRAM)
Get neoge.MP3Player_<version>_<date>.zip from the
releases page. Extract it to the
root of the SD card. It makes this tree:
/Cores/neoge.MP3Player/ 7 JSON files, info.txt, icon.bin, bitstream.rbf_r
/Platforms/pocketmp3.json
/Platforms/_images/pocketmp3.bin
/Assets/pocketmp3/common/ put your .mp3 files here
Then open openFPGA > Media > MP3 Player on the Pocket and select an MP3 file. Playback starts automatically.
The repository has the JSON files and the art, but not the bit stream. To get
the same tree from source, do a build — tools/build.sh writes it to dist/,
and tools/mkrelease.sh packs dist/ into the release ZIP.
pupdate can also install and update
the core. It reads the openFPGA cores inventory and unpacks the release ZIP to
the card root, which is the layout that mkrelease.sh makes.
If the core does not appear in the menu, delete the files System/*cache*.bin
from the SD card. Then do a full power cycle. Sleep mode is not sufficient.
| Button | Action |
|---|---|
| A | Play / pause |
| B | Stop |
| D-pad Left / Right | Seek −10 s / +10 s |
| D-pad Up / Down | Seek +20 s / −20 s |
| Select + D-pad | Seek ±1 s |
| Start | Repeat on / off |
| Seek key pressed again quickly | The step becomes two times larger, up to ×32 |
The core shows a 320×240 display:
- Header line with the core name and the version
- Title, artist and album from the ID3 tag
- Codec line with the bit rate, the sample rate and the channel mode
- Elapsed time and track length, with
RPTat the right while repeat is on - Progress bar
- MPEG-1 Layer III only. Layer I, Layer II, MPEG-2 and MPEG-2.5 do not play.
- A 32 kHz file decodes, but it plays at the incorrect speed. The resampler does 44.1 → 48 kHz only.
- The track length and the seek position use a constant-bit-rate calculation. A VBR file thus shows an incorrect length, and the seek position is not accurate. The core does not read the XING TOC.
- The core does not decode intensity stereo. It passes those bands through. LAME and other usual encoders make MS stereo only.
- The core decodes a mixed block as a long block. Usual encoders do not make mixed blocks.
- The core sets
sleep_supported: false. Thus the Pocket does not keep the core in sleep mode.
The APF bridge writes the selected file into SDRAM: slot capture → byte expansion → asynchronous FIFO → SDRAM controller (CL = 2, BL = 1, per-byte DQM writes). A streaming reader then gives the bytes to the decoder.
The decoder does these steps: frame sync, side info, scalefactors, Huffman decode, requantization, stereo processing, alias reduction, IMDCT, polyphase synthesis and the 44.1 → 48 kHz resampler. The PCM goes through an audio FIFO to the I²S output at 48 kHz, with an MCLK/LRCK ratio of 256. The FIFO also controls the speed: the decoder stops while the FIFO is almost full, thus the pipeline runs in real time.
id3_capture reads the tag from the load stream, and playback_fsm controls
play, pause, stop, seek and repeat.
You need Quartus Prime Lite 25.1std. The device is 5CEBA4F23C8, which the
Analogue Pocket Framework (APF) sets.
python3 tools/gen_roms.py # font, IMDCT, polyphase, FIR and pow ROMs
python3 tools/gen_huff_lut.py # Huffman tree ROMs
./tools/build.sh # Quartus flow, .rbf -> .rbf_r, package dist/
build.sh compiles the Quartus project src/fpga/ap_core, reverses the bits of
the .rbf into the APF .rbf_r format, and puts the result into dist/. Set
QUARTUS_BIN if Quartus is not in /opt/intelFPGA/25.1/quartus/bin.
The current build uses 9793 ALMs (53 %), 79 M10K blocks (26 %), 22 DSP blocks (33 %) and 1 PLL. The PLL makes 133.12 MHz for the SDRAM and the decoder, and 12.288 MHz for the pixel clock and the audio MCLK.
Do these tests before each hardware build:
sim/build_sim.sh # Verilator model of mp3_decoder
(cd assets && /tmp/pocketmp3_sim/tb_mp3 ../sim/test44.mp3 /tmp/out.raw)
ffmpeg -i sim/test44.mp3 -f s16le -ar 48000 -ac 2 /tmp/ref.raw # reference
sim/compare.py /tmp/ref.raw /tmp/out.raw # SNR against the reference
sim/run_mem_sim.sh sdram # bridge -> SDRAM -> reader, byte-exact
sim/run_mem_sim.sh core # the same path with the real decoder
sim/run_mem_sim.sh audio # I2S serializer: LRCK rate and data
sim/run_mem_sim.sh buttons # seek, clamps, acceleration, repeat
sim/run_mem_sim.sh id3 # ID3v2.3, ID3v2.4 and the v1 fallback
The memory-path tests use Icarus, because that path needs tri-state signals.
Always do them after a change to src/fpga/sdram_*.sv or apf_bridge.sv.
The decoder gives 37.2 dB SNR on test48.mp3 (48 kHz stereo) and 27.0 dB on
test44.mp3 (44.1 kHz, thus with the resampler). sim/golden.py is a Python
model of the scalefactor and Huffman stages. The RTL Huffman decoder is bit-exact
against it.
pocket-mp3/
├── core/ APF core files (7 JSON files and info.txt)
├── Platforms/ Platform metadata for the Pocket menu
├── src/fpga/ SystemVerilog sources, the Quartus project and the APF framework
├── assets/ ROM data (.hex) and the Pocket menu art
├── sim/ testbenches, test files and the compare script
├── tools/ ROM generators, the build script and the release packer
└── dist/ the SD-card tree
The code of this project is under the MIT license. See LICENSE.
The files in src/fpga/apf/ and src/fpga/core/ are different. They come from
the official openFPGA core template
and stay under the Analogue Pocket EULA. Do not relicense them. See
src/fpga/VENDOR_NOTICE.md.
