Crate rotary[−][src]
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.
use rand::Rng as _; let mut buffer = rotary::Dynamic::<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 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
use rotary::{BitSet, Mask as _}; let mut buffer = rotary::Dynamic::<f32>::with_topology(4, 1024); let mask: rotary::BitSet<u128> = rotary::bit_set![0, 2, 3]; 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]; assert_eq!(&buffer[0], &expected[..]); assert_eq!(&buffer[1], &zeroed[..]); assert_eq!(&buffer[2], &expected[..]); assert_eq!(&buffer[3], &expected[..]);
For convenience we also provide the dynamic! macro when constructing audio buffers.
use rotary::BitSet; let mut buf = rotary::Dynamic::<f32>::with_topology(4, 128); for channel in &mut buf { for f in channel { *f = 2.0; } } assert_eq!(buf, rotary::dynamic![[2.0; 128]; 4])
Re-exports
pub use self::bit_set::BitSet; |
pub use self::buf::Buf; |
pub use self::buf::BufMut; |
pub use self::channel::Channel; |
pub use self::channel::ChannelMut; |
pub use self::dynamic::Dynamic; |
pub use self::interleaved::Interleaved; |
pub use self::mask::Mask; |
pub use self::sequential::Sequential; |
Modules
bit_set | A fixed size bit set. |
buf | Trait for dealing with abstract channel buffers. |
channel | A channel buffer as created through Buf::channel or BufMut::channel_mut. |
dynamic | A dynamically sized, multi-channel audio buffer. |
interleaved | A dynamically sized, multi-channel interleaved audio buffer. |
mask | Utilities used for masking indexes. |
sequential | A dynamically sized, multi-channel sequential audio buffer. |
utils | Utilities for manipulating audio buffers. |
wrap |
Macros
bit_set | Construct a bit set with specific values set. |
dynamic | Construct an audio buffer. |
interleaved | Construct an interleaved audio buffer. |
sequential | Construct a sequential audio buffer. |
Traits
Sample | A sample that can be stored in an audio buffer. Types implementing this are known as being sample apt. |
Translate | Trait used for translating one sample type to another. |