Struct rsynth::buffer::AudioBufferIn[][src]

pub struct AudioBufferIn<'channels, 'samples, S> where
    S: 'static + Copy
{ /* fields omitted */ }

Audio input buffer.

It is guaranteed that all channels have the same number of frames.

Implementations

impl<'channels, 'samples, S> AudioBufferIn<'channels, 'samples, S> where
    S: 'static + Copy
[src]

pub fn new(channels: &'channels [&'samples [S]], length: usize) -> Self[src]

Create a new audio input buffer.

Panics

Panics if one of the elements of channels does not have the given length.

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

Get the number of channels.

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

Get the number of frames.

pub fn channels(&self) -> &'channels [&'samples [S]][src]

Get the channels as slices.

pub fn index_frames<'s, 'v, R>(
    &'s self,
    range: R,
    vec: &'v mut Vec<&'s [S]>
) -> AudioBufferIn<'v, 's, S> where
    R: SliceIndex<[S], Output = [S]> + RangeBounds<usize> + Clone
[src]

Get an AudioBufferIn with all channels and the given range of frames.

The vector vec will be used to store the channels of the result.

Remark

The vector vec will be cleared before use in order to guarantee that all channels have the same length.

Usage in a real-time thread

This method will append number_of_channels elements to the given vector. This will cause memory to be allocated if this exceeds the capacity of the given vector.

Suggestion

You can use the vecstorage crate to re-use the memory of a vector for different lifetimes.

Remark

If you enable the rsor-0-1 Cargo feature, you can also use the index_frames_from_slice method.

Example

use rsynth::buffer::AudioBufferIn;
let mut vec = Vec::with_capacity(2);
let channel1 = vec![11, 12, 13, 14];
let channel2 = vec![21, 22, 23, 24];
let chunk = [channel1.as_slice(), channel2.as_slice()];
let chunk = AudioBufferIn::new(&chunk, 4);
let parts = chunk.index_frames(1..2, &mut vec);
assert_eq!(parts.number_of_frames(), 1);
assert_eq!(parts.number_of_channels(), 2);
let channels = parts.channels();
assert_eq!(channels[0], &[12]);
assert_eq!(channels[1], &[22]);

pub fn index_frames_from_slice<'s, 'v, R>(
    &'s self,
    range: R,
    slice: &'v mut Slice<[S]>
) -> AudioBufferIn<'v, 's, S> where
    R: SliceIndex<[S], Output = [S]> + RangeBounds<usize> + Clone
[src]

Get an AudioBufferIn with all channels and the given range of frames.

The Slice will be used to store the channels of the result.

Usage in a real-time thread

This method will append number_of_channels elements to the given Slice. This will cause memory to be allocated if this exceeds the capacity of the given Slice.

Example

use rsynth::rsor::Slice;
use rsynth::buffer::AudioBufferIn;
let mut slice = Slice::with_capacity(2);
let channel1 = vec![11, 12, 13, 14];
let channel2 = vec![21, 22, 23, 24];
let chunk = [channel1.as_slice(), channel2.as_slice()];
let chunk = AudioBufferIn::new(&chunk, 4);
let parts = chunk.index_frames_from_slice(1..2, &mut slice);
assert_eq!(parts.number_of_frames(), 1);
assert_eq!(parts.number_of_channels(), 2);
let channels = parts.channels();
assert_eq!(channels[0], &[12]);
assert_eq!(channels[1], &[22]);

pub fn get_channel(&self, index: usize) -> Option<&[S]>[src]

Get the channel with the given index.

Return None when the index is out of bounds.

pub fn index_channel(&self, index: usize) -> &[S][src]

Get the channel with the given index.

Panics

Panics if the index is out of bounds.

Trait Implementations

impl<'channels, 'samples, S: Clone> Clone for AudioBufferIn<'channels, 'samples, S> where
    S: 'static + Copy
[src]

impl<'channels, 'samples, S: Copy> Copy for AudioBufferIn<'channels, 'samples, S> where
    S: 'static + Copy
[src]

impl<'channels, 'samples, S: Debug> Debug for AudioBufferIn<'channels, 'samples, S> where
    S: 'static + Copy
[src]

Auto Trait Implementations

impl<'channels, 'samples, S> RefUnwindSafe for AudioBufferIn<'channels, 'samples, S> where
    S: RefUnwindSafe

impl<'channels, 'samples, S> Send for AudioBufferIn<'channels, 'samples, S> where
    S: Sync

impl<'channels, 'samples, S> Sync for AudioBufferIn<'channels, 'samples, S> where
    S: Sync

impl<'channels, 'samples, S> Unpin for AudioBufferIn<'channels, 'samples, S> where
    'samples: 'channels, 

impl<'channels, 'samples, S> UnwindSafe for AudioBufferIn<'channels, 'samples, S> where
    S: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<S, T> Duplex<S> for T where
    T: FromSample<S> + ToSample<S>, 

impl<T> From<T> for T[src]

impl<S> FromSample<S> for S

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> ToSample<U> for T where
    U: FromSample<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.