virtual device input output

This commit is contained in:
mii443
2024-02-14 18:34:33 +09:00
parent b2409cbc2d
commit af9a0befbd

View File

@@ -32,4 +32,35 @@ impl VirtualDevice {
self.output_index.push(self.get_min_index());
self.output_index.len() - 1
}
pub fn take_output(&mut self, index: usize, channel: u8, take_size: usize) -> Option<Vec<f64>> {
let mut buffer = Vec::with_capacity(take_size);
let start = self.output_index[index];
let end = start + take_size;
if end > self.output_buffer[channel as usize].len() {
return None;
}
for i in start..end {
buffer.push(self.output_buffer[channel as usize][i]);
}
self.output_index[index] = end;
let min = self.get_min_index();
if min != 0 {
for i in 0..self.channels as usize {
self.output_buffer[i].drain(0..min);
}
for i in 0..self.output_index.len() {
self.output_index[i] -= min;
}
}
Some(buffer)
}
pub fn write_input(&mut self, channel: u8, buffer: Vec<f64>) {
self.output_buffer[channel as usize].extend(buffer);
}
}