From patchwork Tue Feb 27 09:48:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46564 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51b:b0:19e:cdac:8cce with SMTP id gm27csp1886754pzb; Tue, 27 Feb 2024 01:48:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWHX9Xag3haBkx7WrNDB4iDuAKJJopy0T3G6FgHbLs7ZdLSV01zo6bPHDD+1cYWFzBqcy/VzeSel8rtlH8d089+CxUFmgvJkw1DTQ== X-Google-Smtp-Source: AGHT+IFC3zzKYOjzpc1kJuYUjWvnHY3kB5f3YlFagxgZto5J86RIJTTm5eEFUFGmbQcZHJSlS0Za X-Received: by 2002:a17:906:6b8d:b0:a43:c0f7:d2c9 with SMTP id l13-20020a1709066b8d00b00a43c0f7d2c9mr461655ejr.47.1709027316210; Tue, 27 Feb 2024 01:48:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709027316; cv=none; d=google.com; s=arc-20160816; b=Lh6ip9VP+mVpW2KL5OXxOEryAZRbW3Gxa4PdF/L8ebAQa8qAHRfhI32ELwipwC+b+5 s234vqvDFnvQtWNRknSvwyia/zq4s+lkx8m/qFydSXCeRF6WviT3gMpabe/EB390GuBl hJdhPIELw7h7GMZgN/S4M0Q9z3zB1rcYNo7H7XWYOkXtBV6gCBcQien1cpQYlKO19Sil +3wQ76ba5v9tLBKqRJ/z6jAtVQ4fb2q0htR8xFn64KlGwX1qdg06c2DBDYKgGFy8kvfM fmWYYziY2jYvRU5pSeVVujYQ1XOtYuiuDI4Lt0bpMxb+on2jCAb2eEihFUrpK6LxaDxj p3FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=uFIBfVnvqX+jOZyySdPRyrM00gBmn07dE/9hbpfGBVY=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=ekeG9sYFt1U87hfv8FUZBIOD+I7epGz6MzOq+bAO1CMLbKO88Lkvw1UN5dt4JY+k4x ffVUUWiAOpOpwarqZqavJpBY1T/5jU19WdSvdhtbcvSmXsiwoaU9GhCS+mpzhDw7pv+Z WJTDCh2+9pCTOCz4GgLPvOsZHqSrQZXDQIj0nlLuLOydN5X8egyX21yweg6dqch0Wla7 MaRmySD2XN3h3poEHdHTAlokj1vo/qsaAI6mKoo2ucCm/lxOFT/yP0ow8lfmgOJ0oOWH xK549YlRCWLLgho6tf+BCYuBnbIuOCE6tnD0MWvWOI/21WuYao240O2wjFiEAZY5H1eo IWAA==; dara=google.com ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u12-20020a17090657cc00b00a4353981511si563299ejr.749.2024.02.27.01.48.35; Tue, 27 Feb 2024 01:48:36 -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 E56D468C462; Tue, 27 Feb 2024 11:48:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 064A668C462 for ; Tue, 27 Feb 2024 11:48:25 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C95BAE9F0C; Tue, 27 Feb 2024 10:48:23 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kwKQdy8EOLgI; Tue, 27 Feb 2024 10:48:22 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5A063E9EFB; Tue, 27 Feb 2024 10:48:22 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Feb 2024 10:48:09 +0100 Message-Id: <20240227094810.1182-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240226221940.GV6420@pb2> References: <20240226221940.GV6420@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] swresample/resample: fix rounding errors with filter_size=1 and phase_shift=0 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: IQSb8mbiT3UG Depending on input chunk size noticable corrpution was hearable, here is an example command line: ffplay -f lavfi -i "sine=440:r=8000:samples_per_frame=32,aresample=24000:filter_size=1:phase_shift=0" Fix this by rounding the fixed point fractions up instead of down. Signed-off-by: Marton Balint --- libswresample/resample.c | 4 ++-- tests/fate/libswresample.mak | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libswresample/resample.c b/libswresample/resample.c index bd54a7002f..17cebad01b 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -357,8 +357,8 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A *consumed = 0; if (c->filter_length == 1 && c->phase_count == 1) { - int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*c->index; - int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr; + int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*c->index + 1; + int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr + 1; int new_size = (src_size * (int64_t)c->src_incr - c->frac + c->dst_incr - 1) / c->dst_incr; dst_size = FFMAX(FFMIN(dst_size, new_size), 0); diff --git a/tests/fate/libswresample.mak b/tests/fate/libswresample.mak index 2fc55ea61a..0971a6b3ba 100644 --- a/tests/fate/libswresample.mak +++ b/tests/fate/libswresample.mak @@ -347,13 +347,13 @@ endef fate-swr-resample_nn-fltp-44100-8000: CMP_TARGET = 591.03 fate-swr-resample_nn-fltp-44100-8000: SIZE_TOLERANCE = 529200 - 20486 -fate-swr-resample_nn-fltp-8000-44100: CMP_TARGET = 3163.32 +fate-swr-resample_nn-fltp-8000-44100: CMP_TARGET = 3156.61 fate-swr-resample_nn-fltp-8000-44100: SIZE_TOLERANCE = 96000 - 20480 fate-swr-resample_nn-s16p-44100-8000: CMP_TARGET = 590.98 fate-swr-resample_nn-s16p-44100-8000: SIZE_TOLERANCE = 529200 - 20486 -fate-swr-resample_nn-s16p-8000-44100: CMP_TARGET = 3163.39 +fate-swr-resample_nn-s16p-8000-44100: CMP_TARGET = 3156.61 fate-swr-resample_nn-s16p-8000-44100: SIZE_TOLERANCE = 96000 - 20480 define ARESAMPLE_ASYNC