Skip to main content

rockbox-ffi (Python)

PyPI Python FFI uv License

Python bindings for the Rockbox DSP, metadata, and playback engine, via cffi (ABI mode) over the prebuilt librockbox_ffi shared library.

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')

# --- 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)
    player.set_queue(["a.flac", "b.mp3", "c.opus"])
    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.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.2.0.tar.gz (11.7 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.2.0-py3-none-manylinux_2_38_x86_64.whl (2.4 MB view details)

Uploaded Python 3manylinux: glibc 2.38+ x86-64

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

Uploaded Python 3manylinux: glibc 2.38+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

rockbox_ffi-0.2.0-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.2.0.tar.gz.

File metadata

  • Download URL: rockbox_ffi-0.2.0.tar.gz
  • Upload date:
  • Size: 11.7 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.2.0.tar.gz
Algorithm Hash digest
SHA256 4b9d69750d5fa8f5be8b64c16670a501618850a8f291bba9f104a9eebb209052
MD5 c92a8b54c16d9bce4481a19097ae0c1b
BLAKE2b-256 04ddc7494a090d6536fdb61fa9a7f78a83aa72ed3c6c28be751c259495021a9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.2.0-py3-none-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 10091ec454fb462be965e058eaf4b566291ec6d139c41a6af7ce9aa966e9b3cb
MD5 59bc71cdff66a1e17706cd758fa0c346
BLAKE2b-256 f7601813a9abfa2b7c1f3f303a05691902d67c9d9e35c1b3d82a5846062a0e27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.2.0-py3-none-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 9906f7e2eaab533835cda27d4c2b100c5b940d8a4f1faba21f05b647706e04eb
MD5 3b40c2dd1e31d30ace21154c659491bd
BLAKE2b-256 d9c1038c313b41aae25e0c896efbec33d573e71b45313666be44231cb13ce113

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9e6e3496fc529413405d9f9a8b1914747eeab2e9148c64ddc6a482a6b36718d
MD5 4ffe788cfe1be770a78e0db8fe77816c
BLAKE2b-256 b0444069a24e9e9cdf6cf74afa6415b91761675a886edfad2df6540ae1a2185c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.2.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 92fc2335d9aa52266a3faebfd29431885717d8637d3a37ac97a2c3475ca2e33c
MD5 dc70ad0cd1e7bc3ac329c73d0b267926
BLAKE2b-256 42909a3317850ed10ceeb05fa62c305729a129c1c804ba51f8aa8b9236976111

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.0

5 files

0.5.1

5 files

0.5.0

5 files

0.4.0

5 files

0.3.0

5 files

This release

0.2.0 This release

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