pub struct Dsp { /* private fields */ }Expand description
Safe wrapper around the audio DSP instance for interleaved 16-bit stereo.
The underlying dsp_config is a static singleton (CODEC_IDX_AUDIO), so
only one Dsp may exist at a time and it is not Send/Sync.
Implementations§
Source§impl Dsp
impl Dsp
Sourcepub fn new(sample_rate: u32) -> Self
pub fn new(sample_rate: u32) -> Self
Set up the audio DSP for interleaved S16LE stereo at sample_rate,
output at the same rate (no resampling).
pub fn raw(&mut self) -> *mut dsp_config
Sourcepub fn set_input_frequency(&mut self, hz: u32)
pub fn set_input_frequency(&mut self, hz: u32)
Change the input sample rate (e.g. on track change); the resampler stage engages automatically when it differs from the output rate.
pub fn eq_enable(&mut self, enable: bool)
Sourcepub fn set_tone(&mut self, bass_db: i32, treble_db: i32)
pub fn set_tone(&mut self, bass_db: i32, treble_db: i32)
Bass/treble tone controls — shelving filters at fixed cutoffs
(200 Hz bass, 3.5 kHz treble). Gains in plain dB, matching
rockboxd’s bass / treble settings.toml keys. 0/0 disables
the stage. Mirrors firmware sound.c: values ×10, prescale by
the larger boost to avoid clipping.
Sourcepub fn set_tone_cutoffs(&mut self, bass_hz: i32, treble_hz: i32)
pub fn set_tone_cutoffs(&mut self, bass_hz: i32, treble_hz: i32)
Override the tone-control shelf cutoffs in Hz (0 = defaults:
200 Hz bass, 3500 Hz treble). Call before Dsp::set_tone — the
coefficients are recomputed by its prescale step.
Sourcepub fn set_surround(&mut self, delay_ms: i32, balance: i32, fx1: i32, fx2: i32)
pub fn set_surround(&mut self, delay_ms: i32, balance: i32, fx1: i32, fx2: i32)
Haas surround. delay_ms > 0 enables the stage (rockboxd’s
surround_enabled key IS the delay in ms, 0 = off); balance in
percent, fx1/fx2 are the band-split cutoffs in Hz. Argument
order mirrors apps/settings.c: balance, cutoffs, then enable.
Sourcepub fn set_channel_config(&mut self, mode: i32)
pub fn set_channel_config(&mut self, mode: i32)
Channel configuration (SOUND_CHAN_*: stereo / mono / custom /
karaoke / swap …).
Sourcepub fn set_stereo_width(&mut self, percent: i32)
pub fn set_stereo_width(&mut self, percent: i32)
Stereo width in percent — only audible when the channel config is
SOUND_CHAN_CUSTOM (100 = unchanged, 0 = mono, >100 = wider).
Sourcepub fn set_compressor(&mut self, settings: &compressor_settings)
pub fn set_compressor(&mut self, settings: &compressor_settings)
Dynamic-range compressor; threshold of 0 disables the stage.
Sourcepub fn set_replaygain(&mut self, mode: i32, noclip: bool, preamp_db: f32)
pub fn set_replaygain(&mut self, mode: i32, noclip: bool, preamp_db: f32)
Replaygain mode (REPLAYGAIN_TRACK / _ALBUM / _SHUFFLE /
_OFF), clipping prevention, and preamp in plain dB. This is the
per-player setting; the per-track values come from
Dsp::set_replaygain_gains — both are needed before the
pre-gain stage engages.
Sourcepub fn set_replaygain_gains(
&mut self,
track_gain_db: Option<f32>,
album_gain_db: Option<f32>,
track_peak: Option<f32>,
album_peak: Option<f32>,
)
pub fn set_replaygain_gains( &mut self, track_gain_db: Option<f32>, album_gain_db: Option<f32>, track_peak: Option<f32>, album_peak: Option<f32>, )
Per-track replaygain values as tagged in the file’s metadata:
gains in plain dB, peaks as linear peak amplitude (1.0 = full
scale), None = tag absent. Call on every track change — the
DSP_RESET issued by Dsp::new zeroes the gains but keeps the
mode from Dsp::set_replaygain.
Sourcepub fn set_replaygain_gains_raw(
&mut self,
track_gain: c_long,
album_gain: c_long,
track_peak: c_long,
album_peak: c_long,
)
pub fn set_replaygain_gains_raw( &mut self, track_gain: c_long, album_gain: c_long, track_peak: c_long, album_peak: c_long, )
Native-unit variant of Dsp::set_replaygain_gains: Q7.24 linear
factors exactly as Rockbox’s metadata parser stores them in
mp3entry (get_replaygain_int output), 0 = not tagged.
Sourcepub fn set_eq_band(&mut self, band: usize, cutoff_hz: i32, q: f32, gain_db: f32)
pub fn set_eq_band(&mut self, band: usize, cutoff_hz: i32, q: f32, gain_db: f32)
Configure one EQ band. Band 0 is a low shelf, band EQ_NUM_BANDS-1
a high shelf, the rest are peaking filters. q and gain_db are in
plain units here; the ×10 fixed-point convention is applied inside.
Sourcepub fn set_eq_band_raw(&mut self, band: usize, setting: eq_band_setting)
pub fn set_eq_band_raw(&mut self, band: usize, setting: eq_band_setting)
Configure one EQ band with native Rockbox units — q and gain in
tenths (q = 70 → Q 7.0, gain = -125 → −12.5 dB), exactly the
format of rockboxd’s [[eq_band_settings]] in settings.toml.
Sourcepub fn set_eq_precut(&mut self, db: f32)
pub fn set_eq_precut(&mut self, db: f32)
EQ precut in dB (applied as negative pre-gain to avoid clipping).
Sourcepub fn process(&mut self, input: &[i16], out: &mut Vec<i16>) -> usize
pub fn process(&mut self, input: &[i16], out: &mut Vec<i16>) -> usize
Run interleaved stereo S16 frames through the pipeline, appending
processed interleaved stereo S16 frames to out. Returns the number
of frames produced (not necessarily equal to the input count — the
resampler/timestretch stages may buffer internally).