mirror of
https://github.com/mii443/maudio-router.git
synced 2025-12-03 11:08:31 +00:00
virtual device input output
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user