extern crate sample;
use sample::interpolate::{Converter, Floor, Linear};
use sample::{signal, Signal};
#[test]
fn test_floor_converter() {
let frames: [[f64; 1]; 3] = [[0.0], [1.0], [2.0]];
let mut source = signal::from_iter(frames.iter().cloned());
let interp = Floor::from_source(&mut source);
let mut conv = Converter::scale_playback_hz(source, interp, 0.5);
assert_eq!(conv.next(), [0.0]);
assert_eq!(conv.next(), [0.0]);
assert_eq!(conv.next(), [1.0]);
assert_eq!(conv.next(), [1.0]);
assert_eq!(conv.next(), [2.0]);
assert_eq!(conv.next(), [2.0]);
}
#[test]
fn test_linear_converter() {
let frames: [[f64; 1]; 3] = [[0.0], [1.0], [2.0]];
let mut source = signal::from_iter(frames.iter().cloned());
let interp = Linear::from_source(&mut source);
let mut conv = Converter::scale_playback_hz(source, interp, 0.5);
assert_eq!(conv.next(), [0.0]);
assert_eq!(conv.next(), [0.5]);
assert_eq!(conv.next(), [1.0]);
assert_eq!(conv.next(), [1.5]);
assert_eq!(conv.next(), [2.0]);
assert_eq!(conv.next(), [1.0]);
}
#[test]
fn test_scale_playback_rate() {
let foo = [[0.0], [1.0], [0.0], [-1.0]];
let mut source = signal::from_iter(foo.iter().cloned());
let interp = Linear::from_source(&mut source);
let frames: Vec<_> = source.scale_hz(interp, 0.5).take(8).collect();
assert_eq!(
&frames[..],
&[[0.0], [0.5], [1.0], [0.5], [0.0], [-0.5], [-1.0], [-0.5]][..]
);
}