fix audio playback of 8Khz samples, further cut down on clones/copies
This commit is contained in:
+5
-7
@@ -156,18 +156,16 @@ impl AudioSink {
|
||||
}
|
||||
|
||||
fn process(&mut self, scope: &ProcessScope) -> Result<(), AudioError> {
|
||||
let mut next_outbuf = match self.sample_src.try_recv() {
|
||||
Ok(buf) => buf,
|
||||
Err(tokio::sync::mpsc::error::TryRecvError::Empty) => return Ok(()),
|
||||
Err(err) => return Err(err.into())
|
||||
};
|
||||
self.output_buf.append(&mut next_outbuf);
|
||||
if let Ok(buf) = self.sample_src.try_recv() {
|
||||
self.output_buf.extend(buf);
|
||||
}
|
||||
|
||||
if self.port.connected_count()? > 0 && !self.output_buf.is_empty() {
|
||||
let outbuf = self.port.as_mut_slice(scope);
|
||||
let mut next_segment: Vec<f32> = self.output_buf.drain(0..(outbuf.len()).min(self.output_buf.len())).collect();
|
||||
let mut next_segment: Vec<f32> = self.output_buf.drain(..(outbuf.len()).min(self.output_buf.len())).collect();
|
||||
let underrun = outbuf.len() - next_segment.len();
|
||||
if underrun > 0 {
|
||||
log::warn!("Audio stream underrun: {} samples", underrun);
|
||||
next_segment.extend(std::iter::repeat_n(0., underrun));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user