Rockbox.Dsp (rockbox_ex_ffi v0.1.0)

Copy Markdown View Source

The DSP pipeline: EQ, tone, surround, compressor, ReplayGain, resampler.

A DSP handle wraps the process-wide audio DSP singleton, so only one should be alive at a time. The handle is a NIF resource — it is freed by the BEAM garbage collector, no explicit close needed.

ReplayGain mode here uses the DSP-native values (see rg_mode/0): 0 track, 1 album, 2 shuffle, 3 off.

Summary

Types

DSP ReplayGain mode: 0 track, 1 album, 2 shuffle, 3 off.

t()

Opaque DSP handle (a NIF resource).

Functions

Convert a little-endian int16 binary to a list of samples.

Create a DSP for interleaved S16LE stereo at sample_rate Hz.

Run interleaved stereo S16 samples through the pipeline. Accepts and returns a binary of little-endian int16 samples (use samples_to_binary/1 / binary_to_samples/1 to convert lists).

Convert a list of int16 samples to a little-endian binary.

Configure one EQ band (0..9). Band 0 low shelf, 9 high shelf.

ReplayGain mode (see rg_mode/0), clipping prevention, preamp in dB.

Per-track gains in plain dB / peaks as linear amplitude. Pass nil for an absent tag.

Native Q7.24 factors (the raw_* metadata fields); 0 = not tagged.

Types

rg_mode()

@type rg_mode() :: 0..3

DSP ReplayGain mode: 0 track, 1 album, 2 shuffle, 3 off.

t()

@opaque t()

Opaque DSP handle (a NIF resource).

Functions

binary_to_samples(bin)

@spec binary_to_samples(binary()) :: [integer()]

Convert a little-endian int16 binary to a list of samples.

eq_enable(d, enable)

@spec eq_enable(t(), boolean()) :: :ok

flush(d)

@spec flush(t()) :: :ok

new(sample_rate)

@spec new(pos_integer()) :: t()

Create a DSP for interleaved S16LE stereo at sample_rate Hz.

process(d, pcm)

@spec process(t(), binary()) :: binary()

Run interleaved stereo S16 samples through the pipeline. Accepts and returns a binary of little-endian int16 samples (use samples_to_binary/1 / binary_to_samples/1 to convert lists).

samples_to_binary(samples)

@spec samples_to_binary([integer()]) :: binary()

Convert a list of int16 samples to a little-endian binary.

set_channel_config(d, mode)

@spec set_channel_config(t(), integer()) :: :ok

set_compressor(d, threshold, makeup_gain, ratio, knee, release_time, attack_time)

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

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

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

Configure one EQ band (0..9). Band 0 low shelf, 9 high shelf.

set_eq_precut(d, db)

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

set_input_frequency(d, hz)

@spec set_input_frequency(t(), pos_integer()) :: :ok

set_replaygain(d, mode, noclip, preamp_db)

@spec set_replaygain(t(), rg_mode(), boolean(), number()) :: :ok

ReplayGain mode (see rg_mode/0), clipping prevention, preamp in dB.

set_replaygain_gains(d, track_gain_db, album_gain_db, track_peak, album_peak)

@spec set_replaygain_gains(
  t(),
  number() | nil,
  number() | nil,
  number() | nil,
  number() | nil
) :: :ok

Per-track gains in plain dB / peaks as linear amplitude. Pass nil for an absent tag.

set_replaygain_gains_raw(d, track_gain, album_gain, track_peak, album_peak)

@spec set_replaygain_gains_raw(t(), integer(), integer(), integer(), integer()) :: :ok

Native Q7.24 factors (the raw_* metadata fields); 0 = not tagged.

set_stereo_width(d, pct)

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

set_surround(d, delay_ms, balance, fx1, fx2)

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

set_tone(d, bass_db, treble_db)

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

set_tone_cutoffs(d, bass_hz, treble_hz)

@spec set_tone_cutoffs(t(), integer(), integer()) :: :ok