Struct rsynth::buffer::AudioBufferOut[][src]

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

An audio output buffer.

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

Implementations

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

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

Create a new audio output buffer.

Panics

Panics if one of the elements of outputs 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 unsafe fn channels<'a>(&'a mut self) -> &'a mut [&'samples mut [S]][src]

Get the channels as slices.

Unsafe

This method is marked unsafe because using it allows to change the length of the channels, which invalidates the invariant.

pub fn split_channels_at<'a>(
    &'a mut self,
    mid: usize
) -> (AudioBufferOut<'a, 'samples, S>, AudioBufferOut<'a, 'samples, S>) where
    'a: 'channels, 
[src]

Split into two AudioBufferOuts. The first will contain the first mid-1 channels and the second will contain the remaining channels.

Panics

Panics if mid is > the number of output channels.

Example

use rsynth::buffer::AudioBufferOut;

let mut channel1 = vec![11, 12, 13, 14];
let mut channel2 = vec![21, 22, 23, 24];
let mut chunk = [channel1.as_mut_slice(), channel2.as_mut_slice()];

let mut buffer = AudioBufferOut::new(&mut chunk, 4);

let (mut firstchannels, mut secondchannels) = buffer.split_channels_at(1);
assert_eq!(firstchannels.number_of_channels(), 1);
assert_eq!(secondchannels.number_of_channels(), 1);

assert_eq!(firstchannels.index_channel(0), &[11, 12, 13, 14]);
assert_eq!(secondchannels.index_channel(0), &[21, 22, 23, 24]);

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

Get an AdioBufferOut with all channels and the given range of frames, using a vector to store the channels of the result.

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 threat

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::AudioBufferOut;

let mut channel1 = vec![11, 12, 13, 14];
let mut channel2 = vec![21, 22, 23, 24];
let mut channels = [channel1.as_mut_slice(), channel2.as_mut_slice()];
let number_of_channels = channels.len();
let mut buffer = AudioBufferOut::new(&mut channels, 4);
let mut vec = Vec::with_capacity(number_of_channels);
let mut sub_part = buffer.index_frames(1..2, &mut vec);
assert_eq!(sub_part.number_of_frames(), 1);
assert_eq!(sub_part.number_of_channels(), number_of_channels);
assert_eq!(sub_part.index_channel(0), &[12]);
assert_eq!(sub_part.index_channel(1), &[22]);

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

Get an AdioBufferOut with all channels and the given range of frames, using a Slice to store the channels of the result.

The parameter slice will be used to store the channels of the result.

Usage in a real-time threat

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::buffer::AudioBufferOut;
use rsynth::rsor::Slice;

let mut channel1 = vec![11, 12, 13, 14];
let mut channel2 = vec![21, 22, 23, 24];
let mut channels = [channel1.as_mut_slice(), channel2.as_mut_slice()];
let number_of_channels = channels.len();
let mut buffer = AudioBufferOut::new(&mut channels, 4);
let mut slice = Slice::with_capacity(number_of_channels);
let mut sub_part = buffer.index_frames_from_slice(1..2, &mut slice);
assert_eq!(sub_part.number_of_frames(), 1);
assert_eq!(sub_part.number_of_channels(), number_of_channels);
assert_eq!(sub_part.index_channel(0), &[12]);
assert_eq!(sub_part.index_channel(1), &[22]);

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

Get the channel with the given index.

Returns None if index is out of bonds.

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

Get the channel with the given index.

Panics

Panics if the index is out of bounds.

pub fn set(&mut self, value: S)[src]

Set all samples to the given value.

pub fn channel_iter_mut<'a>(
    &'a mut self
) -> AudioBufferOutChannelIteratorMut<'a, 'samples, S>

Notable traits for AudioBufferOutChannelIteratorMut<'channels, 'samples, S>

impl<'channels, 'samples, S> Iterator for AudioBufferOutChannelIteratorMut<'channels, 'samples, S> type Item = &'channels mut [S];
[src]

Get an iterator over the channels.

pub fn as_audio_buffer_in<'s, 'vec>(
    &'s self,
    vec: &'vec mut Vec<&'s [S]>
) -> AudioBufferIn<'vec, 's, S>
[src]

Convert to an AudioBufferIn.

Trait Implementations

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

Auto Trait Implementations

impl<'channels, 'out_samples, S> RefUnwindSafe for AudioBufferOut<'channels, 'out_samples, S> where
    S: RefUnwindSafe

impl<'channels, 'out_samples, S> Send for AudioBufferOut<'channels, 'out_samples, S> where
    S: Send

impl<'channels, 'out_samples, S> Sync for AudioBufferOut<'channels, 'out_samples, S> where
    S: Sync

impl<'channels, 'out_samples, S> Unpin for AudioBufferOut<'channels, 'out_samples, S> where
    'out_samples: 'channels, 

impl<'channels, 'out_samples, S> !UnwindSafe for AudioBufferOut<'channels, 'out_samples, S>

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, 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.