pub type NodeId = usize;
pub const MAX_BLOCK_SIZE: usize = 128;
#[repr(C, align(64))]
pub struct AlignedBuffer<const N: usize> {
pub data: [f32; N],
}
impl<const N: usize> AlignedBuffer<N> {
pub const fn new() -> Self {
Self { data: [0.0; N] }
}
pub fn as_slice(&self) -> &[f32] {
&self.data
}
pub fn as_mut_slice(&mut self) -> &mut [f32] {
&mut self.data
}
}
impl<const N: usize> Default for AlignedBuffer<N> {
fn default() -> Self {
Self::new()
}
}
pub struct SignalBuffer {
buffer: AlignedBuffer<MAX_BLOCK_SIZE>,
len: usize,
}
impl SignalBuffer {
pub fn new() -> Self {
Self {
buffer: AlignedBuffer::new(),
len: 0,
}
}
pub fn resize(&mut self, len: usize) {
assert!(len <= MAX_BLOCK_SIZE);
self.len = len;
}
pub fn len(&self) -> usize {
self.len
}
pub fn is_empty(&self) -> bool {
self.len == 0
}
pub fn as_slice(&self) -> &[f32] {
&self.buffer.data[..self.len]
}
pub fn as_mut_slice(&mut self) -> &mut [f32] {
&mut self.buffer.data[..self.len]
}
pub fn clear(&mut self) {
for i in 0..self.len {
self.buffer.data[i] = 0.0;
}
}
}
impl Default for SignalBuffer {
fn default() -> Self {
Self::new()
}
}