From patchwork Fri Feb 17 08:55:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 2591 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp73847vsb; Fri, 17 Feb 2017 00:56:16 -0800 (PST) X-Received: by 10.223.135.8 with SMTP id a8mr6329525wra.162.1487321776605; Fri, 17 Feb 2017 00:56:16 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b27si887258wmi.98.2017.02.17.00.56.15; Fri, 17 Feb 2017 00:56:16 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C798689A6C; Fri, 17 Feb 2017 10:56:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 64C8068097F for ; Fri, 17 Feb 2017 10:55:56 +0200 (EET) X-QQ-mid: bizesmtp4t1487321753t3vmjezcw Received: from localhost (unknown [47.90.47.25]) by esmtp4.qq.com (ESMTP) with id ; Fri, 17 Feb 2017 16:55:52 +0800 (CST) X-QQ-SSF: 00100000002000F0F820B60A0000000 X-QQ-FEAT: FRkVFvYdryU6dGK09KgsZzOXIQBayrqN6+TQB84tMYHDXu5VM//LuNEeU0sf1 zMfgzahuE8M6WnIhtomFTiBOuAZv6C1fWCwRSrNRKT5R7rwdKkxilHqWeWTVtnb+hAIO1rX hhYrVNqTaCIS60ALsinsY5Aoy85q2MR9pLpKx4CZPl4jYpKsNgkJD4XvfOrPm7FTszkR0zT SZrUk4woSGdu+JNp2ad0uuqXVy4kEJxGzA4CmJZs5/L0+s27O9+EbbaDKM5Nvlr0zcvhkva 0TbF4J7lMiB/I3 X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Feb 2017 16:55:51 +0800 Message-Id: <20170217085551.1291-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty MIME-Version: 1.0 X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avfilter/af_atempo: fix sound shake when change speed X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavfilter/af_atempo.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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, 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; }