From patchwork Mon Feb 26 00:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46529 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51b:b0:19e:cdac:8cce with SMTP id gm27csp1099404pzb; Sun, 25 Feb 2024 16:45:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW7k0kNBg1oFf8hR4yUCdPwbe3ZyaDzGFJg8J6NThKmnFcttCYlkfIXShVD+lw6ysMUI6hLp4CAYFoUOy1JGvS0Dw4/pF8/+Vc5WQ== X-Google-Smtp-Source: AGHT+IG9Nxa9tYhpRKYnmbs7wxKZDW3JcdJ5MgUJeuExsZZW6oSduVEYhX1qpe7dl+fJ6jMenjKC X-Received: by 2002:a17:906:807:b0:a41:309d:8a3b with SMTP id e7-20020a170906080700b00a41309d8a3bmr3317506ejd.41.1708908348586; Sun, 25 Feb 2024 16:45:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708908348; cv=none; d=google.com; s=arc-20160816; b=CYxDfxNuk/6nLdgHdksVzLpIw1hUFUFYH5c2I684hZqtx0apun83pS4mhxezjHh2Mz Syz4gk8Xe8ciHCoiVZ7K5AloKtWXzwLlJ5OggAeC2GmT4K6duWifx4afI0JoTlI9Hn1b ffXmsZBbPp+xx8FXRcDsCS2Fojx9jxe+WQAoU3ZJ4JJEck4XGIPLjovHlnZfEpo4nBnI 3XQzpqh3UuxrklvDUGezrWF4CLSdfTqGKZogMj9MeVPOCE5BDY0eoUinUEsKSMju9LpI ItfiQ84HeGIK7Zmc2qbP+SN8omBX/xCPKtSNhUK7wkBtYlFsBKQuuDwXBGI+VHfktBeq nveg== 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=3ljZZqGREAegZSeVbcT3C77JagjhmiQKVuVanVeMhVA=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=Awih2lmlWgzu8WLR0Mu27F0ud90GuL0Go3KzeFmaCpxYX8AejkFra2S/9ghv+/34Go myTxn7dIwZ/Aetxxkh5EYMAzsClvhmXM5VUs0gl5C/v5McWpD6wxxJV5WgJy8W2uGOGj tgN0W5zaXFS5v21S3svTK3OlvamgzzL5FIb/sPz6B5zeAZcu7R2cEiOHNtL3DRas67Iz QymQ8SgkRZ3/5sxIGZSW/zXxLY1cF/x/28sA5F3SeSdCrAQvgBr/dv5qBAk0dPQ79S+F 2Qh1+vFBvVInYy2pfizo6YRawFEn1ejOGVH4ynvUO13XHokmIyN7P5BkVIN/YSYJWff8 kctQ==; 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 bv9-20020a170907934900b00a3ea9a44b5csi1652445ejc.87.2024.02.25.16.45.48; Sun, 25 Feb 2024 16:45:48 -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 07ED068C7E4; Mon, 26 Feb 2024 02:45:40 +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 7978B68AC15 for ; Mon, 26 Feb 2024 02:45:33 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 537D4EA064; Mon, 26 Feb 2024 01:45:33 +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 uahoeZ0PInl5; Mon, 26 Feb 2024 01:45:31 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A2903EA079; Mon, 26 Feb 2024 01:45:31 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Feb 2024 01:45:23 +0100 Message-Id: <20240226004525.4321-2-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240226004525.4321-1-cus@passwd.hu> References: <20240226004525.4321-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] swresample/resample: rework resample_one function to work the same way as the others 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: vD7vbH1wRZrR This also fixes resampling with filter_size=1 and phase_shift=0, depending on input chunk size noticable corrpution was hearable with this command line: ffplay -f lavfi -i "sine=440:r=8000:samples_per_frame=32,aresample=24000:filter_size=1:phase_shift=0" Signed-off-by: Marton Balint --- libswresample/resample.c | 29 +++++++---------------------- libswresample/resample.h | 4 ++-- libswresample/resample_template.c | 29 ++++++++++++++++++++++++----- tests/fate/libswresample.mak | 4 ++-- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/libswresample/resample.c b/libswresample/resample.c index bd54a7002f..89859dec79 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -356,26 +356,7 @@ 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; - 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); - if (dst_size > 0) { - for (i = 0; i < dst->ch_count; i++) { - c->dsp.resample_one(dst->ch[i], src->ch[i], dst_size, index2, incr); - if (i+1 == dst->ch_count) { - c->index += dst_size * c->dst_incr_div; - c->index += (c->frac + dst_size * (int64_t)c->dst_incr_mod) / c->src_incr; - av_assert2(c->index >= 0); - *consumed = c->index; - c->frac = (c->frac + dst_size * (int64_t)c->dst_incr_mod) % c->src_incr; - c->index = 0; - } - } - } - } else { + { int64_t end_index = (1LL + src_size - c->filter_length) * c->phase_count; int64_t delta_frac = (end_index - c->index) * c->src_incr - c->frac; int delta_n = (delta_frac + c->dst_incr - 1) / c->dst_incr; @@ -386,8 +367,12 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A if (dst_size > 0) { /* resample_linear and resample_common should have same behavior * when frac and dst_incr_mod are zero */ - resample_func = (c->linear && (c->frac || c->dst_incr_mod)) ? - c->dsp.resample_linear : c->dsp.resample_common; + if (c->filter_length == 1 && c->phase_count == 1) + resample_func = c->dsp.resample_one; + else if (c->linear && (c->frac || c->dst_incr_mod)) + resample_func = c->dsp.resample_linear; + else + resample_func = c->dsp.resample_common; for (i = 0; i < dst->ch_count; i++) *consumed = resample_func(c, dst->ch[i], src->ch[i], dst_size, i+1 == dst->ch_count); } diff --git a/libswresample/resample.h b/libswresample/resample.h index 1731dad3cf..8cc29effe8 100644 --- a/libswresample/resample.h +++ b/libswresample/resample.h @@ -51,8 +51,8 @@ typedef struct ResampleContext { int phase_count_compensation; /* desired phase_count when compensation is enabled */ struct { - void (*resample_one)(void *dst, const void *src, - int n, int64_t index, int64_t incr); + int (*resample_one)(struct ResampleContext *c, void *dst, + const void *src, int n, int update_ctx); int (*resample_common)(struct ResampleContext *c, void *dst, const void *src, int n, int update_ctx); int (*resample_linear)(struct ResampleContext *c, void *dst, diff --git a/libswresample/resample_template.c b/libswresample/resample_template.c index 4c227b9940..0c6e0ee34d 100644 --- a/libswresample/resample_template.c +++ b/libswresample/resample_template.c @@ -72,17 +72,36 @@ #endif -static void RENAME(resample_one)(void *dest, const void *source, - int dst_size, int64_t index2, int64_t incr) +static int RENAME(resample_one)(ResampleContext *c, + void *dest, const void *source, + int n, int update_ctx) { DELEM *dst = dest; const DELEM *src = source; int dst_index; + int frac= c->frac; + int sample_index = c->index; + int index = 0; + + for (dst_index = 0; dst_index < n; dst_index++) { + dst[dst_index] = src[sample_index]; + + frac += c->dst_incr_mod; + index += c->dst_incr_div; + if (frac >= c->src_incr) { + frac -= c->src_incr; + index++; + } + sample_index += index; + index = 0; + } - for (dst_index = 0; dst_index < dst_size; dst_index++) { - dst[dst_index] = src[index2 >> 32]; - index2 += incr; + if(update_ctx){ + c->frac= frac; + c->index= index; } + + return sample_index; } static int RENAME(resample_common)(ResampleContext *c, 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