1
0
Fork 0

Push samples to the ring buffer

This commit is contained in:
Robbert van der Helm 2022-11-09 16:14:51 +01:00
parent 3475ea2de8
commit 86b5ed8f7e
2 changed files with 24 additions and 1 deletions

View file

@ -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;
}
}
}
}

View file

@ -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<Self>,
) -> 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
}
}