From patchwork Fri Aug 4 19:19:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 43128 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9329:b0:130:ccc6:6c4b with SMTP id r41csp168271pzh; Fri, 4 Aug 2023 12:19:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGq8mxXyS9TaBxqkLDLwbyXw/9ui56zKS79Jj83hX8mgvDkURuudPk6VyGCqyv77+Biucw4 X-Received: by 2002:a05:6402:2046:b0:523:1004:1c9b with SMTP id bc6-20020a056402204600b0052310041c9bmr2240205edb.20.1691176770508; Fri, 04 Aug 2023 12:19:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691176770; cv=none; d=google.com; s=arc-20160816; b=VKXdPhjMB6xQCEn/ftZR48+JZmS+7OmE8cA0x/HxbtbFxFaDgtqiHHKhUr1q2xJFes luWhK8snsmAZ6m4DK2tiWSkkCirrxUm7pm4XK+jyf1sZYmamfeM2C4cxYyArbKBQb4Rx 5mTHmOObQuG+qThA1oWKzxsao3Kl5j4qtM5ir7AcW1QNcYTz83rEvtFOIOHmJntwWIkl AunKWJ+jfQ3kF/kJVSc5VFkkLsIUxXBucIuHNmTZEHuMwY8nIr1L3qW/bXyknHrJzXnk BtOErDTKI7mZarfNfLL8iqGGyqTbdoXLPK/OUocBzEnycWV0W/UYKG29KM8VdlwNovKN iGAg== 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=5fE46NzymSP+8BSHqj4xjE+ixhegrTmmHw0QO4u/AEM=; fh=NIkoTDpgqwsBDY3Ej4pG8uwJcqBS6rd7Vc7bU5x+v0U=; b=FueonxH/jKZJQcDDD6GuqOFqYeixWFW8UkIGn1YI0rdtHCP9kjvmKPpzg5wbsA4V24 dnyUITXj5PVgbHcgBZSFmX4vBrHWg1iPl6zcxhpnXg2ZYY0zt+7/a0ZEQfc53kUkrLvO dz5nZmavrq/ebZQ6qyzSh5cgAOruAASWoftFtINOhuU1LLoQy1pTrjX/TII/juzvQjgW u6tS35difQIXMlnycf8Ve3ARxK/WQdcQd4yJEhitUuAul57lc40vMSoh1+pg35st78iE y804AS9aaa47S8XWUrxDVf2upx1w5u4JKJ0N9MSn8dU+X66c0u3m5j0kdErPIfWfMEMX YH7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=YsNWzG0M; 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 g2-20020aa7c582000000b005224f9c546csi1640573edq.487.2023.08.04.12.19.12; Fri, 04 Aug 2023 12:19:30 -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=YsNWzG0M; 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 4A68068C748; Fri, 4 Aug 2023 22:19:08 +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 600D168C402 for ; Fri, 4 Aug 2023 22:19:01 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 17CD7106015D for ; Fri, 4 Aug 2023 19:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1691176740; 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=II1id0lsGB7q9fTbu9bSK1OMyTk/FpctzOO41mcVFLs=; b=YsNWzG0MnPysQXp0Ml5CQcNsReoREenT5WjLyartM/M+TGb+KsA/6Zf1WTlGeL7D vyXAXeaF3gLvVet3tOaID3XeGexY2zWMlLuC+QbyDgJ8nNq0MFrkxPXoToikx5pbEvH 8mLH6PNjB89KsbzVKbI3Hn2aJGCqO8BqNmc/1P/dgrJvi0TBipiIOWf/iSgxxs5TyE2 AVIwEZFLyuX+9p4E6ICEWktRP4DRDXASyVK93kRHVBZ2uPSBpncIhlLq29Q6ZlMkSET 7xtxSvi08Pb4+ApBJYjFfpjNEOTmlXo1kNQgoxDgA2VJ2lOHXLJ6n/5/PmId93mrZJB uzOskmCGWQ== Date: Fri, 4 Aug 2023 21:19:00 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] wmavoice: convert RDFT to lavu/tx 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: OclouZpbHWXc Patch attached. From a5b6b7d954447d4cc07377f00370a0781e5056b3 Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 4 Aug 2023 20:20:10 +0200 Subject: [PATCH 1/2] wmavoice: convert RDFT to lavu/tx --- libavcodec/wmavoice.c | 75 ++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 44fda0e2d6..5ae92e2dbc 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -31,6 +31,7 @@ #include "libavutil/float_dsp.h" #include "libavutil/mem_internal.h" #include "libavutil/thread.h" +#include "libavutil/tx.h" #include "avcodec.h" #include "codec_internal.h" #include "decode.h" @@ -263,8 +264,8 @@ typedef struct WMAVoiceContext { * smoothing and so on, and context variables for FFT/iFFT. * @{ */ - RDFTContext rdft, irdft; ///< contexts for FFT-calculation in the - ///< postfilter (for denoise filter) + AVTXContext *rdft, *irdft; ///< contexts for FFT-calculation in the + av_tx_fn rdft_fn, irdft_fn; ///< postfilter (for denoise filter) DCTContext dct, dst; ///< contexts for phase shift (in Hilbert ///< transform, part of postfilter) float sin[511], cos[511]; ///< 8-bit cosine/sine windows over [-pi,pi] @@ -277,9 +278,9 @@ typedef struct WMAVoiceContext { ///< by postfilter float denoise_filter_cache[MAX_FRAMESIZE]; int denoise_filter_cache_size; ///< samples in #denoise_filter_cache - DECLARE_ALIGNED(32, float, tilted_lpcs_pf)[0x80]; + DECLARE_ALIGNED(32, float, tilted_lpcs_pf)[0x82]; ///< aligned buffer for LPC tilting - DECLARE_ALIGNED(32, float, denoise_coeffs_pf)[0x80]; + DECLARE_ALIGNED(32, float, denoise_coeffs_pf)[0x82]; ///< aligned buffer for denoise coefficients DECLARE_ALIGNED(32, float, synth_filter_out_buf)[0x80 + MAX_LSPS_ALIGN16]; ///< aligned buffer for postfilter speech @@ -388,12 +389,20 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) s->spillover_bitsize = 3 + av_ceil_log2(ctx->block_align); s->do_apf = flags & 0x1; if (s->do_apf) { - if ((ret = ff_rdft_init(&s->rdft, 7, DFT_R2C)) < 0 || - (ret = ff_rdft_init(&s->irdft, 7, IDFT_C2R)) < 0 || - (ret = ff_dct_init (&s->dct, 6, DCT_I)) < 0 || + float scale = 1.0f; + + if ((ret = ff_dct_init (&s->dct, 6, DCT_I)) < 0 || (ret = ff_dct_init (&s->dst, 6, DST_I)) < 0) return ret; + ret = av_tx_init(&s->rdft, &s->rdft_fn, AV_TX_FLOAT_RDFT, 0, 1 << 7, &scale, 0); + if (ret < 0) + return ret; + + ret = av_tx_init(&s->irdft, &s->irdft_fn, AV_TX_FLOAT_RDFT, 1, 1 << 7, &scale, 0); + if (ret < 0) + return ret; + ff_sine_window_init(s->cos, 256); memcpy(&s->sin[255], s->cos, 256 * sizeof(s->cos[0])); for (n = 0; n < 255; n++) { @@ -596,20 +605,24 @@ static float tilt_factor(const float *lpcs, int n_lpcs) /** * Derive denoise filter coefficients (in real domain) from the LPCs. */ -static void calc_input_response(WMAVoiceContext *s, float *lpcs, - int fcb_type, float *coeffs, int remainder) +static void calc_input_response(WMAVoiceContext *s, float *lpcs_src, + int fcb_type, float *coeffs_dst, int remainder) { float last_coeff, min = 15.0, max = -15.0; float irange, angle_mul, gain_mul, range, sq; + LOCAL_ALIGNED_32(float, coeffs, [0x82]); + LOCAL_ALIGNED_32(float, lpcs, [0x82]); int n, idx; + memcpy(coeffs, coeffs_dst, 0x82*sizeof(float)); + /* Create frequency power spectrum of speech input (i.e. RDFT of LPCs) */ - s->rdft.rdft_calc(&s->rdft, lpcs); + s->rdft_fn(s->rdft, lpcs, lpcs_src, sizeof(float)); #define log_range(var, assign) do { \ float tmp = log10f(assign); var = tmp; \ max = FFMAX(max, tmp); min = FFMIN(min, tmp); \ } while (0) - log_range(last_coeff, lpcs[1] * lpcs[1]); + log_range(last_coeff, lpcs[64] * lpcs[64]); for (n = 1; n < 64; n++) log_range(lpcs[n], lpcs[n * 2] * lpcs[n * 2] + lpcs[n * 2 + 1] * lpcs[n * 2 + 1]); @@ -668,25 +681,25 @@ static void calc_input_response(WMAVoiceContext *s, float *lpcs, coeffs[n * 2 + 1] = coeffs[n] * s->sin[idx]; coeffs[n * 2] = coeffs[n] * s->cos[idx]; } - coeffs[1] = last_coeff; + coeffs[64] = last_coeff; /* move into real domain */ - s->irdft.rdft_calc(&s->irdft, coeffs); + s->irdft_fn(s->irdft, coeffs_dst, coeffs, sizeof(AVComplexFloat)); /* tilt correction and normalize scale */ - memset(&coeffs[remainder], 0, sizeof(coeffs[0]) * (128 - remainder)); + memset(&coeffs_dst[remainder], 0, sizeof(coeffs_dst[0]) * (128 - remainder)); if (s->denoise_tilt_corr) { float tilt_mem = 0; - coeffs[remainder - 1] = 0; + coeffs_dst[remainder - 1] = 0; ff_tilt_compensation(&tilt_mem, - -1.8 * tilt_factor(coeffs, remainder - 1), - coeffs, remainder); + -1.8 * tilt_factor(coeffs_dst, remainder - 1), + coeffs_dst, remainder); } - sq = (1.0 / 64.0) * sqrtf(1 / avpriv_scalarproduct_float_c(coeffs, coeffs, + sq = (1.0 / 64.0) * sqrtf(1 / avpriv_scalarproduct_float_c(coeffs_dst, coeffs_dst, remainder)); for (n = 0; n < remainder; n++) - coeffs[n] *= sq; + coeffs_dst[n] *= sq; } /** @@ -722,6 +735,8 @@ static void wiener_denoise(WMAVoiceContext *s, int fcb_type, int remainder, lim, n; if (fcb_type != FCB_TYPE_SILENCE) { + LOCAL_ALIGNED_32(float, coeffs_f, [0x82]); + LOCAL_ALIGNED_32(float, synth_f, [0x82]); float *tilted_lpcs = s->tilted_lpcs_pf, *coeffs = s->denoise_coeffs_pf, tilt_mem = 0; @@ -742,16 +757,16 @@ static void wiener_denoise(WMAVoiceContext *s, int fcb_type, /* apply coefficients (in frequency spectrum domain), i.e. complex * number multiplication */ memset(&synth_pf[size], 0, sizeof(synth_pf[0]) * (128 - size)); - s->rdft.rdft_calc(&s->rdft, synth_pf); - s->rdft.rdft_calc(&s->rdft, coeffs); - synth_pf[0] *= coeffs[0]; - synth_pf[1] *= coeffs[1]; - for (n = 1; n < 64; n++) { - float v1 = synth_pf[n * 2], v2 = synth_pf[n * 2 + 1]; - synth_pf[n * 2] = v1 * coeffs[n * 2] - v2 * coeffs[n * 2 + 1]; - synth_pf[n * 2 + 1] = v2 * coeffs[n * 2] + v1 * coeffs[n * 2 + 1]; + s->rdft_fn(s->rdft, synth_f, synth_pf, sizeof(float)); + s->rdft_fn(s->rdft, coeffs_f, coeffs, sizeof(float)); + synth_f[0] *= coeffs_f[0]; + synth_f[1] *= coeffs_f[1]; + for (n = 1; n <= 64; n++) { + float v1 = synth_f[n * 2], v2 = synth_f[n * 2 + 1]; + synth_f[n * 2] = v1 * coeffs_f[n * 2] - v2 * coeffs_f[n * 2 + 1]; + synth_f[n * 2 + 1] = v2 * coeffs_f[n * 2] + v1 * coeffs_f[n * 2 + 1]; } - s->irdft.rdft_calc(&s->irdft, synth_pf); + s->irdft_fn(s->irdft, synth_pf, synth_f, sizeof(AVComplexFloat)); } /* merge filter output with the history of previous runs */ @@ -1986,8 +2001,8 @@ static av_cold int wmavoice_decode_end(AVCodecContext *ctx) WMAVoiceContext *s = ctx->priv_data; if (s->do_apf) { - ff_rdft_end(&s->rdft); - ff_rdft_end(&s->irdft); + av_tx_uninit(&s->rdft); + av_tx_uninit(&s->irdft); ff_dct_end(&s->dct); ff_dct_end(&s->dst); } -- 2.40.1