pub struct SoftClip { /* private fields */ }Expand description
Carries the soft-clipping curve across frame boundaries for one stream.
One per decoder, or per stream if you are clipping several. Construct it with the channel count the buffers you will pass are interleaved at.
use opus_pure::SoftClip;
let mut clip = SoftClip::new(2);
let mut pcm = vec![0.0f32; 960 * 2];
// ...decode into `pcm`...
clip.apply(&mut pcm);Implementations§
Source§impl SoftClip
impl SoftClip
Sourcepub fn new(channels: usize) -> Self
pub fn new(channels: usize) -> Self
A new soft clipper for interleaved audio with channels channels.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Forget any curve in progress, as if the next frame were the first.
Use this on a discontinuity — a seek, or a new stream through the same clipper — where carrying the previous curve forward would bend audio that has nothing to do with it.
Sourcepub fn apply(&mut self, pcm: &mut [f32])
pub fn apply(&mut self, pcm: &mut [f32])
Soft-clip pcm in place, into ±1.
pcm is interleaved at channels. Any trailing
samples that do not complete a frame are left untouched, and a zero
channel count or an empty buffer is a no-op rather than an error: this
is a filter, and having nothing to filter is not a mistake.