Trait rotary::buf::Buf[][src]

pub trait Buf<T> where
    T: Sample
{ fn frames(&self) -> usize;
fn channels(&self) -> usize;
fn channel(&self, channel: usize) -> Channel<'_, T>; fn offset(self, offset: usize) -> Offset<Self>
    where
        Self: Sized
, { ... }
fn limit(self, limit: usize) -> Limit<Self>
    where
        Self: Sized
, { ... } }

A trait describing an immutable audio buffer.

Required methods

fn frames(&self) -> usize[src]

The number of frames in a buffer.

fn channels(&self) -> usize[src]

The number of channels in the buffer.

fn channel(&self, channel: usize) -> Channel<'_, T>[src]

Return a handler to the buffer associated with the channel.

Note that we don’t access the buffer for the underlying channel directly as a linear buffer like &[T], because the underlying representation might be different.

We must instead make use of the various utility functions found on Channel to copy data out of the channel.

Panics

Panics if the specified channel is out of bound as reported by Buf::channels.

Loading content...

Provided methods

fn offset(self, offset: usize) -> Offset<Self> where
    Self: Sized
[src]

Offset the buffer to process by offset number of frames.

Examples

use rotary::{Buf as _, BufMut as _};

let mut from = rotary::interleaved![[0.0f32; 4]; 2];
*from.frame_mut(0, 2).unwrap() = 1.0;
*from.frame_mut(0, 3).unwrap() = 1.0;

let mut to = rotary::Interleaved::<f32>::with_topology(2, 4);

to.channel_mut(0).copy_from((&from).offset(2).channel(0));
assert_eq!(to.as_slice(), &[1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]);

Test with a mutable buffer.

use rotary::{Buf as _, BufMut as _};

let mut buffer = rotary::Interleaved::with_topology(2, 4);

(&mut buffer).offset(2).channel_mut(0).copy_from_slice(&[1.0, 1.0]);

assert_eq!(buffer.as_slice(), &[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0])

fn limit(self, limit: usize) -> Limit<Self> where
    Self: Sized
[src]

Limit the buffer to process by limit number of frames.

Examples

use rotary::{Buf as _, BufMut as _};

let from = rotary::interleaved![[1.0f32; 4]; 2];
let mut to = rotary::Interleaved::<f32>::with_topology(2, 4);

to.channel_mut(0).copy_from(from.limit(2).channel(0));
assert_eq!(to.as_slice(), &[1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
Loading content...

Implementations on Foreign Types

impl<B, T> Buf<T> for &B where
    B: Buf<T>,
    T: Sample
[src]

impl<B: ?Sized, T> Buf<T> for &mut B where
    B: Buf<T>,
    T: Sample
[src]

impl<T> Buf<T> for Vec<Vec<T>> where
    T: Sample
[src]

impl<T> Buf<T> for [Vec<T>] where
    T: Sample
[src]

Loading content...

Implementors

impl<B, T> Buf<T> for Limit<B> where
    B: Buf<T>,
    T: Sample
[src]

impl<B, T> Buf<T> for Offset<B> where
    B: Buf<T>,
    T: Sample
[src]

impl<T> Buf<T> for Dynamic<T> where
    T: Sample
[src]

impl<T> Buf<T> for rotary::interleaved::Interleaved<T> where
    T: Sample
[src]

impl<T> Buf<T> for rotary::sequential::Sequential<T> where
    T: Sample
[src]

impl<T, S> Buf<S> for rotary::wrap::Interleaved<T> where
    T: AsRef<[S]>,
    S: Sample
[src]

impl<T, S> Buf<S> for rotary::wrap::Sequential<T> where
    T: AsRef<[S]>,
    S: Sample
[src]

Loading content...