rotary
A library for working with audio buffers
The buffer is constructed similarly to a Vec<Vec<T>>
, except the interior
vector has a fixed size. And the buffer makes no attempt to clear data which
is freed when using functions such as Dynamic::resize.
Formats and topologies
The following are the three canonical audio formats which are supported by this library:
- dynamic - where each channel is stored in its own heap-allocated buffer.
- interleaved - where each channel is interleaved, like
0:0, 1:0, 1:0, 1:1
. - sequential - where each channel is stored in a linear
buffer, one after another. Like
0:0, 0:1, 1:0, 1:0
.
These all implement the Buf and BufMut traits, allowing library authors to abstract over any one specific format. The exact channel and frame count of a buffer is known as its topology.
use BufMut as _;
let mut dynamic = dynamic!;
let mut interleaved = interleaved!;
let mut sequential = sequential!;
dynamic.channel_mut.copy_from_iter;
interleaved.channel_mut.copy_from_iter;
sequential.channel_mut.copy_from_iter;
We also support wrapping external buffers so that they can interoperate like other rotary buffers.
Example: play-mp3
Play an mp3 file with minimp3-rs, cpal, and rubato for resampling.
This example can handle with any channel and sample rate configuration.
Examples
use Rng as _;
let mut buffer = new;
buffer.resize_channels;
buffer.resize;
/// Fill both channels with random noise.
let mut rng = thread_rng;
rng.fill;
rng.fill;
For convenience we also provide several macros for constructing various forms of dynamic audio buffers. These should mostly be used for testing.
let mut buf = with_topology;
for channel in &mut buf
assert_eq! ;
assert_eq! ;
License: MIT/Apache-2.0