Crate rotary[][src]

Documentation Crates Actions Status

A library for dealing efficiently with AudioBuffer non-interleaved 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 AudioBuffer::resize.

use rand::Rng as _;

let mut buffer = rotary::AudioBuffer::<f32>::new();

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 masked audio buffers if you need the ability to temporarily enable or disable channels. This requires that you specify the type of the mask. A good option for this is a BitSet, which supports up to 128 channels.

use rotary::BitSet;

let mut buffer = rotary::MaskedAudioBuffer::<f32, BitSet<u128>>::with_topology(4, 128);

buffer.mask(1);

for  channel in buffer.iter_mut() {
    for b in channel {
        *b = 1.0;
    }
}

let expected = vec![1.0f32; 128];

assert_eq!(&buffer[0], &expected[..]);
assert_eq!(&buffer[1], &[][..]);
assert_eq!(&buffer[2], &expected[..]);
assert_eq!(&buffer[3], &expected[..]);

For convenience we also provide the audio_buffer! macro when constructing audio buffers.

use rotary::BitSet;

let mut buf = rotary::AudioBuffer::<f32>::with_topology(4, 128);

for channel in &mut buf {
    for f in channel {
        *f = 2.0;
    }
}

assert_eq!(buf, rotary::audio_buffer![[2.0; 128]; 4])

Re-exports

pub use self::audio_buffer::AudioBuffer;
pub use self::bit_set::BitSet;
pub use self::masked_audio_buffer::MaskedAudioBuffer;

Modules

audio_buffer

A dynamically sized, multi-channel audio buffer.

bit_set

A fixed size bit set.

channel

A reference to a channel in a buffer.

masked_audio_buffer

A dynamically sized, multi-channel audio buffer that supports.

Macros

audio_buffer

Construct an audio buffer.

interleaved

Construct an interleaved audio buffer.

sequential

Construct a sequential audio buffer.

Structs

BufChannel

The buffer of a single channel.

Interleaved

A dynamically sized, multi-channel interleaved audio buffer.

Sequential

A dynamically sized, multi-channel sequential audio buffer.

Traits

Buf

A trait describing an immutable audio buffer.

Mask

The trait for a mask that can be used with crate::MaskedAudioBuffer.

Sample

A sample that can be stored in an audio buffer. Types implementing this are known as being sample apt.