soundmentations.Limiter¶
- class soundmentations.Limiter(threshold: float = 0.9, p: float = 1.0)[source]¶
Bases:
BaseLimiter
Apply hard limiting to audio samples to prevent clipping.
This transform clips audio samples that exceed the specified threshold, preventing digital clipping and maintaining signal integrity within the specified dynamic range.
- Parameters:
Examples
Apply hard limiting to prevent clipping:
>>> import numpy as np >>> from soundmentations.transforms.amplitude import Limiter >>> >>> # Create audio with some peaks above 0.9 >>> audio = np.array([0.5, 1.2, -1.5, 0.8, 0.95]) >>> >>> # Apply limiting at 0.9 threshold >>> limiter = Limiter(threshold=0.9) >>> limited = limiter(audio, sample_rate=44100) >>> print(limited) # [0.5, 0.9, -0.9, 0.8, 0.9]
Use in audio processing pipeline:
>>> import soundmentations as S >>> >>> # Safe audio processing with limiting >>> safe_pipeline = S.Compose([ ... S.Gain(gain=12.0, p=1.0), # Boost signal ... S.Limiter(threshold=0.95, p=1.0), # Prevent clipping ... S.FadeOut(duration=0.1, p=0.5) # Smooth ending ... ]) >>> >>> processed = safe_pipeline(audio, sample_rate=44100)
Protect against digital distortion:
>>> # Conservative limiting for pristine quality >>> conservative_limiter = Limiter(threshold=0.8, p=1.0) >>> clean_audio = conservative_limiter(loud_audio, sample_rate=44100)