summaryrefslogtreecommitdiffstats
path: root/audio/filter
diff options
context:
space:
mode:
authorferreum <code@ferreum.de>2023-08-08 12:48:11 +0200
committerNiklas Haas <github-daiK1o@haasn.dev>2023-09-20 14:36:23 +0200
commitc3bceb324343afe423d24428a56047aeb45d5f67 (patch)
tree2678a3c9363c37dfedfa97aec30c1b0cf829419e /audio/filter
parentde09ec9ea48ed40caefe2deebbd168f69a2b1d78 (diff)
downloadmpv-c3bceb324343afe423d24428a56047aeb45d5f67.tar.bz2
mpv-c3bceb324343afe423d24428a56047aeb45d5f67.tar.xz
af_scaletempo2: fix audio offset when playing back at 1x speed
`read_input_buffer` needs to respect the `target_block_index`, otherwise the audio resumes at the wrong position.
Diffstat (limited to 'audio/filter')
-rw-r--r--audio/filter/af_scaletempo2_internals.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/audio/filter/af_scaletempo2_internals.c b/audio/filter/af_scaletempo2_internals.c
index a8fd91cebb..168914de28 100644
--- a/audio/filter/af_scaletempo2_internals.c
+++ b/audio/filter/af_scaletempo2_internals.c
@@ -427,12 +427,6 @@ static void seek_buffer(struct mp_scaletempo2 *p, int frames)
}
}
-static void read_buffer(struct mp_scaletempo2 *p, int frames, float **dest)
-{
- peek_buffer(p, frames, 0, 0, dest);
- seek_buffer(p, frames);
-}
-
static int write_completed_frames_to(struct mp_scaletempo2 *p,
int requested_frames, int dest_offset, float **dest)
{
@@ -642,6 +636,18 @@ static bool run_one_wsola_iteration(struct mp_scaletempo2 *p, float playback_rat
return true;
}
+static int read_input_buffer(struct mp_scaletempo2 *p, int dest_size, float **dest)
+{
+ int frames_to_copy = MPMIN(dest_size, p->input_buffer_frames - p->target_block_index);
+
+ if (frames_to_copy <= 0)
+ return 0; // There is nothing to read from input buffer; return.
+
+ peek_buffer(p, frames_to_copy, p->target_block_index, 0, dest);
+ seek_buffer(p, frames_to_copy);
+ return frames_to_copy;
+}
+
int mp_scaletempo2_fill_buffer(struct mp_scaletempo2 *p,
float **dest, int dest_size, float playback_rate)
{
@@ -680,9 +686,7 @@ 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) {
- int frames_to_copy = MPMIN(dest_size, p->input_buffer_frames);
- read_buffer(p, frames_to_copy, dest);
- return frames_to_copy;
+ return read_input_buffer(p, dest_size, dest);
}
int rendered_frames = 0;