Skip to main content

NdarrayAdapter

Struct NdarrayAdapter 

Source
pub struct NdarrayAdapter<U, O> { /* private fields */ }
Expand description

A wrapper implementing the audioadapter traits for a two-dimensional ndarray array.

The axis order O records whether the array is channel-major (ChannelsFrames) or frame-major (FramesChannels).

Implementations§

Source§

impl<S> NdarrayAdapter<ArrayBase<S, Ix2>, ChannelsFrames>
where S: Data,

Source

pub fn new_channels_frames(array: ArrayBase<S, Ix2>) -> Self

Wrap an array shaped (channels, frames).

Source§

impl<S> NdarrayAdapter<ArrayBase<S, Ix2>, FramesChannels>
where S: Data,

Source

pub fn new_frames_channels(array: ArrayBase<S, Ix2>) -> Self

Wrap an array shaped (frames, channels).

Source§

impl<U, O> NdarrayAdapter<U, O>

Source

pub fn into_inner(self) -> U

Consume the adapter and return the wrapped array.

Source

pub fn inner(&self) -> &U

Get a reference to the wrapped array.

Trait Implementations§

Source§

impl<S, O> Adapter<<S as RawData>::Elem> for NdarrayAdapter<ArrayBase<S, Ix2>, O>
where S: Data, S::Elem: Clone, O: AxisOrder,

Source§

fn channels(&self) -> usize

Get the number of channels stored in this buffer.
Source§

fn frames(&self) -> usize

Get the number of frames stored in this buffer.
Source§

unsafe fn read_sample_unchecked(&self, channel: usize, frame: usize) -> S::Elem

Read the sample at a given combination of frame and channel. Read more
Source§

fn copy_from_channel_to_slice( &self, channel: usize, skip: usize, slice: &mut [S::Elem], ) -> usize

Copy values from a channel of self to a slice. The skip argument is the offset in samples from where the first value will be copied. If the target slice is longer than the available number of values in the channel, then only the available number of samples will be copied. Read more
Source§

fn read_sample(&self, channel: usize, frame: usize) -> Option<T>

Read the sample at a given combination of frame and channel. Returns None if the frame or channel is out of bounds of the buffer.
Source§

fn copy_from_frame_to_slice( &self, frame: usize, skip: usize, slice: &mut [T], ) -> usize

Copy values from a frame of self to a slice. The skip argument is the offset in samples from where the first value will be copied. If the slice is longer than the available number of values in the frame, then only the available number of samples will be copied. Read more
Source§

impl<S, O> AdapterMut<<S as RawData>::Elem> for NdarrayAdapter<ArrayBase<S, Ix2>, O>
where S: DataMut, S::Elem: Clone, O: AxisOrder,

Source§

unsafe fn write_sample_unchecked( &mut self, channel: usize, frame: usize, value: &S::Elem, ) -> bool

Write a sample to the given combination of frame and channel. Returns a boolean indicating if the sample value was clipped during conversion. Implementations that do not perform any conversion always return false. Read more
Source§

fn copy_from_slice_to_channel( &mut self, channel: usize, skip: usize, slice: &[S::Elem], ) -> (usize, usize)

Copies values from a slice into a channel of self. The skip argument is the offset into the channel to where the first value will be copied. If the slice is longer than the available space in the channel, then only the number of samples that fit will be copied. Read more
Source§

fn write_sample( &mut self, channel: usize, frame: usize, value: &T, ) -> Option<bool>

Write a sample to the given combination of frame and channel. Returns a boolean indicating if the sample value was clipped during conversion. Implementations that do not perform any conversion always return false. Returns None if the frame or channel is out of bounds of the buffer.
Source§

fn copy_from_slice_to_frame( &mut self, frame: usize, skip: usize, slice: &[T], ) -> (usize, usize)

Copy values from a slice into a frame of self. The skip argument is the offset into the frame to where the first value will be copied. If the slice is longer than the available space in the frame, then only the number of samples that fit will be copied. Read more
Source§

fn copy_from_other_to_channel( &mut self, other: &dyn Adapter<T>, other_channel: usize, self_channel: usize, other_skip: usize, self_skip: usize, take: usize, ) -> Option<usize>

Copy values from a channel of another Adapter. The self_skip and other_skip arguments are the offsets in frames for where copying starts in the two channels. The method copies take values. Read more
Source§

fn copy_from_other( &mut self, other: &dyn Adapter<T>, other_skip: usize, self_skip: usize, take: usize, ) -> Option<usize>

Copy values from another Adapter into self. The self_skip and other_skip arguments are the offsets in frames for where copying starts in the two buffers. The method copies take frames for all channels in other. Read more
Source§

fn fill_channel_with(&mut self, channel: usize, value: &T) -> Option<()>

Write the provided value to every sample in a channel. Can be used to clear a channel by writing zeroes, or to initialize each sample to a certain value. Returns None if called with an invalid channel number.
Source§

fn fill_frame_with(&mut self, frame: usize, value: &T) -> Option<()>

Write the provided value to every sample in a frame. Can be used to clear a frame by writing zeroes, or to initialize each sample to a certain value. Returns None if called with an invalid frame number.
Source§

fn fill_frames_with( &mut self, start: usize, count: usize, value: &T, ) -> Option<usize>

Write the provided value to every sample in a range of frames. Can be used to clear a range of frames by writing zeroes, or to initialize each sample to a certain value. Returns None if called with a too large range.
Source§

fn fill_with(&mut self, value: &T)

Write the provided value to every sample in the entire buffer. Can be used to clear a buffer by writing zeroes, or to initialize each sample to a certain value.
Source§

fn copy_frames_within( &mut self, src: usize, dest: usize, count: usize, ) -> Option<usize>

Copy frames within the buffer. Copying is performed for all channels. Copies count frames, from the range src..src+count, to the range dest..dest+count. The two regions are allowed to overlap. The default implementation copies by calling the read and write methods, while type specific implementations can use more efficient methods.
Source§

fn copy_sample_within( &mut self, source_channel: usize, source_frame: usize, target_channel: usize, target_frame: usize, ) -> bool

Copy a single sample within the buffer. Copies from the source to the target frame and channel. Returns true if the sample was copied, and false if not, which may happen if the source or target frame or channel was out of bounds. The default implementation copies by calling the read and write methods, while type specific implementations can use more efficient methods.
Source§

fn swap_samples( &mut self, channel_a: usize, frame_a: usize, channel_b: usize, frame_b: usize, ) -> bool

Swap two samples in the buffer. Returns true if the samples were swapped, and false if not, which may happen if the channel or frame for either sample was out of bounds. The default implementation copies by calling the read and write methods, while type specific implementations can use more efficient methods.

Auto Trait Implementations§

§

impl<U, O> Freeze for NdarrayAdapter<U, O>
where U: Freeze, PhantomData<O>: Freeze,

§

impl<U, O> RefUnwindSafe for NdarrayAdapter<U, O>

§

impl<U, O> Send for NdarrayAdapter<U, O>
where U: Send, PhantomData<O>: Send,

§

impl<U, O> Sync for NdarrayAdapter<U, O>
where U: Sync, PhantomData<O>: Sync,

§

impl<U, O> Unpin for NdarrayAdapter<U, O>
where U: Unpin, PhantomData<O>: Unpin,

§

impl<U, O> UnsafeUnpin for NdarrayAdapter<U, O>

§

impl<U, O> UnwindSafe for NdarrayAdapter<U, O>

Blanket Implementations§

Source§

impl<T, U> AdapterIterators<T> for U
where T: Clone, U: Adapter<T>,

Source§

fn iter_channel(&self, channel: usize) -> Option<ChannelSamples<'_, T>>

Get an iterator that yields the sample value of the specified channel.
Source§

fn iter_channels(&self) -> Channels<'_, T>

Get an iterator that yields iterators for the channels.
Source§

fn iter_frame(&self, frame: usize) -> Option<FrameSamples<'_, T>>

Get an iterator that yields the sample values of the specified frame.
Source§

fn iter_frames(&self) -> Frames<'_, T>

Get an iterator that yields iterators for the frames.
Source§

impl<T, U> AdapterStats<T> for U
where T: StatsSample, U: Adapter<T>,

Source§

fn channel_sum(&self, channel: usize) -> f64

Calculate the sum of all the samples of the given channel. The result is returned as f64. An empty buffer, or a channel index that is out of bounds, gives a sum of zero. Read more
Source§

fn frame_sum(&self, frame: usize) -> f64

Calculate the sum of all the samples of the given frame. The result is returned as f64. An empty buffer, or a frame index that is out of bounds, gives a sum of zero.
Source§

fn channel_sum_of_squares(&self, channel: usize) -> f64

Calculate the sum of the squares of all the samples of the given channel. The result is returned as f64. An empty buffer, or a channel index that is out of bounds, gives a sum of zero. Read more
Source§

fn frame_sum_of_squares(&self, frame: usize) -> f64

Calculate the sum of the squares of all the samples of the given frame. The result is returned as f64. An empty buffer, or a frame index that is out of bounds, gives a sum of zero.
Source§

fn channel_rms(&self, channel: usize) -> f64

Calculate the RMS value of the given channel. The result is returned as f64.
Source§

fn frame_rms(&self, frame: usize) -> f64

Calculate the RMS value of the given frame. The result is returned as f64.
Source§

fn channel_mean(&self, channel: usize) -> f64

Calculate the mean (average) value of the given channel. The result is returned as f64. For audio samples this is the DC offset of the channel.
Source§

fn frame_mean(&self, frame: usize) -> f64

Calculate the mean (average) value of the given frame. The result is returned as f64.
Source§

fn channel_min_and_max(&self, channel: usize) -> (T, T)

Calculate the peak-to-peak value of the given channel. The result is returned as a tuple (min, max) with values of the same type as the samples. An empty buffer, or a channel index that is out of bounds, gives a result of (0, 0).
Source§

fn channel_peak_to_peak(&self, channel: usize) -> f64

Calculate the peak-to-peak value of the given channel. The result is returned as f64.
Source§

fn channel_peak(&self, channel: usize) -> f64

Calculate the peak value, the largest absolute sample value, of the given channel. The result is returned as f64, since the absolute value of the most negative sample does not fit in the sample type. This is the value shown by a peak meter. Read more
Source§

fn frame_min_and_max(&self, frame: usize) -> (T, T)

Calculate the peak-to-peak value of the given frame. The result is returned as a tuple (min, max) with values of the same type as the samples. An empty buffer, or a frame index that is out of bounds, gives a result of (0, 0).
Source§

fn frame_peak_to_peak(&self, frame: usize) -> f64

Calculate the peak-to-peak value of the given frame. The result is returned as f64.
Source§

fn frame_peak(&self, frame: usize) -> f64

Calculate the peak value, the largest absolute sample value, of the given frame. The result is returned as f64, see AdapterStats::channel_peak.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.