Struct LimitSettings

pub struct LimitSettings {
    pub threshold: f32,
    pub knee_width: f32,
    pub attack: Duration,
    pub release: Duration,
}
Available on crate feature dep_rodio only.
Expand description

Configuration settings for audio limiting.

This struct defines how the limiter behaves, including when to start limiting (threshold), how gradually to apply it (knee width), and how quickly to respond to level changes (attack/release times).

§Parameters

  • Threshold - Level in dB where limiting begins (must be negative, typically -1 to -6 dB)
  • Knee Width - Range in dB over which limiting gradually increases (wider = smoother)
  • Attack - Time to respond to level increases (shorter = faster but may distort)
  • Release - Time to recover after level decreases (longer = smoother)

§Examples

§Basic Usage

use rodio::source::{SineWave, Source, LimitSettings};
use std::time::Duration;

// Use default settings (-1 dB threshold, 4 dB knee, 5ms attack, 100ms release)
let source = SineWave::new(440.0).amplify(2.0);
let limited = source.limit(LimitSettings::default());

§Custom Settings with Builder Pattern

use rodio::source::{SineWave, Source, LimitSettings};
use std::time::Duration;

let source = SineWave::new(440.0).amplify(3.0);
let settings = LimitSettings::new()
    .with_threshold(-6.0)                    // Limit peaks above -6dB
    .with_knee_width(2.0)                    // 2dB soft knee for smooth limiting
    .with_attack(Duration::from_millis(3))   // Fast 3ms attack
    .with_release(Duration::from_millis(50)); // 50ms release

let limited = source.limit(settings);

§Common Adjustments

use rodio::source::LimitSettings;
use std::time::Duration;

// More headroom for dynamic content
let conservative = LimitSettings::default()
    .with_threshold(-3.0)                    // More headroom
    .with_knee_width(6.0);                   // Wide knee for transparency

// Tighter control for broadcast/streaming
let broadcast = LimitSettings::default()
    .with_knee_width(2.0)                     // Narrower knee for firmer limiting
    .with_attack(Duration::from_millis(3))    // Faster attack
    .with_release(Duration::from_millis(50)); // Faster release

Configuration settings for audio limiting.

§dB vs. dBFS Reference

This limiter uses dBFS (decibels relative to Full Scale) for all level measurements:

  • 0 dBFS = maximum possible digital level (1.0 in linear scale)
  • Negative dBFS = levels below maximum (e.g., -6 dBFS = 0.5 in linear scale)
  • Positive dBFS = levels above maximum (causes digital clipping)

Unlike absolute dB measurements (dB SPL), dBFS is relative to the digital system’s maximum representable value, making it the standard for digital audio processing.

§Common dBFS Reference Points

  • 0 dBFS: Digital maximum (clipping threshold)
  • -1 dBFS: Just below clipping (tight limiting)
  • -3 dBFS: Moderate headroom (balanced limiting)
  • -6 dBFS: Generous headroom (gentle limiting)
  • -12 dBFS: Conservative level (preserves significant dynamics)
  • -20 dBFS: Very quiet level (background/ambient sounds)

Fields§

§threshold: f32

Level where limiting begins (dBFS, must be negative).

Specifies the threshold in dBFS where the limiter starts to reduce gain:

  • -1.0 = limit at -1 dBFS (tight limiting, prevents clipping)
  • -3.0 = limit at -3 dBFS (balanced approach with headroom)
  • -6.0 = limit at -6 dBFS (gentle limiting, preserves dynamics)

Values must be negative - positive values would attempt limiting above 0 dBFS, which cannot prevent clipping.

§knee_width: f32

Range over which limiting gradually increases (dB).

Defines the transition zone width in dB where limiting gradually increases from no effect to full limiting:

  • 0.0 = hard limiting (abrupt transition)
  • 2.0 = moderate knee (some gradual transition)
  • 4.0 = soft knee (smooth, transparent transition)
  • 8.0 = very soft knee (very gradual, musical transition)
§attack: Duration

Time to respond to level increases

§release: Duration

Time to recover after level decreases

Implementations§

§

impl LimitSettings

pub fn new() -> LimitSettings

Creates new limit settings with default values.

Equivalent to LimitSettings::default().

pub fn dynamic_content() -> LimitSettings

Creates settings optimized for dynamic content like music and sound effects.

Designed for content with varying dynamics where you want to preserve the natural feel while preventing occasional peaks from clipping.

§Configuration
  • Threshold: -3.0 dBFS (more headroom than default)
  • Knee width: 6.0 dB (wide, transparent transition)
  • Attack: 5 ms (default, balanced response)
  • Release: 100 ms (default, smooth recovery)
§Use Cases
  • Music playback with occasional loud peaks
  • Sound effects that need natural dynamics
  • Content where transparency is more important than tight control
  • Game audio with varying intensity levels
§Examples
use rodio::source::{SineWave, Source, LimitSettings};

let music = SineWave::new(440.0).amplify(1.5);
let limited = music.limit(LimitSettings::dynamic_content());

pub fn broadcast() -> LimitSettings

Creates settings optimized for broadcast and streaming applications.

Designed for consistent loudness and reliable peak control in scenarios where clipping absolutely cannot occur and consistent levels are critical.

§Configuration
  • Threshold: -1.0 dBFS (default, tight control)
  • Knee width: 2.0 dB (narrower, more decisive limiting)
  • Attack: 3 ms (faster response to catch transients)
  • Release: 50 ms (faster recovery for consistent levels)
§Use Cases
  • Live streaming where clipping would be catastrophic
  • Broadcast audio that must meet loudness standards
  • Voice chat applications requiring consistent levels
  • Podcast production for consistent listening experience
  • Game voice communication systems
§Examples
use rodio::source::{SineWave, Source, LimitSettings};

let voice_chat = SineWave::new(440.0).amplify(2.0);
let limited = voice_chat.limit(LimitSettings::broadcast());

pub fn mastering() -> LimitSettings

Creates settings optimized for mastering and final audio production.

Designed for the final stage of audio production where tight peak control is needed while maintaining audio quality and preventing any clipping.

§Configuration
  • Threshold: -0.5 dBFS (very tight, maximum loudness)
  • Knee width: 1.0 dB (narrow, precise control)
  • Attack: 1 ms (very fast, catches all transients)
  • Release: 200 ms (slower, maintains natural envelope)
§Use Cases
  • Final mastering stage for tight peak control
  • Preparing audio for streaming platforms (after loudness processing)
  • Album mastering where consistent peak levels are critical
  • Audio post-production for film/video
§Examples
use rodio::source::{SineWave, Source, LimitSettings};

let master_track = SineWave::new(440.0).amplify(3.0);
let mastered = master_track.limit(LimitSettings::mastering());

pub fn live_performance() -> LimitSettings

Creates settings optimized for live performance and real-time applications.

Designed for scenarios where low latency is critical and the limiter must respond quickly to protect equipment and audiences.

§Configuration
  • Threshold: -2.0 dBFS (some headroom for safety)
  • Knee width: 3.0 dB (moderate, good compromise)
  • Attack: 0.5 ms (extremely fast for protection)
  • Release: 30 ms (fast recovery for live feel)
§Use Cases
  • Live concert sound reinforcement
  • DJ mixing and live electronic music
  • Real-time audio processing where latency matters
  • Equipment protection in live settings
  • Interactive audio applications and games
§Examples
use rodio::source::{SineWave, Source, LimitSettings};

let live_input = SineWave::new(440.0).amplify(2.5);
let protected = live_input.limit(LimitSettings::live_performance());

pub fn gaming() -> LimitSettings

Creates settings optimized for gaming and interactive audio.

Designed for games where audio levels can vary dramatically between quiet ambient sounds and loud action sequences, requiring responsive limiting that maintains immersion.

§Configuration
  • Threshold: -3.0 dBFS (balanced headroom for dynamic range)
  • Knee width: 3.0 dB (moderate transition for natural feel)
  • Attack: 2 ms (fast enough for sound effects, not harsh)
  • Release: 75 ms (quick recovery for interactive responsiveness)
§Use Cases
  • Game audio mixing for consistent player experience
  • Interactive audio applications requiring dynamic response
  • VR/AR audio where sudden loud sounds could be jarring
  • Mobile games needing battery-efficient processing
  • Streaming gameplay audio for viewers
§Examples
use rodio::source::{SineWave, Source, LimitSettings};

let game_audio = SineWave::new(440.0).amplify(2.0);
let limited = game_audio.limit(LimitSettings::gaming());

pub fn with_threshold(self, threshold: f32) -> LimitSettings

Sets the threshold level where limiting begins.

§Arguments
  • threshold - Level in dBFS where limiting starts (must be negative)
    • -1.0 = limiting starts at -1 dBFS (tight limiting, prevents clipping)
    • -3.0 = limiting starts at -3 dBFS (balanced approach with headroom)
    • -6.0 = limiting starts at -6 dBFS (gentle limiting, preserves dynamics)
    • -12.0 = limiting starts at -12 dBFS (very aggressive, significantly reduces dynamics)
§dBFS Context

Remember that 0 dBFS is the digital maximum. Negative dBFS values represent levels below this maximum:

  • -1 dBFS ≈ 89% of maximum amplitude (very loud, limiting triggers late)
  • -3 dBFS ≈ 71% of maximum amplitude (loud, moderate limiting)
  • -6 dBFS ≈ 50% of maximum amplitude (moderate, gentle limiting)
  • -12 dBFS ≈ 25% of maximum amplitude (quiet, aggressive limiting)

Lower thresholds (more negative) trigger limiting earlier and reduce dynamics more. Only negative values are meaningful - positive values would attempt limiting above 0 dBFS, which cannot prevent clipping.

pub fn with_knee_width(self, knee_width: f32) -> LimitSettings

Sets the knee width - range over which limiting gradually increases.

§Arguments
  • knee_width - Range in dB over which limiting transitions from off to full effect
    • 0.0 dB = hard knee (abrupt limiting, may sound harsh)
    • 1.0-2.0 dB = moderate knee (noticeable but controlled limiting)
    • 4.0 dB = soft knee (smooth, transparent limiting) [default]
    • 6.0-8.0 dB = very soft knee (very gradual, musical limiting)
§How Knee Width Works

The knee creates a transition zone around the threshold. For example, with threshold = -3.0 dBFS and knee_width = 4.0 dB:

  • No limiting below -5 dBFS (threshold - knee_width/2)
  • Gradual limiting from -5 dBFS to -1 dBFS
  • Full limiting above -1 dBFS (threshold + knee_width/2)

pub fn with_attack(self, attack: Duration) -> LimitSettings

Sets the attack time - how quickly the limiter responds to level increases.

§Arguments
  • attack - Time duration for the limiter to react to peaks
    • Shorter (1-5 ms) = faster response, may cause distortion
    • Longer (10-20 ms) = smoother sound, may allow brief overshoots

pub fn with_release(self, release: Duration) -> LimitSettings

Sets the release time - how quickly the limiter recovers after level decreases.

§Arguments
  • release - Time duration for the limiter to stop limiting
    • Shorter (10-50 ms) = quick recovery, may sound pumping
    • Longer (100-500 ms) = smooth recovery, more natural sound

Trait Implementations§

§

impl Clone for LimitSettings

§

fn clone(&self) -> LimitSettings

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
§

impl Debug for LimitSettings

§

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

Formats the value using the given formatter. Read more
§

impl Default for LimitSettings

§

fn default() -> LimitSettings

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

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> ByteSized for T

Source§

const BYTE_ALIGN: usize = _

The alignment of this type in bytes.
Source§

const BYTE_SIZE: usize = _

The size of this type in bytes.
Source§

fn byte_align(&self) -> usize

Returns the alignment of this type in bytes.
Source§

fn byte_size(&self) -> usize

Returns the size of this type in bytes. Read more
Source§

fn ptr_size_ratio(&self) -> [usize; 2]

Returns the size ratio between Ptr::BYTES and BYTE_SIZE. Read more
Source§

impl<T, R> Chain<R> for T
where T: ?Sized,

Source§

fn chain<F>(self, f: F) -> R
where F: FnOnce(Self) -> R, Self: Sized,

Chain a function which takes the parameter by value.
Source§

fn chain_ref<F>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Chain a function which takes the parameter by shared reference.
Source§

fn chain_mut<F>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Chain a function which takes the parameter by exclusive reference.
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> ExtAny for T
where T: Any + ?Sized,

Source§

fn type_id() -> TypeId

Returns the TypeId of Self. Read more
Source§

fn type_of(&self) -> TypeId

Returns the TypeId of self. Read more
Source§

fn type_name(&self) -> &'static str

Returns the type name of self. Read more
Source§

fn type_is<T: 'static>(&self) -> bool

Returns true if Self is of type T. Read more
Source§

fn type_hash(&self) -> u64

Returns a deterministic hash of the TypeId of Self.
Source§

fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64

Returns a deterministic hash of the TypeId of Self using a custom hasher.
Source§

fn as_any_ref(&self) -> &dyn Any
where Self: Sized,

Upcasts &self as &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any
where Self: Sized,

Upcasts &mut self as &mut dyn Any. Read more
Source§

fn as_any_box(self: Box<Self>) -> Box<dyn Any>
where Self: Sized,

Upcasts Box<self> as Box<dyn Any>. Read more
Source§

fn downcast_ref<T: 'static>(&self) -> Option<&T>

Available on crate feature unsafe_layout only.
Returns some shared reference to the inner value if it is of type T. Read more
Source§

fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Available on crate feature unsafe_layout only.
Returns some exclusive reference to the inner value if it is of type T. Read more
Source§

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

Source§

const NEEDS_DROP: bool = _

Know whether dropping values of this type matters, in compile-time.
Source§

fn mem_align_of<T>() -> usize

Returns the minimum alignment of the type in bytes. Read more
Source§

fn mem_align_of_val(&self) -> usize

Returns the alignment of the pointed-to value in bytes. Read more
Source§

fn mem_size_of<T>() -> usize

Returns the size of a type in bytes. Read more
Source§

fn mem_size_of_val(&self) -> usize

Returns the size of the pointed-to value in bytes. Read more
Source§

fn mem_copy(&self) -> Self
where Self: Copy,

Bitwise-copies a value. Read more
Source§

fn mem_needs_drop(&self) -> bool

Returns true if dropping values of this type matters. Read more
Source§

fn mem_drop(self)
where Self: Sized,

Drops self by running its destructor. Read more
Source§

fn mem_forget(self)
where Self: Sized,

Forgets about self without running its destructor. Read more
Source§

fn mem_replace(&mut self, other: Self) -> Self
where Self: Sized,

Replaces self with other, returning the previous value of self. Read more
Source§

fn mem_take(&mut self) -> Self
where Self: Default,

Replaces self with its default value, returning the previous value of self. Read more
Source§

fn mem_swap(&mut self, other: &mut Self)
where Self: Sized,

Swaps the value of self and other without deinitializing either one. Read more
Source§

unsafe fn mem_zeroed<T>() -> T

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

fn mem_as_bytes(&self) -> &[u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &[u8]. Read more
Source§

fn mem_as_bytes_mut(&mut self) -> &mut [u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &mut [u8]. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T> Hook for T

Source§

fn hook_ref<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Applies a function which takes the parameter by shared reference, and then returns the (possibly) modified owned value. Read more
Source§

fn hook_mut<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Applies a function which takes the parameter by exclusive reference, and then returns the (possibly) modified owned value. 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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

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

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Ungil for T
where T: Send,