diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index e4ef012..a139c42 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -905,13 +905,6 @@ fn set_hw_params_from_format<'a>( BufferSize::Default => (), } - // If this isn't set manually a overlarge buffer may be used causing audio delay - let mut hw_params_copy = hw_params.clone(); - if let Err(_) = hw_params.set_buffer_time_near(100_000, alsa::ValueOr::Nearest) { - // Swap out the params with errors for a snapshot taken before the error was introduced. - mem::swap(&mut hw_params_copy, &mut hw_params); - } - pcm_handle.hw_params(&hw_params)?; Ok(hw_params) diff --git a/src/host/emscripten/mod.rs b/src/host/emscripten/mod.rs index d9e9de8..21e8712 100644 --- a/src/host/emscripten/mod.rs +++ b/src/host/emscripten/mod.rs @@ -334,7 +334,7 @@ fn audio_callback_fn( // and there may be underflows set_timeout( || audio_callback_fn::(user_data_ptr, config, sample_format, buffer_size_frames), - 330, + buffer_size_frames * 1000 / sample_rate, ); } } diff --git a/src/lib.rs b/src/lib.rs index 0a3b749..917cb6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -183,6 +183,13 @@ pub struct SampleRate(pub u32); /// The desired number of frames for the hardware buffer. pub type FrameCount = u32; +/// The buffer size used by the device. +/// +/// Default is used when no specific buffer size is set and uses the default +/// behavior of the given host. Note, the default buffer size may be surprisingly +/// large, leading to latency issues. If low latency is desired, Fixed(BufferSize) +/// should be used in accordance with the SupportedBufferSize range produced by +/// the SupportedStreamConfig API. #[derive(Clone, Debug, Eq, PartialEq)] pub enum BufferSize { Default,