Linear with until_exhausted does not produce enough frames
The last 2 frames are missing:
#[test]
fn test_linear_converter_until_exhausted() {
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 conv = Converter::scale_playback_hz(source, interp, 0.5);
let bar: Vec<_> = conv.until_exhausted().collect();
assert_eq!(bar, [[0.0], [0.5], [1.0], [1.5], [2.0], [1.0]]);
}
Floor is not affected.
I'm not sure about Sinc but it is probably affected. I'm still trying to figure out how to get the correct initial samples...
I don't believe the last frame [1.0] should be there actually, because the frames array doesn't end with [0.0]. (Sometimes you wouldn't want the value to return to unity, as in interpolating breakpoints on an envelope of some sort.) Though the [2.0] probably should be there at the end. PRs welcome, I'm sure!
Well, a frame is indeed a single point in time, but it actually represents a span of time (determined by the frequency).
I expect to get the same duration of sound regardless of the interpolation being applied:
- 3 frames at 22050 Hz -> 136 μs of sound
- 6 frames at 44100 Hz -> 136 μs of sound
As for Sinc, none of the combinations I tried produced the expected amount of frames (double the input).
Good point! In that case, it seems we'd want to keep the last two frames [2.0], [2.0], rather than move toward unity. I could see the other way creating some confusing issues with (say) generating amplitude envelopes.
Does that work? Mentioning @mitchmindtree who I think is the only maintainer of this crate, but I could be wrong about that. I've been out of Rust-land for a while but just replied to this one since I believe I was at least partly originally responsible for this behavior.
Since there is silence after you play a sound, I would expect it to interpolate towards silence, but I don't really care about interpolated values. I'm satisfied as long as I get the same duration of sound and I get the same values in the same instants.
The constructor of Linear could determine what it interpolates to when the input is exhausted (last frame, silence, custom frame).