Struct rsynth::buffer::AudioBufferIn [−][src]
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]
S: 'static + Copy,
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]
&'s self,
range: R,
vec: &'v mut Vec<&'s [S]>
) -> AudioBufferIn<'v, 's, S> where
R: SliceIndex<[S], Output = [S]> + RangeBounds<usize> + Clone,
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]
&'s self,
range: R,
slice: &'v mut Slice<[S]>
) -> AudioBufferIn<'v, 's, S> where
R: SliceIndex<[S], Output = [S]> + RangeBounds<usize> + Clone,
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]
Trait Implementations
impl<'channels, 'samples, S: Clone> Clone for AudioBufferIn<'channels, 'samples, S> where
S: 'static + Copy,
[src]
S: 'static + Copy,
fn clone(&self) -> AudioBufferIn<'channels, 'samples, S>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'channels, 'samples, S: Copy> Copy for AudioBufferIn<'channels, 'samples, S> where
S: 'static + Copy,
[src]
S: 'static + Copy,
impl<'channels, 'samples, S: Debug> Debug for AudioBufferIn<'channels, 'samples, S> where
S: 'static + Copy,
[src]
S: 'static + Copy,
Auto Trait Implementations
impl<'channels, 'samples, S> RefUnwindSafe for AudioBufferIn<'channels, 'samples, S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<'channels, 'samples, S> Send for AudioBufferIn<'channels, 'samples, S> where
S: Sync,
S: Sync,
impl<'channels, 'samples, S> Sync for AudioBufferIn<'channels, 'samples, S> where
S: Sync,
S: Sync,
impl<'channels, 'samples, S> Unpin for AudioBufferIn<'channels, 'samples, S> where
'samples: 'channels,
'samples: 'channels,
impl<'channels, 'samples, S> UnwindSafe for AudioBufferIn<'channels, 'samples, S> where
S: RefUnwindSafe,
S: 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<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> 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> 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>,