Skip to main content

SoftClip

Struct SoftClip 

Source
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

Source

pub fn new(channels: usize) -> Self

A new soft clipper for interleaved audio with channels channels.

Source

pub fn channels(&self) -> usize

The channel count this was built for.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for SoftClip

Source§

fn clone(&self) -> SoftClip

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 SoftClip

Source§

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

Formats the value using the given formatter. 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> 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, 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> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.