diff --git a/plugins/buffr_glitch/src/buffer.rs b/plugins/buffr_glitch/src/buffer.rs index 65455fbe..ceaa9f2b 100644 --- a/plugins/buffr_glitch/src/buffer.rs +++ b/plugins/buffr_glitch/src/buffer.rs @@ -49,6 +49,23 @@ impl RingBuffer { for buffer in self.buffers.iter_mut() { buffer.fill(0.0); } + self.next_write_pos = 0; } + + /// Push a sample to the buffer. The write position is advanced whenever the last channel is + /// written to. + pub fn push(&mut self, channel_idx: usize, sample: f32) { + self.buffers[channel_idx][self.next_write_pos] = sample; + + // TODO: This can be done more efficiently, but you really won't notice the performance + // impact here + if channel_idx == self.buffers.len() - 1 { + self.next_write_pos += 1; + + if self.next_write_pos == self.buffers[0].len() { + self.next_write_pos = 0; + } + } + } } diff --git a/plugins/buffr_glitch/src/lib.rs b/plugins/buffr_glitch/src/lib.rs index 9e151a4c..975c5a0c 100644 --- a/plugins/buffr_glitch/src/lib.rs +++ b/plugins/buffr_glitch/src/lib.rs @@ -90,10 +90,16 @@ impl Plugin for BuffrGlitch { fn process( &mut self, - _buffer: &mut Buffer, + buffer: &mut Buffer, _aux: &mut AuxiliaryBuffers, _context: &mut impl ProcessContext, ) -> ProcessStatus { + for channel_samples in buffer.iter_samples() { + for (channel_idx, sample) in channel_samples.into_iter().enumerate() { + self.buffer.push(channel_idx, *sample); + } + } + ProcessStatus::Normal } }