Skip to main content

rockbox-ffi (Python)

PyPI Python FFI uv License

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 / streaming URLs — mix and match freely.
    player.set_queue(["a.flac", "https://example.com/b.mp3", "http://radio.example/stream"])
    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_replaygainDspReplayGainMode (TRACK=0, ALBUM=1, SHUFFLE=2, OFF=3)
  • Player.set_replaygainReplayGainMode (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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rockbox_ffi-0.5.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rockbox_ffi-0.5.1-py3-none-manylinux_2_38_x86_64.whl (2.4 MB view details)

Uploaded Python 3manylinux: glibc 2.38+ x86-64

rockbox_ffi-0.5.1-py3-none-manylinux_2_38_aarch64.whl (2.5 MB view details)

Uploaded Python 3manylinux: glibc 2.38+ ARM64

rockbox_ffi-0.5.1-py3-none-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

rockbox_ffi-0.5.1-py3-none-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file rockbox_ffi-0.5.1.tar.gz.

File metadata

  • Download URL: rockbox_ffi-0.5.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for rockbox_ffi-0.5.1.tar.gz
Algorithm Hash digest
SHA256 dea01a53a1ebf48f5449e6ef0475b4fb87d3ce0304e565433613ab47a5e9ac0b
MD5 ae0331eb656eae7e108d8743b804fb1f
BLAKE2b-256 186dfea43a082cb5d872390ba1d2de96340be701a6cf7437365668687d9c149e

See more details on using hashes here.

File details

Details for the file rockbox_ffi-0.5.1-py3-none-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for rockbox_ffi-0.5.1-py3-none-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 ed1458e2a5f3ba816b3db5987af54463b68e5dc57c6c2c7cc1f5da5bb5017835
MD5 ecb49281dd544305005a42e3b1523f0a
BLAKE2b-256 e9b2ee08a24b599981088b42447df3ea106d33bfa384beaaf91d2f7b6c7d6f64

See more details on using hashes here.

File details

Details for the file rockbox_ffi-0.5.1-py3-none-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for rockbox_ffi-0.5.1-py3-none-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 01e25443a832d38d1010199f239956e35494476f09405d8db3c7b94cc7019aa6
MD5 23457127b8e3ec1aa758bf09d749ad77
BLAKE2b-256 cb849d94078dfd5f7865bb986cec97457289f2b832b926060de2c43a36c47003

See more details on using hashes here.

File details

Details for the file rockbox_ffi-0.5.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rockbox_ffi-0.5.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 21a2f28bb9ea87bb159e09ea86cde0b500c15e67b8df267557580a6a6de8675c
MD5 fc2cdedb4d390daf65bfb86fbfbb1b6e
BLAKE2b-256 2130bed1dcd45e2cb901f3fa1245af071a1eafded03e8e8fddcd2f9ab6bab315

See more details on using hashes here.

File details

Details for the file rockbox_ffi-0.5.1-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rockbox_ffi-0.5.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 573baa6f1168f26ce9374613832bff317875f3fbf229421a53f6ffe48325e126
MD5 b413d3f0f032334c1a04b7f588528ade
BLAKE2b-256 7901545e1b3062ca2e186e78e5e3776aeeab620b996300a03d13c5941615a7de

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.0

5 files

This release

0.5.1 This release

5 files

0.5.0

5 files

0.4.0

5 files

0.3.0

5 files

0.2.0

5 files

0.1.2

5 files

0.1.0

6 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page