Skip to main content

AudioSampleIterators

Trait AudioSampleIterators 

Source
pub trait AudioSampleIterators<'a, T>
where T: StandardSample,
{ // Required methods fn frames(&'a self) -> FrameIterator<'a, T> ; fn channels<'iter>(&'iter self) -> ChannelIterator<'iter, 'a, T> ; }
Expand description

Extension trait providing iterator methods for AudioSamples.

Required Methods§

Source

fn frames(&'a self) -> FrameIterator<'a, T>

Returns an iterator over frames, where each frame is a snapshot of one sample from each channel at the same point in time.

For mono audio, each frame contains exactly one sample. For multi-channel audio, each frame contains one sample per channel, preserving channel alignment across time.

§Returns

A FrameIterator that yields one AudioSamples view per time index. The total number of frames equals self.samples_per_channel().

§Panics

Does not panic.

§Examples
use audio_samples::{AudioSamples, sample_rate, iterators::AudioSampleIterators};
use ndarray::array;

let audio = AudioSamples::new_multi_channel(
    array![[1.0f32, 2.0], [3.0, 4.0]],
    sample_rate!(44100),
).unwrap();

// Each frame has one sample per channel; two time steps → two frames.
let mut count = 0;
for frame in audio.frames() {
    assert_eq!(frame.num_channels().get(), 2);
    count += 1;
}
assert_eq!(count, 2);
Source

fn channels<'iter>(&'iter self) -> ChannelIterator<'iter, 'a, T>

Returns an iterator over complete channels.

Each iteration yields the full temporal sequence of samples belonging to one channel. Channels are yielded in increasing channel-index order.

§Returns

A ChannelIterator that yields one owned AudioSamples per channel. The total number of items equals self.num_channels().

§Panics

Does not panic.

§Examples
use audio_samples::{AudioSamples, sample_rate, iterators::AudioSampleIterators};
use ndarray::array;

let audio = AudioSamples::new_multi_channel(
    array![[1.0f32, 2.0, 3.0], [4.0, 5.0, 6.0]],
    sample_rate!(44100),
).unwrap();

let channels: Vec<_> = audio.channels().collect();
assert_eq!(channels.len(), 2);
assert_eq!(channels[0].samples_per_channel().get(), 3);

Implementors§