Skip to content

Commit ed77013

Browse files
committed
[add] test to ensure that cursor looping works when the cursor advances fractionally
1 parent ef792ec commit ed77013

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crates/lambda-rs/src/audio/playback/callback.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,28 @@ mod tests {
724724
return;
725725
}
726726

727+
/// Looping MUST wrap correctly when pitch advances the cursor fractionally.
728+
#[test]
729+
fn scheduler_looping_wraps_with_fractional_pitch() {
730+
let buffer = make_test_buffer(vec![0.0, 1.0], 1);
731+
732+
let mut scheduler = PlaybackScheduler::new_with_ramp_frames(1, 0);
733+
scheduler.set_buffer(buffer);
734+
scheduler.set_looping(true);
735+
scheduler.play();
736+
737+
let mut writer = TestAudioOutput::new(1, 4);
738+
scheduler.render(&mut writer, 1.0, 1.0, 1.5);
739+
740+
assert_eq!(scheduler.state(), PlaybackState::Playing);
741+
742+
assert!((writer.sample(0, 0) - 0.0).abs() <= 1e-6);
743+
assert!((writer.sample(1, 0) - 0.5).abs() <= 1e-6);
744+
assert!((writer.sample(2, 0) - 1.0).abs() <= 1e-6);
745+
assert!((writer.sample(3, 0) - 0.5).abs() <= 1e-6);
746+
return;
747+
}
748+
727749
/// Pitch `1.0` MUST reproduce the original sample sequence (no resampling).
728750
#[test]
729751
fn scheduler_pitch_one_reproduces_original_sequence() {

0 commit comments

Comments
 (0)