SampleRateConverter: Check that resampling does not change duration

Reproduces the issue in #316
This commit is contained in:
Nicolas Braud-Santoni 2020-10-01 17:43:00 +02:00
parent 20cd8eb3a3
commit 412a02ae85
No known key found for this signature in database
GPG key ID: E6F98EE292D5ECCB

View file

@ -252,6 +252,7 @@ where
#[cfg(test)]
mod test {
use super::SampleRateConverter;
use core::time::Duration;
use cpal::SampleRate;
use quickcheck::quickcheck;
@ -329,6 +330,25 @@ mod test {
.step_by(k as usize).collect::<Vec<_>>().concat()
)
}
#[ignore]
fn equal_durations(d: Duration, freq: u32, to: u32) -> () {
use crate::source::{SineWave, Source};
let to = if to == 0 { return; } else { SampleRate(to) };
let source = SineWave::new(freq).take_duration(d);
let from = SampleRate(source.sample_rate());
let resampled =
SampleRateConverter::new(source, from, to, 1);
let duration =
Duration::from_secs_f32(resampled.count() as f32 / to.0 as f32);
let delta = if d < duration { duration - d } else { d - duration };
assert!(delta < Duration::from_millis(1),
"Resampled duration ({:?}) is not close to original ({:?}); Δ = {:?}",
duration, d, delta);
}
}
#[test]