From patchwork Thu Jun 6 05:12:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 49613 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c209:0:b0:460:55fa:d5ed with SMTP id d9csp142880vqo; Wed, 5 Jun 2024 22:13:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMaMVP3172jeYYVwSn8gz2fMU3o5YyXxKqwCEGMsOFHJ+FCo4MRb6BQe3x2ln+CUlW30b8t5z893IjIZykEE45HhpPBIDOyecp0A== X-Google-Smtp-Source: AGHT+IF0vI6JHJZ+GPuWogfyp2ySlhZfU5LxSgmqJnrCDpUfeTYRpkU+udab8NDwztynFEkykaw6 X-Received: by 2002:a17:906:a885:b0:a68:e21b:35f0 with SMTP id a640c23a62f3a-a699f681ac0mr285671766b.38.1717650779824; Wed, 05 Jun 2024 22:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717650779; cv=none; d=google.com; s=arc-20160816; b=Vik5cc9DQOr9s3+xMkweMcnCExuRYr0cheRqPJHaoht35Vo+ZEOr31NzPaJ1piOm9G Ya08vKQQ/EHcVxlEsoEBQMELKkl8QQbE5+evX0rO0QdjuG/AXNgoY4ByvAQor5fB1lxT Md7MtYggLIVVbE5/5nwdQRxwG/4rJjYiDy5x4Ga0v4uMlFVaEVoIY6m7lkYFRNNbDmpo W9kfH4ghvzgBARBHhclMeaFqf5Nur+4Vmo6Q8dqJib/0Izp6XHtsCpwqET256UD+G2+/ VyUmYb/JiVgAUAa2xCJUhUTO0X0t/0LHO6zUieEKw5PBpApm7lpHNgoMbshKYz7eRxyx 1iHA== 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:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to :delivered-to; bh=Za6eIkEKYlmNSGYohTJy3ASxkPPXvtum5LSXE22yYnc=; fh=nenT92/WZoU6unXd3J6UhGUdod4piddKfVtctNBOh6k=; b=vk9jT8o0WPhtqZGLaI3faKlz/LlPcqSAl9l4Yq6eE4g/UpBsd2MQu+czKa9EVdfiIC +WKjK4j0aTDXSuZkeYWjtkLQVz0ff9AMloHUzJDpbgf5vguqzVa2PYz2BQYIeimiz1vI jq8A2LabcPMbOU6WwpwXZ2bQ4kcJGeZOdqjaIaBhTXzCAJL+2El/TgZ9aTw6zhE21vCc HwYSwGLer1aZ1hwEIlOw784VJCgvr4ZdUi8fRAXvOrhwI+3qhZT6dUedPICym1LcOpsZ OFo2NxzATEctlb9OZTnbiMLUHd5jl/MtOm6whhzQsMOIeGq/QnvUFv/gEAbXKtHzE4zl uPmg==; 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 a640c23a62f3a-a6c80581250si28716666b.22.2024.06.05.22.12.58; Wed, 05 Jun 2024 22:12:59 -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; 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 08B6568D504; Thu, 6 Jun 2024 08:12:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vidala.lynne.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E17CB68D499 for ; Thu, 6 Jun 2024 08:12:47 +0300 (EEST) To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 Jun 2024 07:12:32 +0200 Message-ID: <20240606051243.3177266-1-dev@lynne.ee> X-Mailer: git-send-email 2.43.0.381.gb435a96ce8 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] aacdec_usac: respect tns_on_lr flag 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: , X-Patchwork-Original-From: Lynne via ffmpeg-devel From: Lynne Reply-To: FFmpeg development discussions and patches Cc: Lynne Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: iC6yKr4nDWGz This was left out, and due to av_unused, forgotten about. --- libavcodec/aac/aacdec.h | 1 + libavcodec/aac/aacdec_usac.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h index ee21a94007..f0a33e7ac3 100644 --- a/libavcodec/aac/aacdec.h +++ b/libavcodec/aac/aacdec.h @@ -230,6 +230,7 @@ typedef struct SingleChannelElement { typedef struct AACUsacStereo { uint8_t common_window; uint8_t common_tw; + uint8_t tns_on_lr; ///< Apply TNS before M/S and stereo prediction uint8_t ms_mask_mode; uint8_t config_idx; diff --git a/libavcodec/aac/aacdec_usac.c b/libavcodec/aac/aacdec_usac.c index 561734f930..3b4e980df4 100644 --- a/libavcodec/aac/aacdec_usac.c +++ b/libavcodec/aac/aacdec_usac.c @@ -876,14 +876,14 @@ static int decode_usac_stereo_info(AACDecContext *ac, AACUSACConfig *usac, return AVERROR_PATCHWELCOME; } + us->tns_on_lr = 0; sce1->tns.present = sce2->tns.present = 0; if (tns_active) { - av_unused int tns_on_lr; int common_tns = 0; if (us->common_window) common_tns = get_bits1(gb); - tns_on_lr = get_bits1(gb); + us->tns_on_lr = get_bits1(gb); if (common_tns) { ret = ff_aac_decode_tns(ac, &sce1->tns, gb, ics1); if (ret < 0) @@ -1214,6 +1214,14 @@ static void spectrum_decode(AACDecContext *ac, AACUSACConfig *usac, } if (nb_channels > 1 && us->common_window) { + for (int ch = 0; ch < nb_channels; ch++) { + SingleChannelElement *sce = &cpe->ch[ch]; + + /* Apply TNS, if the tns_on_lr bit is not set. */ + if (sce->tns.present && !us->tns_on_lr) + ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1); + } + if (us->ms_mask_mode == 3) { const float *filt; complex_stereo_downmix_cur(ac, cpe, us->dmix_re); @@ -1248,8 +1256,8 @@ static void spectrum_decode(AACDecContext *ac, AACUSACConfig *usac, for (int ch = 0; ch < nb_channels; ch++) { SingleChannelElement *sce = &cpe->ch[ch]; - /* Apply TNS */ - if (sce->tns.present) + /* Apply TNS, if it hasn't been applied yet. */ + if (sce->tns.present && ((nb_channels == 1) || (us->tns_on_lr))) ac->dsp.apply_tns(sce->coeffs, &sce->tns, &sce->ics, 1); ac->oc[1].m4ac.frame_length_short ? ac->dsp.imdct_and_windowing_768(ac, sce) :