pub struct DelayLine { buffer: [f32; LEN], index: usize, } impl DelayLine { pub fn new() -> Self { Self { buffer: [0.0; LEN], index: 0, } } pub fn read_slice(&self, slice: &mut [f32]) { // Copy values in order for i in 0..LEN { slice[i] = self.buffer[(self.index + i - LEN) % LEN]; } } pub fn write_and_advance(&mut self, value: f32) { self.buffer[self.index] = value; if self.index == LEN - 1 { self.index = 0; } else { self.index += 1; } } }