rockbox-ffi (Python)
Python bindings for the Rockbox DSP, metadata, codecs, and
playback engine, via cffi (ABI mode) over the prebuilt
librockbox_ffi shared library.
📖 Sound settings reference — the equalizer, tone, crossfeed, compressor and other DSP controls mirror Rockbox's own. See the official Rockbox manual — Sound Settings.
Setup
Build the shared library once (from the repo root):
cargo build --release -p rockbox-ffi
Then install the Python package with uv:
cd bindings/python
uv venv
uv pip install -e .
uv run python examples/smoke.py
The library is located automatically by walking up to
target/release/librockbox_ffi.{dylib,so}. Override with the
ROCKBOX_FFI_LIB environment variable.
Interactive console
uv pip install -e '.[dev]' # installs IPython
uv run python console.py
Drops into IPython with rb, metadata, Dsp, Player, the enums, and a
FIXTURE sample track preloaded (falls back to the plain REPL without
IPython):
metadata.read(str(FIXTURE))["title"] # 'Speak'
p = Player(volume=0.6)
p.set_queue([str(FIXTURE)]); p.play()
p.status()["state"] # 'playing'
Usage
import rockbox_ffi as rb
from rockbox_ffi import Dsp, Player, metadata
from rockbox_ffi.enums import DspReplayGainMode, ReplayGainMode, CrossfadeMode
# --- metadata ---------------------------------------------------------
meta = metadata.read("song.flac")
print(meta["artist"], "—", meta["title"], meta["duration_ms"], "ms")
print(metadata.probe("track.opus")) # -> "Opus"
# --- DSP (interleaved stereo int16) -----------------------------------
with Dsp(44100) as dsp:
dsp.eq_enable(True)
dsp.set_eq_band(0, cutoff_hz=60, q=0.7, gain_db=3.0)
dsp.set_replaygain(DspReplayGainMode.TRACK, noclip=True, preamp_db=0.0)
dsp.set_replaygain_gains(track_gain_db=-6.02) # halves amplitude
processed = dsp.process(samples) # array('h')
# --- codecs (decode a file to PCM, one chunk at a time) ---------------
from rockbox_ffi import Decoder
with Decoder("song.flac") as dec:
print(dec.metadata()["title"]) # tags from the open file
for samples, sample_rate in dec.chunks(): # array('h'), Hz
... # interleaved-stereo int16 PCM
print(dec.finished()) # (True, 0) (0 = clean end)
# --- playback (needs an output device) --------------------------------
with Player(volume=0.8) as player:
player.set_replaygain(ReplayGainMode.TRACK, preamp_db=0.0, prevent_clipping=True)
player.set_crossfade(CrossfadeMode.ALWAYS)
# Queue entries may be local files, http(s):// URLs to remote media,
# or live-radio streams, or HLS / MPEG-DASH manifests (.m3u8/.mpd) — mix and match freely.
player.set_queue(["a.flac", "https://example.com/b.mp3", "http://radio.example/stream", "https://cdn.example.com/live/main.m3u8"])
player.play()
print(player.status()) # {'state': 'playing', 'index': 0, ...}
API
| Module | Contents |
|---|---|
rockbox_ffi.metadata |
read(path) -> dict, probe(filename) -> str | None |
rockbox_ffi.Dsp |
EQ / tone / surround / compressor / ReplayGain, process(samples) |
rockbox_ffi.Decoder |
codec engine: metadata(), chunks() / next_chunk(), seek_ms(), finished() |
rockbox_ffi.Player |
queue + transport + crossfade + ReplayGain, status() -> dict |
rockbox_ffi.enums |
DspReplayGainMode, ReplayGainMode, CrossfadeMode, MixMode, … |
Two ReplayGain encodings
The DSP and player use different mode integers (a quirk of the C ABI):
Dsp.set_replaygain→DspReplayGainMode(TRACK=0, ALBUM=1, SHUFFLE=2, OFF=3)Player.set_replaygain→ReplayGainMode(OFF=0, TRACK=1, ALBUM=2)
Use the named enums and you won't have to remember which is which.
Memory
All heap allocations crossing the FFI boundary (JSON strings, sample
buffers) are freed inside the wrappers — you never call a *_free yourself.
Metadata
Release files for rockbox-ffi 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rockbox_ffi-0.7.0.tar.gz | 15.9 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| rockbox_ffi-0.7.0-py3-none-manylinux_2_38_x86_64.whl | Python 3 | none | Linux glibc 2.38+ x86-64 | Details |
| rockbox_ffi-0.7.0-py3-none-manylinux_2_38_aarch64.whl | Python 3 | none | Linux glibc 2.38+ ARM64 | Details |
| rockbox_ffi-0.7.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
| rockbox_ffi-0.7.0-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details |
Total release size: 9.8 MB
Release files / rockbox_ffi-0.7.0.tar.gz
| Download URL | rockbox_ffi-0.7.0.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2486bd51fce30d645d68d94549b342e16e3e5241dda1549fde5d77f1de2215c8
|
|
BLAKE2b-256 checksum How to use checksums |
a631b993e7335a3b0c5d5f439c283c85ebe26b76ad619839b5b81924cfd55615
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / rockbox_ffi-0.7.0-py3-none-manylinux_2_38_x86_64.whl
| Download URL | rockbox_ffi-0.7.0-py3-none-manylinux_2_38_x86_64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | Linux glibc 2.38+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
fb84aa0ef1ea33e4a270ff877726001c63e19ab7a49f502f7f0da7ef428d652d
|
|
BLAKE2b-256 checksum How to use checksums |
caad22075ebf7ce854d9eee7a73f72273eb55cb8ba144d10175064d82dc97a05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / rockbox_ffi-0.7.0-py3-none-manylinux_2_38_aarch64.whl
| Download URL | rockbox_ffi-0.7.0-py3-none-manylinux_2_38_aarch64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | Linux glibc 2.38+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
d8c3f2264ebeaf210755ac7b7e87f297e34a32a56a695db59eb553b8aa794aca
|
|
BLAKE2b-256 checksum How to use checksums |
81fec66246ada9a88abf274852beda80033ded50852813723a106c95e83ce95d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / rockbox_ffi-0.7.0-py3-none-macosx_11_0_arm64.whl
| Download URL | rockbox_ffi-0.7.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5679327a592b929e27ef6a8c963d5a9f0395333d432951cbc7f58da0e01ea22d
|
|
BLAKE2b-256 checksum How to use checksums |
9726e7ffe16db16b19cd851dd48e688e58e19c89cbd2598a3820772a463506de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / rockbox_ffi-0.7.0-py3-none-macosx_10_12_x86_64.whl
| Download URL | rockbox_ffi-0.7.0-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.3 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
f5d9030478952735bfa8c53272336441f6019ef7ba61edb43d100ac07769955b
|
|
BLAKE2b-256 checksum How to use checksums |
53c4068e54da7cba8f0ea528cdb9c122a362012c30c9925e416aa381ad6ccc91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|