Skip to content

Commit 1ace2f5

Browse files
committed
implement loop interpolation for negative playback rate
1 parent 3de5f6b commit 1ace2f5

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/node/audio_buffer_source.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -745,23 +745,29 @@ impl AudioProcessor for AudioBufferSourceRenderer {
745745
{
746746
Some(val) => *val,
747747
None => {
748-
// @todo - handle playback_rate < 0.
749-
//
750-
// find first sample >= to start loop point
751-
if is_looping {
752-
let start_playhead =
753-
actual_loop_start * sample_rate;
754-
let start_index =
755-
if start_playhead.floor() == start_playhead {
756-
start_playhead as usize
757-
} else {
758-
start_playhead as usize + 1
759-
};
760-
761-
buffer_channel[start_index]
748+
let sample = if is_looping {
749+
if playback_rate >= 0. {
750+
let start_playhead =
751+
actual_loop_start * sample_rate;
752+
let start_index =
753+
if start_playhead.floor() == start_playhead {
754+
start_playhead as usize
755+
} else {
756+
start_playhead as usize + 1
757+
};
758+
759+
buffer_channel[start_index]
760+
} else {
761+
let end_playhead =
762+
actual_loop_end * sample_rate;
763+
let end_index = end_playhead as usize;
764+
buffer_channel[end_index]
765+
}
762766
} else {
763767
0.
764-
}
768+
};
769+
770+
sample
765771
}
766772
};
767773

0 commit comments

Comments
 (0)