From patchwork Fri Feb 17 14:06:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Koshevoy X-Patchwork-Id: 2594 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp196406vsb; Fri, 17 Feb 2017 06:15:15 -0800 (PST) X-Received: by 10.28.158.82 with SMTP id h79mr3979175wme.30.1487340915837; Fri, 17 Feb 2017 06:15:15 -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 b32si4327618wra.296.2017.02.17.06.14.56; Fri, 17 Feb 2017 06:15:15 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5A77689AF3; Fri, 17 Feb 2017 16:14:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua0-f194.google.com (mail-ua0-f194.google.com [209.85.217.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 966AE687EE5 for ; Fri, 17 Feb 2017 16:14:40 +0200 (EET) Received: by mail-ua0-f194.google.com with SMTP id q14so2819396uaq.2 for ; Fri, 17 Feb 2017 06:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=11NNXfApwzxS8kvH13JNiW4S31teb1VhaQwvf3SDkos=; b=lxHVWxcIGtksJoo4Ok4wIiu8twai5wYgyXb2RRhQlqwuKTNGWcrJBBj0irSgG4xAWY qYFOTba+a+luCI6EUbZ0QeIxsz37AanxCCYZzFJdCMeqGC9OqPdM6K0yt9BheDPvNjWY Yo+CfXX0yHqT/BNsV6i1kpouxxClJYFR4bNvxTvJk1yIQzRbNebWnJBDIqtWZ9tQksjr 3FII5NVzLBqFuYxuQESSj354mCKQH3v8H8Ck0mmKkCe5oMAINpXhnX+IaJrnjJrbv2LP quKydBzG7Xk4CiY0XTgGuMQQWkxRe7b66AJd4a4YpbAlvcJcJNqpaDiSC2pUB3kJJKpw YpgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=11NNXfApwzxS8kvH13JNiW4S31teb1VhaQwvf3SDkos=; b=ZO3HazVjQrmfnQ4/V0omu5TbfaRLwbozDP6+k2ZmcekZlw0n3ZBbaULs4wFTKYowmY m1+3hTPW+LFtbb4SoWbkihR3FcPwtCbY9HyhP8ds/zTnbC7ydrdFqm58OIwV1b/u0A02 s/dy6z8LXRx7FBfCL1kY/dRnKQ28NMcdEaqHfo1lyZbX/2Or7txdoG85ePQkOBc+zMpS fIcS04WOoOvwUl+M2YoXeBxIs05iVOlsQnpK9E0zvMUR8Vipzkx07nGL/3X9s96EoKYG VP86AMwLpym5/b0ItrI3WuaePP7fpMw2t+aynbksgAJCblCcqG1Bc36XjK8yoxIlWByH XHEA== X-Gm-Message-State: AMke39maJ0Id/N03CAR4RwkxJHHQngnmNu5rZ6GqoCCR8rVtLLQ2MvVH4zw8bbjJtwyy/kxXEI4fpNyaoNmzYQ== X-Received: by 10.176.91.72 with SMTP id v8mr4153029uae.23.1487340400647; Fri, 17 Feb 2017 06:06:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.41.70 with HTTP; Fri, 17 Feb 2017 06:06:38 -0800 (PST) Received: by 10.103.41.70 with HTTP; Fri, 17 Feb 2017 06:06:38 -0800 (PST) In-Reply-To: <20170217085551.1291-1-lq@chinaffmpeg.org> References: <20170217085551.1291-1-lq@chinaffmpeg.org> From: Pavel Koshevoy Date: Fri, 17 Feb 2017 07:06:38 -0700 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Feb 17, 2017 01:56, "Steven Liu" 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 --- 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 --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,