Skip to main content

Dsp

Struct Dsp 

Source
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

Source

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).

Source

pub fn raw(&mut self) -> *mut dsp_config

Source

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.

Source

pub fn flush(&mut self)

Drop any samples buffered inside the pipeline (call on seek/stop).

Source

pub fn eq_enable(&mut self, enable: bool)

Source

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.

Source

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.

Source

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.

Source

pub fn set_channel_config(&mut self, mode: i32)

Channel configuration (SOUND_CHAN_*: stereo / mono / custom / karaoke / swap …).

Source

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).

Source

pub fn set_compressor(&mut self, settings: &compressor_settings)

Dynamic-range compressor; threshold of 0 disables the stage.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_eq_precut(&mut self, db: f32)

EQ precut in dB (applied as negative pre-gain to avoid clipping).

Source

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).

Auto Trait Implementations§

§

impl !Send for Dsp

§

impl !Sync for Dsp

§

impl Freeze for Dsp

§

impl RefUnwindSafe for Dsp

§

impl Unpin for Dsp

§

impl UnsafeUnpin for Dsp

§

impl UnwindSafe for Dsp

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.