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].
Play an mp3 file with [minimp3-rs], [cpal], and [rubato] for resampling.
bash
cargo --manifest-path=examples/Cargo.toml --release --bin play-mp3 -- path/to/file.mp3
```rust use rand::Rng as _;
let mut buffer = rotary::Dynamic::
buffer.resize_channels(2); buffer.resize(2048);
/// Fill both channels with random noise. let mut rng = rand::thread_rng(); rng.fill(&mut buffer[0]); rng.fill(&mut buffer[1]); ```
You can use the included [Mask] trait to separately keep track of active and
inactive channels in an audio buffer. This requires that you specify the
type of the mask. A good option for this is a [BitSet
```rust use rotary::{BitSet, Mask as _};
let mut buffer = rotary::Dynamic::
for chan in mask.join(buffer.iter_mut()) { for b in chan { *b = 1.0; } }
let zeroed = vec![0.0f32; 1024]; let expected = vec![1.0f32; 1024];
asserteq!(&buffer[0], &expected[..]); asserteq!(&buffer[1], &zeroed[..]); asserteq!(&buffer[2], &expected[..]); asserteq!(&buffer[3], &expected[..]); ```
For convenience we also provide the [dynamic!] macro when constructing audio buffers.
```rust use rotary::BitSet;
let mut buf = rotary::Dynamic::
for channel in &mut buf { for f in channel { *f = 2.0; } }
assert_eq!(buf, rotary::dynamic![[2.0; 128]; 4]) ```
License: MIT/Apache-2.0