Expand description
Wrappers providing direct access to samples in buffers.
§Direct wrappers
This module is a collection of wrappers that implement the
audioadapter traits for various data structures.
These wrap data structures where the samples are already stored in the desired format.
§Available wrappers
Wrappers are available for plain slices, &[T],
and slices of vectors, &[Vec<T>].
Each wrapper exist in an interleaved and sequential version.
§Example
Wrap a Vec of i32 as an interleaved buffer and print all the values.
use audioadapter::direct::InterleavedSlice;
use audioadapter::Adapter;
// make a vector with some dummy data.
// 2 channels * 3 frames => 6 samples
let data: Vec<i32> = vec![1, 2, 3, 4, 5, 6];
// wrap the data
let buffer = InterleavedSlice::new(&data, 2, 3).unwrap();
// Loop over all samples and print their values
for channel in 0..buffer.channels() {
for frame in 0..buffer.frames() {
let value = buffer.read_sample(channel, frame).unwrap();
println!(
"Channel: {}, frame: {}, value: {}",
channel, frame, value
);
}
}Structs§
- Interleaved
Slice - Wrapper for a slice of length
frames * channels. The samples are stored in interleaved order, where all the samples for one frame are stored consecutively, followed by the samples for the next frame. For a stereo buffer containing four frames, the order isL1, R1, L2, R2, L3, R3, L4, R4 - Interleaved
Slice OfVecs - Wrapper for a slice of length
frames, containing vectors of lengthchannels. Each vector contains the samples for all channels of one frame. - Sequential
Slice - Wrapper for a slice of length
frames * channels. The samples are stored in sequential order, where all the samples for one channel are stored consecutively, followed by the samples for the next channel. For a stereo buffer containing four frames, the order isL1, L2, L3, L4, R1, R2, R3, R4 - Sequential
Slice OfVecs - Wrapper for a slice of length
channels, containing vectors of lengthframes. Each vector contains the samples for all frames of one channel. - Sparse
Sequential Slice OfVecs - Wrapper for a slice of length
channels, containing vectors of lengthframes. Each vector contains the samples for all frames of one channel. This is similar to SequentialSliceOfVecs, but here vectors for unused channels may be empty. Reading from an unused channel returnsT::default(), while writing does nothing.