Struct rsynth::buffer::AudioBufferInOut[][src]

pub struct AudioBufferInOut<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> where
    S: 'static + Copy
{ /* fields omitted */ }

A buffer holding both input and output audio.

All inputs and all outputs are guaranteed to have the same number of frames.

Implementations

impl<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> AudioBufferInOut<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> where
    S: 'static + Copy
[src]

pub fn new(
    inputs: &'in_channels [&'in_samples [S]],
    outputs: &'out_channels mut [&'out_samples mut [S]],
    length: usize
) -> Self
[src]

Create a new AudioBufferInOut.

Panics

Panics if one of the following happens:

  • not all elements of inputs have the same length,
  • not all elements of outputs have the same length,
  • not all elements of inputs have the same length as all the elements of outputs

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

Get the number of frames.

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

Get the number of input channels.

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

Get the number of output channels.

pub fn split_output_channels_at<'a>(
    &'a mut self,
    mid: usize
) -> (AudioBufferInOut<'in_channels, 'in_samples, 'a, 'out_samples, S>, AudioBufferInOut<'in_channels, 'in_samples, 'a, 'out_samples, S>) where
    'a: 'out_channels, 
[src]

Create two new AUdioBufferInOuts: one with all the input channels and with the output channels from 0 to mid, excluding mid and one with all the input channels and with the output channels from mid including onwards.

Panics

Panics if mid is > the number of output channels.

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

Get the input channel with the given index.

Returns None when index is out of bounds.

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

Get the output channel with the given index.

Panics

Panics if the index is out of bounds.

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

Get the output channel with the given index.

Returns None when index is out of bounds.

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

Get the output channel with the given index.

Panics

Panics if the index is out of bounds.

pub fn index_frames<'s, 'in_vec, 'out_vec, R>(
    &'s mut self,
    range: R,
    vec_in: &'in_vec mut Vec<&'s [S]>,
    vec_out: &'out_vec mut Vec<&'s mut [S]>
) -> AudioBufferInOut<'in_vec, 's, 'out_vec, 's, S> where
    R: SliceIndex<[S], Output = [S]> + RangeBounds<usize> + Clone
[src]

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

The vectors vec_in and vec_out will be used to store the channels of the result.

Remark

The vectors vec_in and vec_out 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 push number_of_input_channels elements to the given “input” vector and number_of_output_channels to the “output” 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::AudioBufferInOut;

let channel1_in = vec![11, 12, 13, 14];
let channel2_in = vec![21, 22, 23, 24];
let channels_in = [channel1_in.as_slice(), channel2_in.as_slice()];
let number_of_input_channels = channels_in.len();
let mut channel1_out = vec![110, 120, 130, 140];
let mut channels_out = [channel1_out.as_mut_slice()];
let number_of_output_channels = channels_out.len();
let mut buffer = AudioBufferInOut::new(&channels_in, &mut channels_out, 4);
let mut vec_in = Vec::with_capacity(number_of_input_channels);
let mut vec_out = Vec::with_capacity(number_of_output_channels);
let mut sub_part = buffer.index_frames(1..2, &mut vec_in, &mut vec_out);
assert_eq!(sub_part.number_of_frames(), 1);
assert_eq!(sub_part.number_of_input_channels(), number_of_input_channels);
assert_eq!(sub_part.number_of_output_channels(), number_of_output_channels);
assert_eq!(sub_part.index_input_channel(0), &[12]);
assert_eq!(sub_part.index_input_channel(1), &[22]);
assert_eq!(sub_part.index_output_channel(0), &[120]);

pub fn index_frames_from_slices<'s, 'in_slice, 'out_slice, R>(
    &'s mut self,
    range: R,
    slice_in: &'in_slice mut Slice<[S]>,
    slice_out: &'out_slice mut Slice<[S]>
) -> AudioBufferInOut<'in_slice, 's, 'out_slice, 's, S> where
    R: SliceIndex<[S], Output = [S]> + RangeBounds<usize> + Clone
[src]

Get an AudioBufferInOut with all channels and with the given range of frames, using rsor’s Slices to store the output.

This method is behind the “rsor-0-1” Cargo feature. This method is similar to the index_frames method.

Usage in a real-time thread

This method will push number_of_input_channels elements to the given “input” Slice and number_of_output_channels to the “output” Slice. This will cause memory to be allocated if this exceeds the capacity of the given vector.

Example

use rsynth::rsor::Slice;
use rsynth::buffer::AudioBufferInOut;

let channel1_in = vec![11, 12, 13, 14];
let channel2_in = vec![21, 22, 23, 24];
let channels_in = [channel1_in.as_slice(), channel2_in.as_slice()];
let number_of_input_channels = channels_in.len();
let mut channel1_out = vec![110, 120, 130, 140];
let mut channels_out = [channel1_out.as_mut_slice()];
let number_of_output_channels = channels_out.len();
let mut buffer = AudioBufferInOut::new(&channels_in, &mut channels_out, 4);
let mut slice_in = Slice::with_capacity(number_of_input_channels);
let mut slice_out = Slice::with_capacity(number_of_output_channels);
let mut sub_part = buffer.index_frames_from_slices(1..2, &mut slice_in, &mut slice_out);
assert_eq!(sub_part.number_of_frames(), 1);
assert_eq!(sub_part.number_of_input_channels(), number_of_input_channels);
assert_eq!(sub_part.number_of_output_channels(), number_of_output_channels);
assert_eq!(sub_part.index_input_channel(0), &[12]);
assert_eq!(sub_part.index_input_channel(1), &[22]);
assert_eq!(sub_part.index_output_channel(0), &[120]);

pub fn separate<'s>(
    &'s mut self
) -> (AudioBufferIn<'in_channels, 'in_samples, S>, AudioBufferOut<'s, 'out_samples, S>)
[src]

Separate the input channels from the output channels.

Separates the AudioBufferInOut into an AudioBufferIn and an AudioBufferOut.

Example

use rsynth::buffer::AudioBufferInOut;

let channel1_in = vec![11, 12, 13, 14];
let channel2_in = vec![21, 22, 23, 24];
let channels_in = [channel1_in.as_slice(), channel2_in.as_slice()];
let number_of_input_channels = channels_in.len();
let mut channel1_out = vec![110, 120, 130, 140];
let mut channels_out = [channel1_out.as_mut_slice()];
let number_of_output_channels = channels_out.len();
let mut buffer = AudioBufferInOut::new(&channels_in, &mut channels_out, 4);

let (input_buffer, output_buffer) = buffer.separate();

pub fn inputs(&self) -> &AudioBufferIn<'in_channels, 'in_samples, S>[src]

Get the input channels as an AudioBufferIn.

pub fn outputs(&mut self) -> &mut AudioBufferOut<'out_channels, 'out_samples, S>[src]

Get the output channels as an AudioBufferOut.

pub fn interleave_with_slice<I, E, C, FR, FE>(
    &mut self,
    input_slice: &mut Slice<[S]>,
    output_slice: &mut Slice<[S]>,
    iterator: I,
    context: &mut C,
    render: FR,
    handle_event: FE
) where
    S: Copy + 'static,
    I: Iterator<Item = (usize, E)>,
    FR: Fn(&mut C, &mut AudioBufferInOut<'_, '_, '_, '_, S>),
    FE: Fn(&mut C, E), 
[src]

Interleave actions on subsequent frames with other actions, such as handling events, Similar to the interleave method, but using the the Slice struct from the rsor crate.

This method is behind the rsor-0-1 feature. See the documentation of interleave for more information.

Note

If the iterator yields items for which the time is > self.number_of_frames, all these items will be handled after the audio.

pub fn interleave<I, E, C, FR, FE>(
    &mut self,
    input_storage: &mut VecStorage<&'static [S]>,
    output_storage: &mut VecStorage<&'static [S]>,
    iterator: I,
    context: &mut C,
    render: FR,
    handle_event: FE
) where
    S: Copy + 'static,
    I: Iterator<Item = (usize, E)>,
    FR: Fn(&mut C, &mut AudioBufferInOut<'_, '_, '_, '_, S>),
    FE: Fn(&mut C, E), 
[src]

Interleave actions on subsequent frames with other actions, such as handling events.

Apart from the input_storage and output_storage, which are only used for technical purposes, this method has the following parameters:

  • iterator: an iterator, yielding items of type (usize, E), where E is a generic type parameter.
  • context: some context, see below
  • render: a function that will be called with two parameters: the context and a sub-chunk
  • handle_event: a function that will be called for every item yielded by the iterator.

Note

If the iterator yields items for which the time is > self.number_of_frames, all these items will be handled after the audio.

Example

use rsynth::audio_chunk;
use rsynth::vecstorage::VecStorage;
use rsynth::buffer::AudioBufferInOut;

let input = audio_chunk![[11, 12, 13, 14], [21, 22, 23, 24]];
let mut provided_output = audio_chunk![[0, 0, 0, 0], [0, 0, 0, 0]];
let mut events = vec![(0 as usize, 1), (0, 2), (2, 3), (2, 4), (4, 5)];
let input = input.as_slices();
let mut output_as_slices = provided_output.as_mut_slices();
let mut buffer = AudioBufferInOut::new(&input, &mut output_as_slices, 4);

buffer.interleave(
    &mut VecStorage::with_capacity(2),
    &mut VecStorage::with_capacity(2),
    events.drain(..),
    &mut (),
    |&mut _context, buf: &mut AudioBufferInOut<i32>| {
        println!("Audio: {:?}", buf);
    },
    |&mut _context, e| {
        println!("Event: {}", e);
    },
);
// This will first print "Event: 1", "Event: 2", then debug-print the first two frames
// of the audio, then "Event: 3", "Event: 4", then debug-print the remaining two frames
// of the audio and then debug-print "Event: 5".

Trait Implementations

impl<'in_channels, 'in_samples, 'out_channels, 'out_samples, S: Debug> Debug for AudioBufferInOut<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> where
    S: 'static + Copy
[src]

Auto Trait Implementations

impl<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> RefUnwindSafe for AudioBufferInOut<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> where
    S: RefUnwindSafe

impl<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> Send for AudioBufferInOut<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> where
    S: Send + Sync

impl<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> Sync for AudioBufferInOut<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> where
    S: Sync

impl<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> Unpin for AudioBufferInOut<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> where
    'in_samples: 'in_channels,
    'out_samples: 'out_channels, 

impl<'in_channels, 'in_samples, 'out_channels, 'out_samples, S> !UnwindSafe for AudioBufferInOut<'in_channels, 'in_samples, 'out_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.