From c0728249a18f5e7ec40332e002f4cd9fedc8e91c Mon Sep 17 00:00:00 2001 From: ferreum Date: Tue, 15 Aug 2023 19:45:12 +0200 Subject: af_scaletempo2: restore exact audio sync on return to 1x speed Target block can be anywhere in the previous search-block, varying by `search-interval` while the filter is active. This resulted in constant audio offset when returning to 1x playback speed. - Move the search block to the target block to sync up exactly. - Drop old frames to minimize input_buffer usage. --- audio/filter/af_scaletempo2_internals.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/audio/filter/af_scaletempo2_internals.c b/audio/filter/af_scaletempo2_internals.c index 5597d531b0..eb2d4bb20b 100644 --- a/audio/filter/af_scaletempo2_internals.c +++ b/audio/filter/af_scaletempo2_internals.c @@ -702,7 +702,15 @@ int mp_scaletempo2_fill_buffer(struct mp_scaletempo2 *p, // Optimize the most common |playback_rate| ~= 1 case to use a single copy // instead of copying frame by frame. if (p->ola_window_size <= faster_step && slower_step >= p->ola_window_size) { - p->wsola_output_started = false; + + if (p->wsola_output_started) { + p->wsola_output_started = false; + + // sync audio precisely again + set_output_time(p, p->target_block_index + p->search_block_center_offset); + remove_old_input_frames(p); + } + return read_input_buffer(p, dest_size, dest); } -- cgit v1.2.3