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 skip(self, n: usize) -> Skip<Self>
    where
        Self: Sized
, { ... }
fn limit(self, limit: usize) -> Limit<Self>
    where
        Self: Sized
, { ... }
fn chunk(self, n: usize, len: usize) -> Chunk<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 skip(self, n: usize) -> Skip<Self> where
    Self: Sized
[src]

Construct a new buffer where n frames are skipped.

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).skip(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).skip(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 channel buffer to 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]);

fn chunk(self, n: usize, len: usize) -> Chunk<Self> where
    Self: Sized
[src]

Construct a range of frames corresponds to the chunk with len and position n.

Which is the range n * len .. n * len + len.

Examples

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

let from = rotary::interleaved![[1.0f32; 4]; 2];
let mut to = rotary::interleaved![[0.0f32; 4]; 2];

(&mut to).chunk(1, 2).channel_mut(0).copy_from(from.channel(0));
assert_eq!(to.as_slice(), &[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.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 Chunk<B> where
    B: Buf<T>,
    T: Sample
[src]

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

impl<B, T> Buf<T> for Skip<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...