Rockbox.Player (rockbox_ex_ffi v0.3.0)

Copy Markdown View Source

Queue-based player with native ReplayGain and Rockbox crossfade.

A player owns a live audio output device and a background engine thread, so it only works where an output device exists. The handle is a NIF resource, freed by the BEAM garbage collector (which stops playback).

ReplayGain mode here uses the player values: 0 off, 1 track, 2 album. Crossfade mode: 0 off, 1 auto-skip, 2 manual-skip, 3 shuffle, 4 shuffle-or-manual, 5 always. Mix mode: 0 crossfade, 1 mix.

Piping

Every mutating/command function returns the player handle, so calls chain:

p
|> Player.set_queue(tracks)
|> Player.set_shuffle(true)
|> Player.set_repeat(:all)
|> Player.play()

Getters/queries (status/1, volume/1, queue/1, repeat/1, dsp_settings/1, resume/1, …) still return their values.

Summary

Types

t()

Opaque player handle (a NIF resource).

Functions

Delete the resume file (forget the saved state). Returns the player handle.

The full DSP-chain state as an atom-keyed map.

Append one track to the queue. path may be a local file path, an http(s):// URL to a finite remote file, or a live-radio / streaming URL.

Whether the equalizer is currently enabled.

Export the current queue to an .m3u8 file (atomic write).

Import an .m3u/.m3u8 playlist into the queue at position.

Insert file paths / URLs into the queue at position.

Replace the queue with an .m3u/.m3u8 playlist file.

Create a player on the default device with default settings.

Create a player with configuration overrides (see @default_config keys). sample_rate: 0 means the device default.

The current queue as a list of path/URL strings.

The current repeat mode as a Rockbox.RepeatMode atom (:off/:one/:all).

Restore the queue + exact position from the player's resume file (does NOT auto-play). Returns {:ok, %{tracks: [...], index: i, elapsed_ms: ms}} or {:error, :absent} when there is nothing to resume.

Persist the queue + exact position to the resume file now. Returns the player handle.

Set the bass tone axis in dB, leaving treble and cutoffs unchanged.

Override the bass tone shelf cutoff in Hz (0 = native default); gains unchanged.

Perceptual bass enhancement. strength is a percentage (0 = off); precut is in tenths of a dB (<= 0).

Channel mixing mode. Accepts a Rockbox.ChannelMode atom (e.g. :mono) or its integer code.

Dynamic-range compressor. threshold_db 0 disables it; the remaining arguments are makeup gain, ratio, knee, attack (ms) and release (ms).

Headphone crossfeed. mode accepts a Rockbox.CrossfeedMode atom (:off, :meier, :custom) or its integer code.

Enable or disable output dithering + noise shaping.

Configure one EQ band (0..10). cutoff_hz in Hz, q a Q factor, gain_db in dB.

Enable or disable the 10-band parametric equalizer.

Global EQ pre-cut in dB (attenuation applied before the bands).

Apply a built-in EQ preset. Accepts a Rockbox.EqPreset atom (e.g. :rock) or its integer code.

Auditory fatigue reduction: 0 off, 1 weak, 2 moderate, 3 strong.

Pitch/speed ratio (10000 = normal); pitch and tempo shift together.

Replace the queue. Each entry may be a local file path, an http(s):// URL to a finite remote file, or a live-radio / streaming URL.

Set the repeat mode. Accepts a Rockbox.RepeatMode atom (:off, :one, :all) or its integer code (0, 1, 2).

Enable or disable shuffle playback.

Custom stereo width in percent (audible with channel mode :custom).

Haas surround effect: delay_ms (0 = off), balance %, and the band-split cutoffs in Hz.

Bass/treble tone controls in dB, with band-split cutoffs in Hz (0 = the native defaults).

Set the treble tone axis in dB, leaving bass and cutoffs unchanged.

Override the treble tone shelf cutoff in Hz (0 = native default); gains unchanged.

Whether shuffle playback is currently enabled.

A snapshot of the player's status as an atom-keyed map.

Types

t()

@opaque t()

Opaque player handle (a NIF resource).

Functions

clear_resume(p)

@spec clear_resume(t()) :: t()

Delete the resume file (forget the saved state). Returns the player handle.

dsp_settings(p)

@spec dsp_settings(t()) :: map()

The full DSP-chain state as an atom-keyed map.

enqueue(p, path)

@spec enqueue(t(), Path.t()) :: t()

Append one track to the queue. path may be a local file path, an http(s):// URL to a finite remote file, or a live-radio / streaming URL.

eq_enabled?(p)

@spec eq_enabled?(t()) :: boolean()

Whether the equalizer is currently enabled.

export_m3u(p, path)

@spec export_m3u(t(), Path.t()) :: :ok | {:error, :export_failed}

Export the current queue to an .m3u8 file (atomic write).

import_m3u(p, path, position, index \\ 0)

@spec import_m3u(t(), Path.t(), Rockbox.InsertPosition.t() | 0..7, non_neg_integer()) ::
  {:ok, [String.t()]} | {:error, term()}

Import an .m3u/.m3u8 playlist into the queue at position.

Returns {:ok, [path, ...]} with the imported entries, or {:error, reason}. index is only used when position is :index (7).

insert(p, paths, position, index \\ 0)

@spec insert(t(), [Path.t()], Rockbox.InsertPosition.t() | 0..7, non_neg_integer()) ::
  t()

Insert file paths / URLs into the queue at position.

position is a Rockbox.InsertPosition atom (or its integer code); index is only used when position is :index (7).

load_m3u(p, path)

@spec load_m3u(t(), Path.t()) :: {:ok, [String.t()]} | {:error, term()}

Replace the queue with an .m3u/.m3u8 playlist file.

Returns {:ok, [path, ...]} with the loaded entries, or {:error, reason}.

new()

@spec new() :: t() | nil

Create a player on the default device with default settings.

new(opts)

@spec new(keyword() | map()) :: t() | nil

Create a player with configuration overrides (see @default_config keys). sample_rate: 0 means the device default.

Pass resume_file: "/path/to/state.m3u8" (optionally with resume_save_interval_ms:) to enable automatic queue+position persistence; restore it later with resume/1.

next(p)

@spec next(t()) :: t()

pause(p)

@spec pause(t()) :: t()

play(p)

@spec play(t()) :: t()

previous(p)

@spec previous(t()) :: t()

queue(p)

@spec queue(t()) :: [String.t()]

The current queue as a list of path/URL strings.

repeat(p)

@spec repeat(t()) :: Rockbox.RepeatMode.t()

The current repeat mode as a Rockbox.RepeatMode atom (:off/:one/:all).

resume(p)

@spec resume(t()) :: {:ok, map()} | {:error, :absent}

Restore the queue + exact position from the player's resume file (does NOT auto-play). Returns {:ok, %{tracks: [...], index: i, elapsed_ms: ms}} or {:error, :absent} when there is nothing to resume.

sample_rate(p)

@spec sample_rate(t()) :: non_neg_integer()

save_resume(p)

@spec save_resume(t()) :: t()

Persist the queue + exact position to the resume file now. Returns the player handle.

seek_ms(p, ms)

@spec seek_ms(t(), non_neg_integer()) :: t()

set_bass(p, bass_db)

@spec set_bass(t(), integer()) :: t()

Set the bass tone axis in dB, leaving treble and cutoffs unchanged.

set_bass_cutoff(p, hz)

@spec set_bass_cutoff(t(), integer()) :: t()

Override the bass tone shelf cutoff in Hz (0 = native default); gains unchanged.

set_bass_enhancement(p, strength, precut)

@spec set_bass_enhancement(t(), integer(), integer()) :: t()

Perceptual bass enhancement. strength is a percentage (0 = off); precut is in tenths of a dB (<= 0).

set_channel_mode(p, mode)

@spec set_channel_mode(t(), Rockbox.ChannelMode.t() | 0..6) :: t()

Channel mixing mode. Accepts a Rockbox.ChannelMode atom (e.g. :mono) or its integer code.

set_compressor(p, threshold_db, makeup_gain, ratio, knee, attack_ms, release_ms)

@spec set_compressor(
  t(),
  integer(),
  integer(),
  integer(),
  integer(),
  integer(),
  integer()
) :: t()

Dynamic-range compressor. threshold_db 0 disables it; the remaining arguments are makeup gain, ratio, knee, attack (ms) and release (ms).

set_crossfade(p, mode, fo_delay_ms, fo_dur_ms, fi_delay_ms, fi_dur_ms, mix_mode)

@spec set_crossfade(t(), 0..5, integer(), integer(), integer(), integer(), 0..1) ::
  t()

set_crossfeed(p, mode, direct_gain, cross_gain, hf_gain, hf_cutoff_hz)

@spec set_crossfeed(
  t(),
  Rockbox.CrossfeedMode.t() | 0..2,
  integer(),
  integer(),
  integer(),
  integer()
) :: t()

Headphone crossfeed. mode accepts a Rockbox.CrossfeedMode atom (:off, :meier, :custom) or its integer code.

direct_gain, cross_gain and hf_gain are in tenths of a dB (<= 0); hf_cutoff_hz is in Hz. The cross/high-frequency parameters only apply in :custom mode.

set_dither(p, enabled)

@spec set_dither(t(), boolean()) :: t()

Enable or disable output dithering + noise shaping.

set_eq_band(p, band, cutoff_hz, q, gain_db)

@spec set_eq_band(t(), 0..10, integer(), number(), number()) :: t()

Configure one EQ band (0..10). cutoff_hz in Hz, q a Q factor, gain_db in dB.

set_eq_enabled(p, enabled)

@spec set_eq_enabled(t(), boolean()) :: t()

Enable or disable the 10-band parametric equalizer.

set_eq_precut(p, db)

@spec set_eq_precut(t(), number()) :: t()

Global EQ pre-cut in dB (attenuation applied before the bands).

set_eq_preset(p, preset)

@spec set_eq_preset(t(), Rockbox.EqPreset.t() | 0..20) :: t()

Apply a built-in EQ preset. Accepts a Rockbox.EqPreset atom (e.g. :rock) or its integer code.

set_fatigue_reduction(p, strength)

@spec set_fatigue_reduction(t(), 0..3) :: t()

Auditory fatigue reduction: 0 off, 1 weak, 2 moderate, 3 strong.

set_pitch(p, ratio)

@spec set_pitch(t(), integer()) :: t()

Pitch/speed ratio (10000 = normal); pitch and tempo shift together.

set_queue(p, paths)

@spec set_queue(t(), [Path.t()]) :: t()

Replace the queue. Each entry may be a local file path, an http(s):// URL to a finite remote file, or a live-radio / streaming URL.

set_repeat(p, mode)

@spec set_repeat(t(), Rockbox.RepeatMode.t() | 0..2) :: t()

Set the repeat mode. Accepts a Rockbox.RepeatMode atom (:off, :one, :all) or its integer code (0, 1, 2).

set_replaygain(p, mode, preamp_db, prevent_clipping)

@spec set_replaygain(t(), 0..2, number(), boolean()) :: t()

set_shuffle(p, enabled)

@spec set_shuffle(t(), boolean()) :: t()

Enable or disable shuffle playback.

set_stereo_width(p, percent)

@spec set_stereo_width(t(), integer()) :: t()

Custom stereo width in percent (audible with channel mode :custom).

set_surround(p, delay_ms, balance, cutoff_low_hz, cutoff_high_hz)

@spec set_surround(t(), integer(), integer(), integer(), integer()) :: t()

Haas surround effect: delay_ms (0 = off), balance %, and the band-split cutoffs in Hz.

set_tone(p, bass_db, treble_db, bass_cutoff_hz, treble_cutoff_hz)

@spec set_tone(t(), integer(), integer(), integer(), integer()) :: t()

Bass/treble tone controls in dB, with band-split cutoffs in Hz (0 = the native defaults).

set_treble(p, treble_db)

@spec set_treble(t(), integer()) :: t()

Set the treble tone axis in dB, leaving bass and cutoffs unchanged.

set_treble_cutoff(p, hz)

@spec set_treble_cutoff(t(), integer()) :: t()

Override the treble tone shelf cutoff in Hz (0 = native default); gains unchanged.

set_volume(p, vol)

@spec set_volume(t(), number()) :: t()

shuffle_enabled?(p)

@spec shuffle_enabled?(t()) :: boolean()

Whether shuffle playback is currently enabled.

skip_to(p, index)

@spec skip_to(t(), non_neg_integer()) :: t()

status(p)

@spec status(t()) :: map()

A snapshot of the player's status as an atom-keyed map.

stop(p)

@spec stop(t()) :: t()

toggle(p)

@spec toggle(t()) :: t()

volume(p)

@spec volume(t()) :: float()