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 From patchwork Fri Aug 4 19:23:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 43129 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9329:b0:130:ccc6:6c4b with SMTP id r41csp170146pzh; Fri, 4 Aug 2023 12:23:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEk9JGkzQRA7TdOvbchTnGJBGCqc59Zm2BZILtaBRr5mec7Nbq1n3I0fQGF5D0EeRKVqLUV X-Received: by 2002:a17:907:2be6:b0:991:e17c:f8fa with SMTP id gv38-20020a1709072be600b00991e17cf8famr2249848ejc.61.1691177000046; Fri, 04 Aug 2023 12:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691177000; cv=none; d=google.com; s=arc-20160816; b=Uwwt6gy2LfN1QoUC8IlkQCVfyVHElNcBWAULmB6iCAkJDJmmi1jPcI7VLbEDWCEqzo iaeWk6Yadq8QNPSWFxPkeInxwcbmSLKyAGbD02F1Wl3QXvGJ4+4gadVtSrnrIy2c2l+F tcKUcnRBxAuUB8YrDNuVNANrYWCoiA+9e0mcaMBs4PS2aq99MmspzYoM0FazMqhFBaKO MLACTMET4/vSyCBr2KNhTkpKo5BYkRsCYq22hjlx8Y1+zI46q3vymRhSwDQyFrREohTi TkJLzLHP9ZwyATY+KX4MvDdvA0OJWZJ4NWg57UzBcgTZ/xKgirgcgfATI+cMGt136IXC zR1A== 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:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=LqJhCr90FACtxZGCGhzjOcrmMjgnUcnsEii+53HFDp8=; fh=awftJPkKIDcYG+GZSKK7EGrS2s4rqD3QuLTgwd5DXmc=; b=NYK3jkv/rKxNUiJicm4afF3DgG9/g6gcacmh7eEHDOJAtIGxSkPQakjvEn3F6ejnnQ kGPM26qDLtRez9iKeA/8MjK7mR0xPfFGjwVRx/5m7BJuTVCvJNqXqSbqJ/fCdr/6hS+M maIGFz47k/YAK+RZTQ9vwMVM7Wq/lhqI51/PRjPWJypa2+tRoG+1G+FaE/vV2SHTHXbF bpVU2mDxjLwXJm1NLhXHpZk09z8ot0ib6kxI2o7YOVfHcpilO5SAsYYv4IRdtcTj8fF/ tlSzUvD3FIaHRRZoimBxn7NnuS2fw6Sdmb/YU3TfEzZ/NdFnB314ptTew5zQ00RGgD+I 5d8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=iy+FhqV0; 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 f12-20020a170906824c00b00991bd84725asi1988842ejx.227.2023.08.04.12.23.19; Fri, 04 Aug 2023 12:23:19 -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=iy+FhqV0; 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 B755A68C443; Fri, 4 Aug 2023 22:23:16 +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 B1C3E68C443 for ; Fri, 4 Aug 2023 22:23:09 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id C321D1060160 for ; Fri, 4 Aug 2023 19:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1691176989; 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:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=JjcRS5MWMVchWMHYMeNipucu3NyHAGZyreCY0XhrQwI=; b=iy+FhqV0P0VTOsALHl/wp63tozJoiWOi+hswvvxP10Vu7W4nkCmqEnd1Hf2+XLRz 0q7t/+2HLU93k/kG/KypCiOukni9mcFVwIZ8vWvHTwmtcUz6F77FcjjLk9MlNlXyYkA pCz/LQun/WOQ3VlBc14O/BhMhaC+ZpIY19YcCbuTjMJBOXpf417t7j7gGx/WuDmY7B3 myHJ9L4DoaK33x8xhpPcO7Pad8/ElGN/C6YGCnRxVclI2KMpiRtaixtVICEffWJA4IG oSwD9GcP8B2rcl+70ZbAwyxeC5CB0mOcmTKE+RJKMPu/pHkKbJatZwS6jR2tv3dHGMM bgf9939jOw== Date: Fri, 4 Aug 2023 21:23:09 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] wmavoice: convert DCT-I/DST-I 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: 90oEAy8Wponz This is the very last user of any lavc transform code. This also *corrects* wmavoice decoding, as the previous DCT/DST transforms were incorrect, bringing it closer to Microsoft's own wmavoice decoder. Note: this requires new FATE files, or for the tests to be modified to use a target error. From c892079d2b816d2742aa3c192c090e2cb83952e7 Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 4 Aug 2023 21:16:30 +0200 Subject: [PATCH 2/2] wmavoice: convert DCT-I/DST-I to lavu/tx This is the very last user of any lavc transform code. This also *corrects* wmavoice decoding, as the previous DCT/DST transforms were incorrect, bringing it closer to Microsoft's own wmavoice decoder. --- libavcodec/wmavoice.c | 29 +++++++++++++++++------------ tests/fate/wma.mak | 6 +++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 5ae92e2dbc..915315cb8a 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -42,8 +42,6 @@ #include "acelp_vectors.h" #include "acelp_filters.h" #include "lsp.h" -#include "dct.h" -#include "rdft.h" #include "sinewin.h" #define MAX_BLOCKS 8 ///< maximum number of blocks per frame @@ -266,8 +264,8 @@ typedef struct WMAVoiceContext { */ 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) + AVTXContext *dct, *dst; ///< contexts for phase shift (in Hilbert + av_tx_fn dct_fn, dst_fn; ///< transform, part of postfilter) float sin[511], cos[511]; ///< 8-bit cosine/sine windows over [-pi,pi] ///< range float postfilter_agc; ///< gain control memory, used in @@ -391,10 +389,6 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) if (s->do_apf) { 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; @@ -403,6 +397,16 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx) if (ret < 0) return ret; + scale = 1.0 / (1 << 6); + ret = av_tx_init(&s->dct, &s->dct_fn, AV_TX_FLOAT_DCT_I, 0, 1 << 6, &scale, 0); + if (ret < 0) + return ret; + + scale = 1.0 / (1 << 6); + ret = av_tx_init(&s->dst, &s->dst_fn, AV_TX_FLOAT_DST_I, 0, 1 << 6, &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++) { @@ -612,6 +616,7 @@ static void calc_input_response(WMAVoiceContext *s, float *lpcs_src, float irange, angle_mul, gain_mul, range, sq; LOCAL_ALIGNED_32(float, coeffs, [0x82]); LOCAL_ALIGNED_32(float, lpcs, [0x82]); + LOCAL_ALIGNED_32(float, lpcs_dct, [0x82]); int n, idx; memcpy(coeffs, coeffs_dst, 0x82*sizeof(float)); @@ -662,8 +667,8 @@ static void calc_input_response(WMAVoiceContext *s, float *lpcs_src, * is a sine input) by doing a phase shift (in theory, H(sin())=cos()). * Hilbert_Transform(RDFT(x)) = Laplace_Transform(x), which calculates the * "moment" of the LPCs in this filter. */ - s->dct.dct_calc(&s->dct, lpcs); - s->dst.dct_calc(&s->dst, lpcs); + s->dct_fn(s->dct, lpcs_dct, lpcs, sizeof(float)); + s->dst_fn(s->dst, lpcs, lpcs_dct, sizeof(float)); /* Split out the coefficient indexes into phase/magnitude pairs */ idx = 255 + av_clip(lpcs[64], -255, 255); @@ -2003,8 +2008,8 @@ static av_cold int wmavoice_decode_end(AVCodecContext *ctx) if (s->do_apf) { av_tx_uninit(&s->rdft); av_tx_uninit(&s->irdft); - ff_dct_end(&s->dct); - ff_dct_end(&s->dst); + av_tx_uninit(&s->dct); + av_tx_uninit(&s->dst); } return 0; diff --git a/tests/fate/wma.mak b/tests/fate/wma.mak index c13874ebfc..d23ea29c92 100644 --- a/tests/fate/wma.mak +++ b/tests/fate/wma.mak @@ -20,17 +20,17 @@ fate-wmapro: $(FATE_WMAPRO-yes) FATE_WMAVOICE-$(call DEMDEC, ASF, WMAVOICE) += fate-wmavoice-7k fate-wmavoice-7k: CMD = pcm -i $(TARGET_SAMPLES)/wmavoice/streaming_CBR-7K.wma -fate-wmavoice-7k: REF = $(SAMPLES)/wmavoice/streaming_CBR-7K.pcm +fate-wmavoice-7k: REF = $(SAMPLES)/wmavoice/streaming_CBR-7K_new.pcm fate-wmavoice-7k: FUZZ = 3 FATE_WMAVOICE-$(call DEMDEC, ASF, WMAVOICE) += fate-wmavoice-11k fate-wmavoice-11k: CMD = pcm -i $(TARGET_SAMPLES)/wmavoice/streaming_CBR-11K.wma -fate-wmavoice-11k: REF = $(SAMPLES)/wmavoice/streaming_CBR-11K.pcm +fate-wmavoice-11k: REF = $(SAMPLES)/wmavoice/streaming_CBR-11K_new.pcm fate-wmavoice-11k: FUZZ = 3 FATE_WMAVOICE-$(call DEMDEC, ASF, WMAVOICE) += fate-wmavoice-19k fate-wmavoice-19k: CMD = pcm -i $(TARGET_SAMPLES)/wmavoice/streaming_CBR-19K.wma -fate-wmavoice-19k: REF = $(SAMPLES)/wmavoice/streaming_CBR-19K.pcm +fate-wmavoice-19k: REF = $(SAMPLES)/wmavoice/streaming_CBR-19K_new.pcm fate-wmavoice-19k: FUZZ = 3 $(FATE_WMAVOICE-yes): CMP = stddev -- 2.40.1