Skip to main content

Python bindings for the Rockbox DSP / metadata / playback engine

Project description

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.

Project details


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.1.2.tar.gz (10.4 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.1.2-py3-none-manylinux_2_38_x86_64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.38+ x86-64

rockbox_ffi-0.1.2-py3-none-manylinux_2_38_aarch64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.38+ ARM64

rockbox_ffi-0.1.2-py3-none-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

rockbox_ffi-0.1.2-py3-none-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: rockbox_ffi-0.1.2.tar.gz
  • Upload date:
  • Size: 10.4 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.1.2.tar.gz
Algorithm Hash digest
SHA256 f7854b33cb1a747832e5c88fab689af6d7c4adc60a7332b3563740e39da5020a
MD5 6693ce7589a5ae380c5cc6cd560de5d5
BLAKE2b-256 759eddcf4e4e2c849a096afe94164a4fff14a04956951a1441d2b6f08088c765

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.2-py3-none-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 14b30bbe4acd4c64577849c51c927c0606ea9de007e143b88900e45cd6efad31
MD5 4f176183a353a85ed07612e5104765e0
BLAKE2b-256 93e657181f75293a5c62b3d6b3f7021ff7e8bd97e5f06d31f5cc818ca6e5b9e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.2-py3-none-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 3cde8753937b45585412c6d1a5f32b0341f714b76266da0d2fc3f672770e1234
MD5 f7a7154c9f9ceed0866729fa82e90daa
BLAKE2b-256 745609a922d8ffa9777ac5483542efd548005412047d0a3020540a21a379bc77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 43775c5842cae1bd0246ed70f2cf3e8214d5ac1f05c898721682591730e7603b
MD5 dda61a0cf4019537d6040012ecda1290
BLAKE2b-256 f1cff817faaca3ea8911fdf4d81770847acf18e80f4b4d56fa85b03be6749166

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.2-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 50670e3a4650ff3c2b6af8b085237978bd0bf665f880b0158f613b9838ce5a84
MD5 1d8a87e5f07d921be5aec4e63e387242
BLAKE2b-256 ab6687bdb0c5efbd11b705453050a2d7340afca87ece0d0029c7479aad431525

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page