mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 21:52:38 +00:00
SampleRateConverter: Generalize tests over rate ratio
This commit is contained in:
parent
663bdd57b2
commit
878de74821
1 changed files with 11 additions and 8 deletions
|
@ -285,10 +285,10 @@ mod test {
|
|||
assert_eq!(input, output);
|
||||
}
|
||||
|
||||
fn half_sample_rate(to: u32, input: Vec<u16>, n: u16) -> () {
|
||||
fn divide_sample_rate(to: u32, k: u32, input: Vec<u16>, n: u16) -> () {
|
||||
let to = if to == 0 { return; } else { SampleRate(to) };
|
||||
let from = multiply_rate(to, 2);
|
||||
if n == 0 { return; }
|
||||
let from = multiply_rate(to, k);
|
||||
if k == 0 || n == 0 { return; }
|
||||
|
||||
// Truncate the input, so it contains an integer number of frames.
|
||||
let input = {
|
||||
|
@ -302,14 +302,15 @@ mod test {
|
|||
SampleRateConverter::new(input.clone().into_iter(), from, to, n)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(input.chunks_exact(n.into()).step_by(2).collect::<Vec<_>>().concat(),
|
||||
assert_eq!(input.chunks_exact(n.into())
|
||||
.step_by(k as usize).collect::<Vec<_>>().concat(),
|
||||
output)
|
||||
}
|
||||
|
||||
fn double_sample_rate(from: u32, input: Vec<u16>, n: u16) -> () {
|
||||
fn multiply_sample_rate(from: u32, k: u32, input: Vec<u16>, n: u16) -> () {
|
||||
let from = if from == 0 { return; } else { SampleRate(from) };
|
||||
let to = multiply_rate(from, 2);
|
||||
if n == 0 { return; }
|
||||
let to = multiply_rate(from, k);
|
||||
if k == 0 || n == 0 { return; }
|
||||
|
||||
// Truncate the input, so it contains an integer number of frames.
|
||||
let input = {
|
||||
|
@ -324,7 +325,9 @@ mod test {
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(input,
|
||||
output.chunks_exact(n.into()).step_by(2).collect::<Vec<_>>().concat())
|
||||
output.chunks_exact(n.into())
|
||||
.step_by(k as usize).collect::<Vec<_>>().concat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue