pub struct AudioBuffer<T> { /* private fields */ }
Expand description

An audio buffer with a format, sample rates, numbers of channels and a buffer.

Implementations§

source§

impl<T> AudioBuffer<T>

source

pub fn new( format: AudioFormat, samples: u32, channels: u8, buffer: Vec<T> ) -> Self

Constructs an audio buffer from arguments. The size of type which stored by buffer must equal to the format bit size.

§Panics

Panics if the size of type T does not equal to the format bit size.

source

pub fn format(&self) -> &AudioFormat

Returns the format of the audio buffer.

source

pub fn samples(&self) -> u32

Returns the sample rates of the audio buffer.

source

pub fn channels(&self) -> u8

Returns the numbers of channels of the audio buffer.

source

pub fn convert<U: Default + Clone>( self, format: AudioFormat, samples: u32, channels: u8 ) -> Result<AudioBuffer<U>>

Convert into another AudioBuffer with different format, sample rate or channels.

§Errors

Returns Err if failed to convert into a specific format.

source

pub fn convert_in<U: Default + Clone>( self, other: &mut AudioBuffer<U> ) -> Result<()>

Convert and write into another existing AudioBuffer.

§Errors

Returns Err if failed to convert between self and other.

source§

impl<T: Default + Clone> AudioBuffer<T>

source

pub fn mix(&self, volume: u8) -> Self

Mix into another AudioBuffer with the specified volume.

The max value of volume is 128, saturating if it is over the max.

source

pub fn mix_in(&self, dst: &mut Self, volume: u8) -> Result<()>

Mix into another existing AudioBuffer with the specified volume.

The max value of volume is 128, saturating if it is over the max.

§Errors

Return Err if the formats of self and dst are different.

Trait Implementations§

source§

impl<T: Clone> Clone for AudioBuffer<T>

source§

fn clone(&self) -> AudioBuffer<T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for AudioBuffer<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for AudioBuffer<T>
where T: RefUnwindSafe,

§

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

§

impl<T> Sync for AudioBuffer<T>
where T: Sync,

§

impl<T> Unpin for AudioBuffer<T>
where T: Unpin,

§

impl<T> UnwindSafe for AudioBuffer<T>
where T: UnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.