Struct rotary::BufChannel [−][src]
The buffer of a single channel.
This doesn’t provide direct access to the underlying buffer, but rather allows us to copy data usinga number of utility functions.
Implementations
impl<'a, T> BufChannel<'a, T>
[src]
pub fn linear(buf: &'a [T]) -> Self
[src]
Construct a linear buffer.
pub fn interleaved(buf: &'a [T], channels: usize, channel: usize) -> Self
[src]
Construct an interleaved buffer.
pub fn frames(&self) -> usize
[src]
Access the number of frames on the current channel.
Examples
use rotary::Buf; fn test(buf: &dyn Buf<f32>) { let left = buf.channel(0); let right = buf.channel(1); assert_eq!(left.frames(), 16); assert_eq!(right.frames(), 16); } test(&rotary::dynamic![[0.0; 16]; 2]); test(&rotary::sequential![[0.0; 16]; 2]); test(&rotary::interleaved![[0.0; 16]; 2]);
pub fn chunks(&self, chunk: usize) -> usize
[src]
How many chunks of the given size can you divide buf into.
This includes one extra chunk even if the chunk doesn’t divide the frame length evenly.
Examples
use rotary::Buf; fn test(buf: &dyn Buf<f32>) { let left = buf.channel(0); let right = buf.channel(1); assert_eq!(left.chunks(4), 4); assert_eq!(right.chunks(4), 4); assert_eq!(left.chunks(6), 3); assert_eq!(right.chunks(6), 3); } test(&rotary::dynamic![[0.0; 16]; 2]); test(&rotary::sequential![[0.0; 16]; 2]); test(&rotary::interleaved![[0.0; 16]; 2]);
pub fn copy_into_slice(&self, out: &mut [T]) where
T: Copy,
[src]
T: Copy,
Copy into the given slice of output.
Examples
use rotary::Buf; fn test(buf: &dyn Buf<f32>) { let channel = buf.channel(0); let mut buf = vec![0.0; 16]; channel.copy_into_slice(&mut buf[..]); assert!(buf.iter().all(|f| *f == 1.0)); } test(&rotary::dynamic![[1.0; 16]; 2]); test(&rotary::sequential![[1.0; 16]; 2]); test(&rotary::interleaved![[1.0; 16]; 2]);
pub fn copy_chunk(&self, out: &mut [T], n: usize, len: usize) where
T: Copy,
[src]
T: Copy,
Copy the given chunk of a channel into a buffer.
The length of the chunk to copy is determined by len
. The offset of
the chunk to copy is determined by n
, where n
is the number of len
sized chunks.
Examples
use rotary::Buf; fn test(buf: &dyn Buf<f32>) { let channel = buf.channel(0); let mut buf = vec![0.0; 4]; channel.copy_chunk(&mut buf[..], 3, 4); assert!(buf.iter().all(|f| *f == 1.0)); } test(&rotary::dynamic![[1.0; 16]; 2]); test(&rotary::sequential![[1.0; 16]; 2]); test(&rotary::interleaved![[1.0; 16]; 2]);
pub fn copy_into_iter<'out, I>(&self, iter: I) where
I: IntoIterator<Item = &'out mut T>,
T: 'out + Copy,
[src]
I: IntoIterator<Item = &'out mut T>,
T: 'out + Copy,
Copy into the given iterator.
Examples
use rotary::Buf; fn test(buf: &dyn Buf<f32>) { let channel = buf.channel(0); let mut buf = vec![0.0; 16]; // Copy into every other position in `buf`. channel.copy_into_iter(buf.iter_mut().step_by(2)); for (n, f) in buf.into_iter().enumerate() { if n % 2 == 0 { assert_eq!(f, 1.0); } else { assert_eq!(f, 0.0); } } } test(&rotary::dynamic![[1.0; 16]; 2]); test(&rotary::sequential![[1.0; 16]; 2]); test(&rotary::interleaved![[1.0; 16]; 2]);
pub fn map_into_slice<M>(&self, out: &mut [T], m: M) where
M: Fn(usize) -> usize,
T: Copy,
[src]
M: Fn(usize) -> usize,
T: Copy,
Copy into the given slice, mapping the index by the given mapping function.
Examples
use rotary::Buf; fn test(buf: &dyn Buf<f32>) { let channel = buf.channel(0); let mut buf = vec![0.0; channel.frames() * 2]; // Copy into every other position in `buf`. channel.map_into_slice(&mut buf[..], |n| n * 2); for (n, f) in buf.into_iter().enumerate() { if n % 2 == 0 { assert_eq!(f, 1.0); } else { assert_eq!(f, 0.0); } } } test(&rotary::dynamic![[1.0; 16]; 2]); test(&rotary::sequential![[1.0; 16]; 2]); test(&rotary::interleaved![[1.0; 16]; 2]);
pub fn range_into_slice(&self, out: &mut [T], start: usize, len: usize) where
T: Copy,
[src]
T: Copy,
Copy the given range into a slice.
The range to be copied is designated with a starting position start
and a length len
.
Trait Implementations
impl<'a, T: Clone> Clone for BufChannel<'a, T>
[src]
fn clone(&self) -> BufChannel<'a, T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, T: Copy> Copy for BufChannel<'a, T>
[src]
impl<'a, T: Debug> Debug for BufChannel<'a, T>
[src]
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for BufChannel<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T> Send for BufChannel<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Sync for BufChannel<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Unpin for BufChannel<'a, T>
impl<'a, T> UnwindSafe for BufChannel<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,