Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub input_sample_rate: usize,
    pub output_sample_rate: usize,
    pub channels: usize,
    pub quality: usize,
    pub bandwidth: f32,
    pub taper_type: TaperType,
    pub phase: f32,
    pub phase_intensity: f32,
    pub rodio_fast_start: bool,
}
Expand description

Configures the ardftsrc resampler.

§Example

let config = ardftsrc::Config::new(44_100, 48_000, 2).with_phase(-0.5);

Fields§

§input_sample_rate: usize

Input audio sample rate in Hz.

§output_sample_rate: usize

Output audio sample rate in Hz.

§channels: usize

Number of interleaved audio channels.

§quality: usize

Set the overall “quality” of the resampler.

Quality roughly sets the spectral resolution scale (and therefore FFT bin count), but this mapping is not exactly 1:1 (exact bin count depends on rate ratio and quantization).

Default value is 1878 (same quality as PRESET_GOOD).

Value guide:

  • 512 (PRESET_FAST): Fast and low quality, great for realtime applications. At this quality you may prefer using a sinc resampler (eg. rubato) instead.
  • 1878 (PRESET_GOOD): Good balanced quality - you should probably use this. (Default)
  • 73622 (PRESET_HIGH): High quality, good for offline resampling, also marginally appropriate for realtime applications where quality is critical.
  • 524514 (PRESET_EXTREME): Extreme quality, good for offline resampling, very high quality but also very slow. Not recommended for realtime applications.
§bandwidth: f32

Normalized filter bandwidth in the range [0.0, 1.0].

Higher values preserve more high-frequency content but shorten the transition band.

Value guide:

  • 0.82: Fast and low quality, great for realtime applications. At this quality you may prefer using a sinc resampler (eg. rubato) instead.
  • 0.95: Balanced high-end retention for most cases.
  • 0.97: More aggressive high-end retention; Use with a higher “quality” setting.
  • 0.99: Very aggressive high-end retention; Only recommended when using a very high “quality” setting.
§taper_type: TaperType

Frequency taper profile used around the cutoff region.

  • Planck: Uses a Planck taper transition.
  • Cosine(alpha): Uses a sigmoid-warped cosine transition.
  • BetaCdf(alpha, beta): Beta-CDF taper from the regularized lower incomplete beta function.

Default value is Cosine(3.4375), which was arrived at through testing various values on the HydrogenAudio SRC test suite.

Lower alpha values result in a smoother transition, while higher values produce a sharper transition.

Value guide for Cosine(alpha):

  • 1.5: Very smooth transition; may increase audible near-Nyquist artifacts.
  • 2.5: Smooth and less aggressive shaping.
  • 3.5: Good balance between smoothness and selectivity.
  • 4.0: Sharper shaping; can trade smoothness for selectivity.
§phase: f32

Phase: Frequency-dependent phase rotation in the range [-1.0, 1.0].

Positive values rotate higher bins forward; negative values apply the conjugate rotation. 0.0 disables phase rotation.

Setting a negative phase value can help with pre-ringing artifacts.

Default value is 0.0.

§phase_intensity: f32

Scales the phase rotation angle in the range [0.0, 100.0].

0.0 disables phase rotation. The default value is 50.0.

§rodio_fast_start: bool

For RodioResampler, this setting controls whether to use a fast start mode.

Fast start mode will prime the resampler with initial samples to get it up to speed, and avoid start-up silence. This is only appropriate to use when the inner sounce can handle rapid calls to next(). For example, this will generally work on buffered streams or audio files, but not on live microphones.

  • Set to “true” if the inner source is something like a buffered stream or audio file.
  • Set to “false” if the inner source is very realtime (e.g. a live microphone).

If set to true for an inner source that cannot handle this, you will experience crackling at the start of the stream as the inner source fails to keep up.

This setting is only for RodioResampler, it has no effect on other resamplers.

Implementations§

Source§

impl Config

Source

pub const DEFAULT: Self

Source

pub fn new( input_sample_rate: usize, output_sample_rate: usize, channels: usize, ) -> Self

Builds a config with explicit sample rates/channel count and default (PRESET_GOOD) quality settings.

Source

pub fn with_input_rate(self, input_sample_rate: usize) -> Self

Input audio sample rate in Hz.

Source

pub fn with_output_rate(self, output_sample_rate: usize) -> Self

Output audio sample rate in Hz.

Source

pub fn with_channels(self, channels: usize) -> Self

Number of interleaved audio channels.

Source

pub fn with_quality(self, quality: usize) -> Self

Set the overall “quality” of the resampler.

Quality roughly sets the spectral resolution scale (and therefore FFT bin count), but this mapping is not exactly 1:1 (exact bin count depends on rate ratio and quantization).

Default value is 1878 (same quality as PRESET_GOOD).

Value guide:

  • 512 (PRESET_FAST): Fast and low quality, great for realtime applications. At this quality you may prefer using a sinc resampler (eg. rubato) instead.
  • 1878 (PRESET_GOOD): Good balanced quality - you should probably use this. (Default)
  • 73622 (PRESET_HIGH): High quality, good for offline resampling, also marginally appropriate for realtime applications where quality is critical.
  • 524514 (PRESET_EXTREME): Extreme quality, good for offline resampling, very high quality but also very slow. Not recommended for realtime applications.
Source

pub fn with_bandwidth(self, bandwidth: f32) -> Self

Normalized filter bandwidth in the range [0.0, 1.0].

Higher values preserve more high-frequency content but shorten the transition band.

Value guide:

  • 0.82: Fast and low quality, great for realtime applications. At this quality you may prefer using a sinc resampler (eg. rubato) instead.
  • 0.95: Balanced high-end retention for most cases.
  • 0.97: More aggressive high-end retention; Use with a higher “quality” setting.
  • 0.99: Very aggressive high-end retention; Only recommended when using a very high “quality” setting.
Source

pub fn with_taper_type(self, taper_type: TaperType) -> Self

Frequency taper profile used around the cutoff region.

  • Planck: Uses a Planck taper transition.
  • Cosine(alpha): Uses a sigmoid-warped cosine transition.

Default value is Cosine(3.4375), which was arrived at through testing various values on the HydrogenAudio SRC test suite.

Lower alpha values result in a smoother transition, while higher values produce a sharper transition.

Value guide for Cosine(alpha):

  • 1.5: Very smooth transition; may increase audible near-Nyquist artifacts.
  • 2.5: Smooth and less aggressive shaping.
  • 3.5: Good balance between smoothness and selectivity.
  • 4.0: Sharper shaping; can trade smoothness for selectivity.
Source

pub fn with_phase(self, phase: f32) -> Self

Phase: Frequency-dependent phase rotation in the range [-1.0, 1.0].

Positive values rotate higher bins forward; negative values apply the conjugate rotation. 0.0 disables phase rotation.

Setting a negative phase value can help with pre-ringing artifacts.

Default value is 0.0.

Source

pub fn with_phase_intensity(self, phase_intensity: f32) -> Self

Scales the phase rotation angle in the range [0.0, 100.0].

0.0 disables phase rotation. The default value is 50.0.

Source

pub fn with_rodio_fast_start(self, rodio_fast_start: bool) -> Self

For RodioResampler, this setting controls whether to use a fast start mode.

Fast start mode will prime the resampler with initial samples to get it up to speed, and avoid start-up silence. This is only appropriate to use when the inner sounce can handle rapid calls to next(). For example, this will generally work on buffered streams or audio files, but not on live microphones.

  • Set to true if the inner source is something like a buffered stream or audio file.
  • Set to false if the inner source is very realtime (e.g. a live microphone).

If set to true for an inner source that cannot handle this, you will experience crackling at the start of the stream as the inner source fails to keep up.

This setting is only for RodioResampler, it has no effect on other resamplers.

Source

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

Validates all user-facing configuration fields.

Returns Ok(()) when all values are in range, or a specific Error describing the first invalid field encountered.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

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

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Config

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<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> 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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,