From patchwork Mon Apr 15 06:28:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 48063 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:670b:b0:1a9:af23:56c1 with SMTP id wh11csp1657628pzb; Sun, 14 Apr 2024 23:28:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXmuQSVc8/c15wx4+qs+HrVQmPJN9RqTrrfLsJ2VWN4Shw2mErQg9Qz8Hc2+yTyylKeCU/54CLQqE8svkv20IgtZRvVa373Bm/ojA== X-Google-Smtp-Source: AGHT+IHqN2Y5y0gRhPvH5Y3Cg90Lm4PXHMI0vIVPxXkatMfgT2hcBLYDvoeoWzz+HrLwEmDn2In8 X-Received: by 2002:a50:c30a:0:b0:570:11ee:a070 with SMTP id a10-20020a50c30a000000b0057011eea070mr3157598edb.4.1713162523129; Sun, 14 Apr 2024 23:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713162523; cv=none; d=google.com; s=arc-20160816; b=U5zg3vPPIR7/oe0Uh6WuLZKVyY0Xt7YvSMlO0e3ivYfftHc/HYmJPuyG1de4nTGOy/ 8EktU7H4yPe/OvqKG+cHB/FRi/lE757Pt554DFIhQU4h3FTcwjuD6rH4+ci2cm5XBY7f Xhyi4orqu0VuTouglZwJaoxGQcNYOUAitpG5tnJf9dGOTCJlmapIP5fr8Pkx4VuSudMk ateCY+qgnctKEa8RWEIBjBC4X7jJ3/iGyydHV0rguGn+CVV2hZ9WyHfhD8fD2uwFylNi uOn1JC1CAh9k8Cv2OoPUrEx+HLxIqceziMTELKdL103LGohVKHEgaUDR5rsiPMGojUsr NBCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=QsjIQTQb8alpzFKpG7OhN01FCH60b/AarRgbj39c1ac=; fh=Q46kXK7oI5D1Jhi90JBr53c7NIaTxGaU4KPeRZyM/hI=; b=iG7xWUDUALLNSPDAlrYm3Z8tptOl56OTFthS0M9UR8LDy6HtTOA+gpVA/mqpf+ovZ+ qyZrRuF02EMfUa4F8gjQoghiD+9T61ABIzLifZYqQyNtznGpQ+sHTazlZaT+MtEpLzGM pSkqlXQvGU7E0YOYinFUkqgy/3iKYLjpHKTHvyHB6zp6BuTShlOWi/TTILYbjiVqiAp8 sNk3EUNJzDaa1N6WZoZ4MfRZQv0pCmWzx+I2eGS2EdwRQ4lMldDD5No2+Va7G49CV9De wyn/E+hIQM3Dd1nlWM6DYV3GGXWFyQn2kCxhscXvS0BBxuB57rtyLyHfCqGsiI1hm2O3 cdZA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=g+fTT5Rx; 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=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ew7-20020a056402538700b0056df633774asi4404813edb.553.2024.04.14.23.28.42; Sun, 14 Apr 2024 23:28:43 -0700 (PDT) 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=@lynne.ee header.s=s1 header.b=g+fTT5Rx; 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=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 60F1368D3F4; Mon, 15 Apr 2024 09:28:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44E4768D316 for ; Mon, 15 Apr 2024 09:28:31 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 9F4AD106015A for ; Mon, 15 Apr 2024 06:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1713162510; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=HbXKhG9FMCPzUVxDM0TJ7M7bf8XHtdf8OFecHYKZY5A=; b=g+fTT5RxsaPJ+4tAwXr1ROqPXOrmWeIeXKn6Fh4N7xU4rmcqMjZz3LRtrwjgwuHJ 8UoD46onjKXvP7aJC4vR+Cz8jmatRHSKn8XZBC5qdv+xMHt3VJ/DHMDfEjYm/L7wjRR ihnfOf9WEO90oqCnl17CdZ8Wn7aAGG4u03Jx90Az5AoXLVDfEGE3ZhmHy7OsKEkKuEB +RaIFTGBat7gDa0fivcB0FsguwoEueorN4vuAY4h6DcoFp61zfvAecROHqHPJw1Vfbh hNp+tEv6TElQK7IGDTfjtDJCQO8+0DuApaQZpKEoCNMlDmGkLAdzGpX3GU/DF7+K6ol g+6P92ehlw== Date: Mon, 15 Apr 2024 08:28:30 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] opusdsp: add ability to modify deemphasis constant 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Ui2Iq/yKH0EE xHE-AAC relies on the same postfilter mechanism that Opus uses to improve clarity (albeit with a steeper deemphasis filter, using a z=0.64). The code to apply it is identical, it's still just a simple IIR low-pass filter. This commit makes it possible to use alternative constants. Patch attached. From c4ad107076970a555ed838a75c0343dffe0cad36 Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 29 Jan 2024 04:31:43 +0100 Subject: [PATCH] opusdsp: add ability to modify deemphasis constant xHE-AAC relies on the same postfilter mechanism that Opus uses to improve clarity (albeit with a steeper deemphasis filter). The code to apply it is identical, it's still just a simple IIR low-pass filter. This commit makes it possible to use alternative constants. --- libavcodec/aarch64/opusdsp_init.c | 2 +- libavcodec/aarch64/opusdsp_neon.S | 28 +++++----------------------- libavcodec/opusdec_celt.c | 4 +++- libavcodec/opusdsp.c | 28 ++++++++++++++++++++++++++-- libavcodec/opusdsp.h | 2 +- libavcodec/x86/opusdsp.asm | 9 +++------ libavcodec/x86/opusdsp_init.c | 2 +- 7 files changed, 40 insertions(+), 35 deletions(-) diff --git a/libavcodec/aarch64/opusdsp_init.c b/libavcodec/aarch64/opusdsp_init.c index bb6d71b66b..449d95e8d3 100644 --- a/libavcodec/aarch64/opusdsp_init.c +++ b/libavcodec/aarch64/opusdsp_init.c @@ -23,7 +23,7 @@ #include "libavcodec/opusdsp.h" void ff_opus_postfilter_neon(float *data, int period, float *gains, int len); -float ff_opus_deemphasis_neon(float *out, float *in, float coeff, int len); +float ff_opus_deemphasis_neon(float *out, float *in, float coeff, float *weights, int len); av_cold void ff_opus_dsp_init_aarch64(OpusDSP *ctx) { diff --git a/libavcodec/aarch64/opusdsp_neon.S b/libavcodec/aarch64/opusdsp_neon.S index e933151ab4..253825aa61 100644 --- a/libavcodec/aarch64/opusdsp_neon.S +++ b/libavcodec/aarch64/opusdsp_neon.S @@ -18,29 +18,11 @@ #include "libavutil/aarch64/asm.S" - // 0.85..^1 0.85..^2 0.85..^3 0.85..^4 -const tab_st, align=4 - .word 0x3f599a00, 0x3f38f671, 0x3f1d382a, 0x3f05a32f -endconst -const tab_x0, align=4 - .word 0x0, 0x3f599a00, 0x3f38f671, 0x3f1d382a -endconst -const tab_x1, align=4 - .word 0x0, 0x0, 0x3f599a00, 0x3f38f671 -endconst -const tab_x2, align=4 - .word 0x0, 0x0, 0x0, 0x3f599a00 -endconst - function ff_opus_deemphasis_neon, export=1 - movrel x4, tab_st - ld1 {v4.4s}, [x4] - movrel x4, tab_x0 - ld1 {v5.4s}, [x4] - movrel x4, tab_x1 - ld1 {v6.4s}, [x4] - movrel x4, tab_x2 - ld1 {v7.4s}, [x4] + ld1 {v4.4s}, [x2], #16 + ld1 {v5.4s}, [x2], #16 + ld1 {v6.4s}, [x2], #16 + ld1 {v7.4s}, [x2] fmul v0.4s, v4.4s, v0.s[0] @@ -63,7 +45,7 @@ function ff_opus_deemphasis_neon, export=1 st1 {v1.4s, v2.4s}, [x0], #32 fmul v0.4s, v4.4s, v2.s[3] - subs w2, w2, #8 + subs w3, w3, #8 b.gt 1b mov s0, v2.s[3] diff --git a/libavcodec/opusdec_celt.c b/libavcodec/opusdec_celt.c index fd8e9929e9..2dd3e12c48 100644 --- a/libavcodec/opusdec_celt.c +++ b/libavcodec/opusdec_celt.c @@ -460,7 +460,9 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, /* deemphasis */ block->emph_coeff = f->opusdsp.deemphasis(output[i], &block->buf[1024 - frame_size], - block->emph_coeff, frame_size); + block->emph_coeff, + ff_deemph_opus_weights, + frame_size); } if (channels == 1) diff --git a/libavcodec/opusdsp.c b/libavcodec/opusdsp.c index 0764d712e4..e46079c271 100644 --- a/libavcodec/opusdsp.c +++ b/libavcodec/opusdsp.c @@ -18,8 +18,31 @@ #include "config.h" #include "libavutil/attributes.h" +#include "libavutil/mem_internal.h" #include "opusdsp.h" +static const DECLARE_ALIGNED(16, float, ff_deemph_opus_weights)[] = { + CELT_EMPH_COEFF, + CELT_EMPH_COEFF*CELT_EMPH_COEFF, + CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF, + CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF, + + 0, + CELT_EMPH_COEFF, + CELT_EMPH_COEFF*CELT_EMPH_COEFF, + CELT_EMPH_COEFF*CELT_EMPH_COEFF*CELT_EMPH_COEFF, + + 0, + 0, + CELT_EMPH_COEFF, + CELT_EMPH_COEFF*CELT_EMPH_COEFF, + + 0, + 0, + 0, + CELT_EMPH_COEFF, +}; + static void postfilter_c(float *data, int period, float *gains, int len) { const float g0 = gains[0]; @@ -43,10 +66,11 @@ static void postfilter_c(float *data, int period, float *gains, int len) } } -static float deemphasis_c(float *y, float *x, float coeff, int len) +static float deemphasis_c(float *y, float *x, float coeff, float *weights, int len) { + float c = weights[0]; for (int i = 0; i < len; i++) - coeff = y[i] = x[i] + coeff*CELT_EMPH_COEFF; + coeff = y[i] = x[i] + coeff*c; return coeff; } diff --git a/libavcodec/opusdsp.h b/libavcodec/opusdsp.h index c2a301e832..0745348e21 100644 --- a/libavcodec/opusdsp.h +++ b/libavcodec/opusdsp.h @@ -23,7 +23,7 @@ typedef struct OpusDSP { void (*postfilter)(float *data, int period, float *gains, int len); - float (*deemphasis)(float *out, float *in, float coeff, int len); + float (*deemphasis)(float *out, float *in, float coeff, float *weights, int len); } OpusDSP; void ff_opus_dsp_init(OpusDSP *ctx); diff --git a/libavcodec/x86/opusdsp.asm b/libavcodec/x86/opusdsp.asm index 418cc16330..635f59f83c 100644 --- a/libavcodec/x86/opusdsp.asm +++ b/libavcodec/x86/opusdsp.asm @@ -22,16 +22,13 @@ SECTION_RODATA - ; 0.85..^1 0.85..^2 0.85..^3 0.85..^4 -tab_st: dd 0x3f599a00, 0x3f38f671, 0x3f1d382a, 0x3f05a32f - SECTION .text INIT_XMM fma3 %if UNIX64 -cglobal opus_deemphasis, 3, 3, 8, out, in, len +cglobal opus_deemphasis, 4, 4, 8, out, in, weights, len %else -cglobal opus_deemphasis, 4, 4, 8, out, in, coeff, len +cglobal opus_deemphasis, 5, 5, 8, out, in, coeff, weights, len %endif %if ARCH_X86_32 VBROADCASTSS m0, coeffm @@ -41,7 +38,7 @@ cglobal opus_deemphasis, 4, 4, 8, out, in, coeff, len shufps m0, m0, 0 %endif - movaps m4, [tab_st] + movaps m4, [weightsq] VBROADCASTSS m5, m4 shufps m6, m4, m4, q1111 shufps m7, m4, m4, q2222 diff --git a/libavcodec/x86/opusdsp_init.c b/libavcodec/x86/opusdsp_init.c index 582fbb4f0c..f9ea4eac8b 100644 --- a/libavcodec/x86/opusdsp_init.c +++ b/libavcodec/x86/opusdsp_init.c @@ -23,7 +23,7 @@ #include "libavcodec/opusdsp.h" void ff_opus_postfilter_fma3(float *data, int period, float *gains, int len); -float ff_opus_deemphasis_fma3(float *out, float *in, float coeff, int len); +float ff_opus_deemphasis_fma3(float *out, float *in, float coeff, float *weights, int len); av_cold void ff_opus_dsp_init_x86(OpusDSP *ctx) { -- 2.43.0.381.gb435a96ce8