Don't really push silence to the ring buffer (#86)

This commit is contained in:
Paul Adenot 2020-04-16 18:13:34 +02:00 коммит произвёл GitHub
Родитель 94ffa140d6
Коммит e8b8a052d8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 3 добавлений и 28 удалений

Просмотреть файл

@ -64,27 +64,6 @@ impl BufferManager {
} }
} }
} }
pub fn push_silent_data(&mut self, silent_samples: usize) {
let pushed = match &mut self.producer {
RingBufferProducer::FloatRingBufferProducer(p) => {
let mut silent_buffer = [0. as f32; INPUT_BUFFER_CAPACITY];
let silent_slice = silent_buffer.split_at_mut(silent_samples).0;
p.push_slice(silent_slice)
}
RingBufferProducer::IntegerRingBufferProducer(p) => {
let mut silent_buffer = [0 as i16; INPUT_BUFFER_CAPACITY];
let silent_slice = silent_buffer.split_at_mut(silent_samples).0;
p.push_slice(silent_slice)
}
};
if pushed != silent_samples {
cubeb_log!(
"Input ringbuffer full, could only push {} instead of {}",
pushed,
silent_samples
);
}
}
pub fn push_data(&mut self, input_data: *const c_void, read_samples: usize) { pub fn push_data(&mut self, input_data: *const c_void, read_samples: usize) {
let pushed = match &mut self.producer { let pushed = match &mut self.producer {
RingBufferProducer::FloatRingBufferProducer(p) => { RingBufferProducer::FloatRingBufferProducer(p) => {

Просмотреть файл

@ -399,12 +399,9 @@ extern "C" fn audiounit_input_callback(
// For now state that no error occurred and feed silence, stream will be // For now state that no error occurred and feed silence, stream will be
// resumed once reinit has completed. // resumed once reinit has completed.
cubeb_logv!( cubeb_logv!(
"({:p}) input: reinit pending feeding silence instead", "({:p}) input: reinit pending, output will pull silence instead",
stm.core_stream_data.stm_ptr stm.core_stream_data.stm_ptr
); );
let elements =
(input_frames * stm.core_stream_data.input_desc.mChannelsPerFrame) as usize;
input_buffer_manager.push_silent_data(elements);
ErrorHandle::Reinit ErrorHandle::Reinit
} else { } else {
assert_eq!(status, NO_ERR); assert_eq!(status, NO_ERR);
@ -610,13 +607,12 @@ extern "C" fn audiounit_output_callback(
&& (stm.switching_device.load(Ordering::SeqCst) && (stm.switching_device.load(Ordering::SeqCst)
|| stm.frames_read.load(Ordering::SeqCst) == 0) || stm.frames_read.load(Ordering::SeqCst) == 0)
{ {
// The silent frames will be inserted in `get_linear_data` below.
let silent_frames_to_push = input_frames_needed - buffered_input_frames; let silent_frames_to_push = input_frames_needed - buffered_input_frames;
let silent_samples_to_push = silent_frames_to_push * input_channels;
input_buffer_manager.push_silent_data(silent_samples_to_push);
stm.frames_read stm.frames_read
.fetch_add(input_frames_needed, Ordering::SeqCst); .fetch_add(input_frames_needed, Ordering::SeqCst);
cubeb_log!( cubeb_log!(
"({:p}) Missing Frames: {} pushed {} frames of input silence.", "({:p}) Missing Frames: {} will append {} frames of input silence.",
stm.core_stream_data.stm_ptr, stm.core_stream_data.stm_ptr,
if stm.frames_read.load(Ordering::SeqCst) == 0 { if stm.frames_read.load(Ordering::SeqCst) == 0 {
"input hasn't started," "input hasn't started,"