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.
This commit is contained in:
ferreum 2023-08-15 19:45:12 +02:00 committed by Niklas Haas
parent f52cf90fed
commit c0728249a1
1 changed files with 9 additions and 1 deletions

View File

@ -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);
}