Make minimum_resampling_input_frames become a member function

This commit is contained in:
Chun-Min Chang 2019-04-18 12:58:33 -07:00
Родитель 5907bc8f90
Коммит b2a5a78d91
2 изменённых файлов: 15 добавлений и 17 удалений

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

@ -433,18 +433,6 @@ fn audiounit_mix_output_buffer(stm: &mut AudioUnitStream,
}
}
fn minimum_resampling_input_frames(stm: &AudioUnitStream, output_frames: i64) -> i64
{
// TODO: Check the arguments ?
assert_ne!(stm.input_hw_rate, 0_f64);
assert_ne!(stm.output_stream_params.rate(), 0);
if stm.input_hw_rate == f64::from(stm.output_stream_params.rate()) {
// Fast path.
return output_frames;
}
(stm.input_hw_rate * output_frames as f64 / f64::from(stm.output_stream_params.rate())).ceil() as i64
}
extern fn audiounit_output_callback(user_ptr: *mut c_void,
_: *mut AudioUnitRenderActionFlags,
_tstamp: *const AudioTimeStamp,
@ -532,7 +520,7 @@ extern fn audiounit_output_callback(user_ptr: *mut c_void,
* currently switching, we add some silence as well to compensate for the
* fact that we're lacking some input data. */
let frames_written = stm.frames_written.load(atomic::Ordering::SeqCst);
let input_frames_needed = minimum_resampling_input_frames(stm, frames_written);
let input_frames_needed = stm.minimum_resampling_input_frames(frames_written);
let missing_frames = input_frames_needed - stm.frames_read.load(atomic::Ordering::SeqCst);
if missing_frames > 0 {
stm.input_linear_buffer.as_mut().unwrap().push_zeros((missing_frames * i64::from(stm.input_desc.mChannelsPerFrame)) as usize);
@ -3869,6 +3857,16 @@ impl<'ctx> AudioUnitStream<'ctx> {
self.output_stream_params.rate() > 0
}
fn minimum_resampling_input_frames(&self, output_frames: i64) -> i64 {
assert_ne!(self.input_hw_rate, 0_f64);
assert_ne!(self.output_stream_params.rate(), 0);
if self.input_hw_rate == f64::from(self.output_stream_params.rate()) {
// Fast path.
return output_frames;
}
(self.input_hw_rate * output_frames as f64 / f64::from(self.output_stream_params.rate())).ceil() as i64
}
fn get_volume(&self) -> Result<f32> {
assert!(!self.output_unit.is_null());
let mut volume: f32 = 0.0;

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

@ -279,7 +279,7 @@ fn test_minimum_resampling_input_frames() {
let frames: i64 = 100;
let times = stream.input_hw_rate / f64::from(stream.output_stream_params.rate());
let expected = (frames as f64 * times).ceil() as i64;
assert_eq!(minimum_resampling_input_frames(&stream, frames), expected);
assert_eq!(stream.minimum_resampling_input_frames(frames), expected);
});
}
@ -290,7 +290,7 @@ fn test_minimum_resampling_input_frames_zero_input_rate() {
// Set input and output rates to 0 and 44100 respectively.
test_minimum_resampling_input_frames_set_stream_rates(stream, (0_f64, 44100_f64));
let frames: i64 = 100;
assert_eq!(minimum_resampling_input_frames(&stream, frames), 0);
assert_eq!(stream.minimum_resampling_input_frames(frames), 0);
});
}
@ -301,7 +301,7 @@ fn test_minimum_resampling_input_frames_zero_output_rate() {
// Set input and output rates to 48000 and 0 respectively.
test_minimum_resampling_input_frames_set_stream_rates(stream, (48000_f64, 0_f64));
let frames: i64 = 100;
assert_eq!(minimum_resampling_input_frames(&stream, frames), 0);
assert_eq!(stream.minimum_resampling_input_frames(frames), 0);
});
}
@ -311,7 +311,7 @@ fn test_minimum_resampling_input_frames_equal_input_output_rate() {
// Set both input and output rates to 44100.
test_minimum_resampling_input_frames_set_stream_rates(stream, (44100_f64, 44100_f64));
let frames: i64 = 100;
assert_eq!(minimum_resampling_input_frames(&stream, frames), frames);
assert_eq!(stream.minimum_resampling_input_frames(frames), frames);
});
}