Skip to main content

PreprocessingConfig

Struct PreprocessingConfig 

Source
pub struct PreprocessingConfig {
    pub highpass_cutoff_hz: f32,
    pub sample_rate_hz: u32,
    pub dc_bias_alpha: f32,
    pub enable_dc_removal: bool,
    pub enable_highpass: bool,
    pub highpass_order: HighpassOrder,
}
Expand description

Configuration for DC offset removal and high-pass filtering.

§Examples

use speech_prep::preprocessing::PreprocessingConfig;

// Default: 80 Hz high-pass, 16kHz sample rate, EMA α=0.95
let config = PreprocessingConfig::default();

// Custom configuration for noisy environment
let config = PreprocessingConfig {
    highpass_cutoff_hz: 120.0, // More aggressive low-frequency removal
    dc_bias_alpha: 0.98,       // Slower DC adaptation
    ..Default::default()
};

Fields§

§highpass_cutoff_hz: f32

High-pass filter cutoff frequency in Hz.

Range: 60.0 - 120.0 Default: 80.0

Effect: Frequencies below this cutoff are attenuated (≥20 dB at fc/2). Higher cutoffs remove more low-frequency content but may affect speech naturalness.

Recommendation:

  • 60-80 Hz: Standard speech (default)
  • 80-100 Hz: Noisy environments with HVAC/rumble
  • 100-120 Hz: Extreme low-frequency noise
§sample_rate_hz: u32

Audio sample rate in Hz.

Typical Values: 16000, 44100, 48000 Default: 16000

Effect: Determines filter coefficient calculation. Must match the actual sample rate of input audio.

§dc_bias_alpha: f32

EMA smoothing factor for DC bias estimation.

Range: 0.9 - 0.99 Default: 0.95

Effect: Controls adaptation speed of DC bias tracking.

  • Higher (0.95-0.99): Slower adaptation, smoother (recommended)
  • Lower (0.90-0.94): Faster adaptation, less smooth

Formula: bias_new = α × bias_old + (1-α) × sample_mean

§enable_dc_removal: bool

Enable DC offset removal stage.

Default: true

Effect: When false, DC removal is skipped (filter-only mode). Useful if audio is already DC-free (rare).

§enable_highpass: bool

Enable high-pass filtering stage.

Default: true

Effect: When false, high-pass filter is skipped (DC-only mode). Useful for testing or if audio already high-pass filtered.

§highpass_order: HighpassOrder

Order of the high-pass filter.

Default: FourthOrder (two cascaded biquads)

Effect: Higher order increases low-frequency attenuation at the cost of additional computation. FourthOrder meets the ≥20 dB @ 40 Hz target.

Implementations§

Source§

impl PreprocessingConfig

Source

pub fn validate(&self) -> Result<()>

Validate configuration parameters.

§Errors

Returns Error::Configuration if:

  • highpass_cutoff_hz < 20 Hz (too low, ineffective)
  • highpass_cutoff_hz >= Nyquist frequency (fs/2)
  • dc_bias_alpha not in (0.0, 1.0)
  • sample_rate_hz is zero

Trait Implementations§

Source§

impl Clone for PreprocessingConfig

Source§

fn clone(&self) -> PreprocessingConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PreprocessingConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PreprocessingConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for PreprocessingConfig

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more