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.

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

Uploaded Python 3manylinux: glibc 2.38+ x86-64

rockbox_ffi-0.1.0-py3-none-manylinux_2_38_aarch64.whl (1.1 MB view details)

Uploaded Python 3manylinux: glibc 2.38+ ARM64

rockbox_ffi-0.1.0-py3-none-macosx_11_0_arm64.whl (984.1 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

rockbox_ffi-0.1.0-py3-none-macosx_10_12_x86_64.whl (1.0 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

rockbox_ffi-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rockbox_ffi-0.1.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rockbox_ffi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2e16f89a0958065a173b646b479449ef9294d861bfd49d9a88367dc7c7878ccd
MD5 cbf8ebf250c4eededf4fd8077155cd82
BLAKE2b-256 9be3131a711120741f36d5df149f127daaa659a8487b628d2fd62271a3e61157

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.0-py3-none-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 fc5d976aa9e17726b95810661927a50df466fb3a63ee75b0d48c3aac93255e17
MD5 2aabd8f8c270cc00f618cb14e496a644
BLAKE2b-256 4cbfb569f4018687b7cc452df9a073726f3080bb67c5240749090931d373c674

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.0-py3-none-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 d579ea955b8b0e9dcecb97d5b269c17b3af616bf0217a8cafbbe5748133a36df
MD5 dd2ee92ea6e1d3be722f0d5c7d835596
BLAKE2b-256 b9c7b5e0ff30f79350755157c9dfc3c24800444f7f83173a82dd914fac7b6da9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 506e4454f54704b7dfcffa5f38146d9c56a92dcf00060334dd5cb5e5ff85c465
MD5 0354851a8d7f63b99b725dca7d01f990
BLAKE2b-256 693e58262142408f7d8db4514447088186d094487b6629c37835cedcf08b2f62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rockbox_ffi-0.1.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9cf3d6d6bf3da5e919d7141a7dbc27179de0ffd78fbe81d9d369f8ef49dde694
MD5 7f803053ca3924840e9b995852c6750d
BLAKE2b-256 7ef21647d1b476c0d128c91259b9168afdcef131eaefb8bea81d6fa939a95a7f

See more details on using hashes here.

File details

Details for the file rockbox_ffi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rockbox_ffi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rockbox_ffi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24c9c969136f7cede388b5652a493c3e0c2cef4a4c8d29ae6fe39b6155eafa0e
MD5 50f12037c23e5dee8453aa7ebf887648
BLAKE2b-256 d17fa0f6dfaba9ca2ecc901af91507b0b5a1128a6383722cc080fc97d2ce7bbf

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