Trait rotary::Buf[][src]

pub trait Buf<T> {
    pub fn frames_hint(&self) -> Option<usize>;
pub fn channels(&self) -> usize;
pub fn channel(&self, channel: usize) -> Channel<'_, T>; pub fn skip(self, n: usize) -> Skip<Self> { ... }
pub fn tail(self, n: usize) -> Tail<Self> { ... }
pub fn limit(self, limit: usize) -> Limit<Self> { ... }
pub fn chunk(self, n: usize, len: usize) -> Chunk<Self> { ... } }

A trait describing an immutable audio buffer.

Required methods

pub fn frames_hint(&self) -> Option<usize>[src]

A typical number of frames in the buffer, if known.

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

The number of channels in the buffer.

pub 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

pub fn skip(self, n: usize) -> Skip<Self>[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])

pub fn tail(self, n: usize) -> Tail<Self>[src]

Construct a new buffer where n frames are skipped.

Examples

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

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

rotary::utils::copy(from, (&mut to).tail(2));

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

pub fn limit(self, limit: usize) -> Limit<Self>[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]);

pub fn chunk(self, n: usize, len: usize) -> Chunk<Self>[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<T> Buf<T> for [Vec<T, Global>][src]

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

impl<T> Buf<T> for Vec<Vec<T, Global>, Global>[src]

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

Loading content...

Implementors

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

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

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

impl<T> Buf<T> for Dynamic<T>[src]

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

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

impl<T> Buf<T> for rotary::wrap::Interleaved<&[T]>[src]

impl<T> Buf<T> for rotary::wrap::Interleaved<&mut [T]>[src]

impl<T> Buf<T> for rotary::wrap::Sequential<&[T]>[src]

impl<T> Buf<T> for rotary::wrap::Sequential<&mut [T]>[src]

impl<T, const N: usize> Buf<T> for rotary::wrap::Interleaved<&[T; N]>[src]

impl<T, const N: usize> Buf<T> for rotary::wrap::Interleaved<&mut [T; N]>[src]

impl<T, const N: usize> Buf<T> for rotary::wrap::Interleaved<[T; N]>[src]

impl<T, const N: usize> Buf<T> for rotary::wrap::Sequential<&[T; N]>[src]

impl<T, const N: usize> Buf<T> for rotary::wrap::Sequential<&mut [T; N]>[src]

impl<T, const N: usize> Buf<T> for rotary::wrap::Sequential<[T; N]>[src]

Loading content...