Struct rsynth::buffer::AudioBufferOut [−][src]
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]
S: 'static + Copy,
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]
&'a mut self,
mid: usize
) -> (AudioBufferOut<'a, 'samples, S>, AudioBufferOut<'a, 'samples, S>) where
'a: 'channels,
Split into two AudioBufferOut
s.
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]
&'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,
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]
&'s mut self,
range: R,
slice: &'v mut Slice<[S]>
) -> AudioBufferOut<'v, 's, S> where
R: SliceIndex<[S], Output = [S]> + RangeBounds<usize> + Clone,
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]
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]
&'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];
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]
&'s self,
vec: &'vec mut Vec<&'s [S]>
) -> AudioBufferIn<'vec, 's, S>
Convert to an AudioBufferIn
.
Trait Implementations
impl<'channels, 'out_samples, S: Debug> Debug for AudioBufferOut<'channels, 'out_samples, S> where
S: 'static + Copy,
[src]
S: 'static + Copy,
Auto Trait Implementations
impl<'channels, 'out_samples, S> RefUnwindSafe for AudioBufferOut<'channels, 'out_samples, S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<'channels, 'out_samples, S> Send for AudioBufferOut<'channels, 'out_samples, S> where
S: Send,
S: Send,
impl<'channels, 'out_samples, S> Sync for AudioBufferOut<'channels, 'out_samples, S> where
S: Sync,
S: Sync,
impl<'channels, 'out_samples, S> Unpin for AudioBufferOut<'channels, 'out_samples, S> where
'out_samples: 'channels,
'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]
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<S, T> Duplex<S> for T where
T: FromSample<S> + ToSample<S>,
T: FromSample<S> + ToSample<S>,
impl<T> From<T> for T
[src]
impl<S> FromSample<S> for S
pub fn from_sample_(s: S) -> S
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> ToSample<U> for T where
U: FromSample<T>,
U: FromSample<T>,
pub fn to_sample_(self) -> U
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>,