Struct Audio

Source
pub struct Audio<Chan: Channel, const CH: usize> { /* private fields */ }
Expand description

Audio buffer (fixed-size array of audio Frames at sample rate specified in hertz).

Implementations§

Source§

impl<Chan: Channel, const CH: usize> Audio<Chan, CH>

Source

pub fn with_silence(hz: u32, len: usize) -> Self

Construct an Audio buffer with all all samples set to zero.

Source

pub fn with_frames<B>(hz: u32, frames: B) -> Self
where B: Into<Box<[Frame<Chan, CH>]>>,

Construct an Audio buffer with owned sample data. You can get ownership of the sample data back from the Audio buffer as either a Vec<S> or a Box<[S]> by calling into().

Source

pub fn with_audio<Ch, const N: usize>(hz: u32, audio: &Audio<Ch, N>) -> Self
where Ch: Channel, Ch32: From<Ch>, Chan: From<Ch>,

Construct an Audio buffer from another Audio buffer of a different format.

Source

pub fn get(&self, index: usize) -> Option<Frame<Chan, CH>>

Get an audio frame.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut Frame<Chan, CH>>

Get a mutable reference to an audio frame.

Source

pub fn as_slice(&self) -> &[Frame<Chan, CH>]

Get a slice of all audio frames.

Source

pub fn as_mut_slice(&mut self) -> &mut [Frame<Chan, CH>]

Get a slice of all audio frames.

Source

pub fn iter(&self) -> Iter<'_, Frame<Chan, CH>>

Returns an iterator over the audio frames.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, Frame<Chan, CH>>

Returns an iterator that allows modifying each audio frame.

Source

pub fn sample_rate(&self) -> NonZeroU32

Get the sample rate of this audio buffer.

Source

pub fn len(&self) -> usize

Get the length of the Audio buffer.

Source

pub fn is_empty(&self) -> bool

Check if Audio buffer is empty.

Source

pub fn silence(&mut self)

Silence the audio buffer.

Source

pub fn sink(&mut self) -> AudioSink<'_, Chan, CH>

Sink audio into this audio buffer from a Stream.

Source§

impl<const CH: usize> Audio<Ch16, CH>

Source

pub fn with_i16_buffer<B>(hz: u32, buffer: B) -> Self
where B: Into<Box<[i16]>>,

Construct an Audio buffer from an i16 buffer.

Source

pub fn as_i16_slice(&mut self) -> &mut [i16]

Get view of samples as an i16 slice.

Source§

impl<const CH: usize> Audio<Ch24, CH>

Source

pub fn with_u8_buffer<B>(hz: u32, buffer: B) -> Self
where B: Into<Box<[u8]>>,

Construct an Audio buffer from an u8 buffer.

Source

pub fn as_u8_slice(&mut self) -> &mut [u8]

Get view of samples as an u8 slice.

Source§

impl<const CH: usize> Audio<Ch32, CH>

Source

pub fn with_f32_buffer<B>(hz: u32, buffer: B) -> Self
where B: Into<Box<[f32]>>,

Construct an Audio buffer from an f32 buffer.

Source

pub fn as_f32_slice(&mut self) -> &mut [f32]

Get view of samples as an f32 slice.

Source§

impl<const CH: usize> Audio<Ch64, CH>

Source

pub fn with_f64_buffer<B>(hz: u32, buffer: B) -> Self
where B: Into<Box<[f64]>>,

Construct an Audio buffer from an f64 buffer.

Source

pub fn as_f64_slice(&mut self) -> &mut [f64]

Get view of samples as an f64 slice.

Trait Implementations§

Source§

impl<Chan: Debug + Channel, const CH: usize> Debug for Audio<Chan, CH>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const CH: usize> From<Audio<Ch16, CH>> for Box<[i16]>

Source§

fn from(audio: Audio<Ch16, CH>) -> Self

Get internal sample data as boxed slice of i16.

Source§

impl<const CH: usize> From<Audio<Ch24, CH>> for Box<[u8]>

Source§

fn from(audio: Audio<Ch24, CH>) -> Self

Get internal sample data as boxed slice of u8.

Source§

impl<const CH: usize> From<Audio<Ch32, CH>> for Box<[f32]>

Source§

fn from(audio: Audio<Ch32, CH>) -> Self

Get internal sample data as boxed slice of f32.

Source§

impl<const CH: usize> From<Audio<Ch64, CH>> for Box<[f64]>

Source§

fn from(audio: Audio<Ch64, CH>) -> Self

Get internal sample data as boxed slice of f64.

Source§

impl<Chan: Channel, const CH: usize> From<Audio<Chan, CH>> for Box<[Frame<Chan, CH>]>

Source§

fn from(audio: Audio<Chan, CH>) -> Self

Get internal sample data as Vec of audio frames.

Source§

impl<Chan, const CH: usize> From<Audio<Chan, CH>> for Vec<Frame<Chan, CH>>
where Chan: Channel,

Source§

fn from(audio: Audio<Chan, CH>) -> Self

Get internal sample data as Vec of audio frames.

Auto Trait Implementations§

§

impl<Chan, const CH: usize> Freeze for Audio<Chan, CH>

§

impl<Chan, const CH: usize> RefUnwindSafe for Audio<Chan, CH>
where Chan: RefUnwindSafe,

§

impl<Chan, const CH: usize> Send for Audio<Chan, CH>
where Chan: Send,

§

impl<Chan, const CH: usize> Sync for Audio<Chan, CH>
where Chan: Sync,

§

impl<Chan, const CH: usize> Unpin for Audio<Chan, CH>

§

impl<Chan, const CH: usize> UnwindSafe for Audio<Chan, CH>
where Chan: 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, 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.