mrDIMAS/hrtf

Panic for low sample rate

Opened this issue · 0 comments

The following snippet panics with
Input FFT buffer must be a multiple of FFT length. Expected multiple of 639, got len = 702

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_sample_rate() {
        let resource = File::open("resources/IRC_1003_C.bin").unwrap(); // IRCAM listen db
        let sphere = HrirSphere::new(resource, 24000).unwrap(); // low sample rate
        let _proc = HrtfProcessor::new(sphere, 1, 128);
    }
}

You could argue 24k is too low of a sample rate anyway. This could maybe be encoded into a new error variant of HrtfError?
But there also may be an underlying issue regarding the length of the HRIR length vs the sample rate. I have not looked into this myself.

Full stacktrace:

   0: rust_begin_unwind
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:270:5
   4: rustfft::common::fft_error_inplace
             at /Users/otto/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustfft-6.1.0/src/common.rs:25:5
   5: <rustfft::algorithm::mixed_radix::MixedRadix<T> as rustfft::Fft<T>>::process_with_scratch
             at /Users/otto/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustfft-6.1.0/src/common.rs:241:21
   6: rustfft::Fft::process
             at /Users/otto/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustfft-6.1.0/src/lib.rs:188:9
   7: hrtf::make_hrtf
             at ./src/lib.rs:256:5
   8: hrtf::HrtfSphere::new::{{closure}}
             at ./src/lib.rs:636:33
   9: core::iter::adapters::map::map_try_fold::{{closure}}
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/iter/adapters/map.rs:91:28
  10: core::iter::traits::iterator::Iterator::try_fold
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/iter/traits/iterator.rs:2461:21
  11: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/iter/adapters/map.rs:117:9
  12: <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/vec/in_place_collect.rs:258:13
  13: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/vec/in_place_collect.rs:182:28
  14: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/vec/mod.rs:2749:9
  15: core::iter::traits::iterator::Iterator::collect
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/iter/traits/iterator.rs:2053:9
  16: hrtf::HrtfSphere::new
             at ./src/lib.rs:632:22
  17: hrtf::HrtfProcessor::new
             at ./src/lib.rs:871:27
  18: hrtf::tests::test_sample_rate
             at ./src/lib.rs:1022:21
  19: hrtf::tests::test_sample_rate::{{closure}}
             at ./src/lib.rs:1019:27