Push samples to the ring buffer
This commit is contained in:
parent
3475ea2de8
commit
86b5ed8f7e
|
@ -49,6 +49,23 @@ impl RingBuffer {
|
||||||
for buffer in self.buffers.iter_mut() {
|
for buffer in self.buffers.iter_mut() {
|
||||||
buffer.fill(0.0);
|
buffer.fill(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.next_write_pos = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,10 +90,16 @@ impl Plugin for BuffrGlitch {
|
||||||
|
|
||||||
fn process(
|
fn process(
|
||||||
&mut self,
|
&mut self,
|
||||||
_buffer: &mut Buffer,
|
buffer: &mut Buffer,
|
||||||
_aux: &mut AuxiliaryBuffers,
|
_aux: &mut AuxiliaryBuffers,
|
||||||
_context: &mut impl ProcessContext<Self>,
|
_context: &mut impl ProcessContext<Self>,
|
||||||
) -> ProcessStatus {
|
) -> 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
|
ProcessStatus::Normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue