diff mbox

[FFmpeg-devel] avfilter/af_atempo: fix sound shake when change speed

Message ID CAJgjuoxkFtsqEYhTBxqe8ipWMHX86_1n1thKJg4UjJuRzfn9gw@mail.gmail.com
State New
Headers show

Commit Message

Pavel Koshevoy Feb. 17, 2017, 2:06 p.m. UTC
On Feb 17, 2017 01:56, "Steven Liu" <lq@chinaffmpeg.org> wrote:

commandline:
./ffmpeg -i ~/Downloads/test.wav -af atempo=1.5 -acodec aac -y
output.aac

play the output.aac, the sound is very shake, terrible.
after this patch,
play the sound is smooth

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavfilter/af_atempo.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

                                      atempo->complex_to_real);

@@ -722,6 +716,9 @@ static int yae_adjust_position(ATempoContext *atempo)
         frag->nsamples = 0;
     }

+    // update cumulative correction drift counter:
+    atempo->drift += correction;
+
     return correction;
 }

--
2.10.1.382.ga23ca1b.dirty
diff mbox

Patch

diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
index a487882..db2f981 100644
--- a/libavfilter/af_atempo.c
+++ b/libavfilter/af_atempo.c
@@ -123,6 +123,8 @@  typedef struct {
     // tempo scaling factor:
     double tempo;

+    int drift;
+
     // a snapshot of previous fragment input and output position values
     // captured when the tempo scale factor was set most recently:
     int64_t origin[2];
@@ -179,6 +181,7 @@  static void yae_clear(ATempoContext *atempo)
     atempo->head = 0;
     atempo->tail = 0;

+    atempo->drift = 0;
     atempo->nfrag = 0;
     atempo->state = YAE_LOAD_FRAGMENT;

@@ -696,21 +699,12 @@  static int yae_adjust_position(ATempoContext *atempo)
     const AudioFragment *prev = yae_prev_frag(atempo);
     AudioFragment       *frag = yae_curr_frag(atempo);

-    const double prev_output_position =
-        (double)(prev->position[1] - atempo->origin[1] + atempo->window /
2);
-
-    const double ideal_output_position =
-        (double)(prev->position[0] - atempo->origin[0] + atempo->window /
2) /
-        atempo->tempo;
-
-    const int drift = (int)(prev_output_position - ideal_output_position);
-
     const int delta_max  = atempo->window / 2;
     const int correction = yae_align(frag,
                                      prev,
                                      atempo->window,
                                      delta_max,
-                                     drift,
+                                     atempo->drift,
                                      atempo->correlation,