mirror of
https://github.com/RustAudio/rodio
synced 2024-11-10 14:14:21 +00:00
SampleRateConverter: Check that resampling does not change duration
Reproduces the issue in #316
This commit is contained in:
parent
20cd8eb3a3
commit
412a02ae85
1 changed files with 20 additions and 0 deletions
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue