diff --git a/src/node/panner.rs b/src/node/panner.rs index d2ac326e..2f7895d0 100644 --- a/src/node/panner.rs +++ b/src/node/panner.rs @@ -24,6 +24,11 @@ pub(crate) fn load_hrtf_processor(sample_rate: u32) -> (HrtfProcessor, usize) { static INSTANCE: OnceLock>> = OnceLock::new(); let cache = INSTANCE.get_or_init(|| Mutex::new(HashMap::new())); + // There's an upstream bug for low sample rates, so work around it by forcing sample_rate to be + // 27k minimum. The HRTF response will be a bit distorted but I assume you won't be using it + // anyway when running these low sample rates. + let sample_rate = sample_rate.max(27_000); + // To avoid poisening the cache mutex, don't use the `entry()` API on HashMap { if let Some(value) = cache.lock().unwrap().get(&sample_rate) { diff --git a/tests/online.rs b/tests/online.rs index 15fc8974..8abdd61c 100644 --- a/tests/online.rs +++ b/tests/online.rs @@ -108,7 +108,6 @@ fn test_none_sink_id() { } #[test] -#[should_panic] // https://github.com/mrDIMAS/hrtf/issues/9 fn test_weird_sample_rate() { let options = AudioContextOptions { sink_id: "none".into(), @@ -116,6 +115,7 @@ fn test_weird_sample_rate() { ..AudioContextOptions::default() }; + // would crash due to let _ = AudioContext::new(options); }