From patchwork Wed Jan 8 07:32:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ted Lee X-Patchwork-Id: 17249 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3279044BAB2 for ; Wed, 8 Jan 2020 09:40:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F1F5F689B6C; Wed, 8 Jan 2020 09:40:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 07B3B68834B for ; Wed, 8 Jan 2020 09:40:03 +0200 (EET) Received: by mail-wm1-f42.google.com with SMTP id p17so1378808wma.1 for ; Tue, 07 Jan 2020 23:40:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaudiolab.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=hL8kiHMppkgwuSWfGNGtx1RHx9zUqLSFADs2yEzz7mk=; b=S5WkyM5F1jDyzD5b77nFNKX3svhZVKVtvMYBN0b2SvO/UJHAKy6TlsVJjzLZANRsYZ jBoF7CxqF6AO4s0E19Xt2/arTRKQqpqCkCUSwt507acPvhUVme88W33av6wb26PEWDWv gu0stEybsR0m+Amv+YhNlPRq6LQfbpngOa8ug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=hL8kiHMppkgwuSWfGNGtx1RHx9zUqLSFADs2yEzz7mk=; b=PtXbhlm/FpTFGS2ERSTt5JVTSxQMf5E/QTgiWO+bBwrxN6tTTUsBy0bsBNOt4iW6hw DkLVQmtcNg33cdHm3Rc7oHOn98NJqN/GPKZdvNeXXrrvQQAeNxxVoO8CGaYDRgegU11n ZUo/8g+Nf2ioGxleKdc30hmY4hEkISRkh1U6l+eGfhrw5ZFpDZYFpndibyaHEpB3R8Ub 5xknf5mfiVrj6CHJDLkuZ89t9Vxrm7cElB6EMdRX2jH0pttCxeCB7Rpa/466m3mX/Eaw +3hK4s/FIbhLwWZHlK7Koe4VPDDBWB2mDspVDgmcUXQmjA582LQUMwcV3UFLL7s+59yT 1Deg== X-Gm-Message-State: APjAAAVcN67eHR0pVrPMYfOu/KELoiyDmiEGZabPHUleGP76kk4GSHAu AvHvNX3tQAJZR36IZhRjB2jVoyxlZAT3XpT0/cOpq22XAzA= X-Google-Smtp-Source: APXvYqyhHbbGJEZ/Yb0vTJFpeOeZE6IhrLri9l+MgZDn1MgnQA+cO+aBvXg7vArqIt3voUoAPBnJ19Kim+FmcJCvN54= X-Received: by 2002:a05:600c:230d:: with SMTP id 13mr2124142wmo.13.1578468770571; Tue, 07 Jan 2020 23:32:50 -0800 (PST) MIME-Version: 1.0 From: Ted Lee Date: Wed, 8 Jan 2020 16:32:39 +0900 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] avfilter/mpegaudiodec_template: Fix wrong decision of illegal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Dear FFmpeg developers, I'm glad to have a chance to contribute to FFmpeg. Since this is the first time for me, please give feedback if I missed something. I will reflect on that. *Summary:* - Test signal: 790_pomnyun_taebaek2.mp3 - MP3 file with the same left channel and right channel except for the first 7 seconds and the last 10 seconds. (download: https://www.dropbox.com/s/sivz18sixvhoo66/790_pomnyun_taebaek2.mp3?dl=0 ) - When decoding the test signal using FFmpeg as below, a difference occurs in the same part of L and R. - $ffmpeg -i 790_pomnyun_taebaek2.mp3 -acodec pcm_s16le 790_pomnyun_taebaek2.wav Expected result (Adobe Audition or Core Audio): Decoded PCM [image: image.png] (L-R) [image: image.png] (You can reproduce it using Adobe Audition or CoreAudio of MacOS) Actual result (FFmpeg): Decoded PCM [image: image.png] (L-R) [image: image.png] *Why it happens?:* - In MPEG-1 Layer 3 (MP3), the illegal position of intensity stereo is defined as the maximum value of scale factor. Since intensity stereo positions (scale factor of the right channel) are always allocated to 3 bits, intensity stereo positions are limited from 0 to 6 and 7 is treated as the illegal position. - In MPEG-2 LSF, the illegal position is also defined as the maximum value of scale factor, but the number of bits of the scale factor is not fixed. So the number of bits needs to be calculated (slen[]) and the illegal stereo position should be changed as the maximum value. However, in the current implementation, the illegal position is defined as fixed value 16. *How to fix this?:* - The maximum value of scale factor (the illegal position) should be store to sf_max_table[] and an illegal position is determined when the scale factor is sf_max_table[](sf_max). From 754545f6c675aede07abd912992f9ed4a17d4ddc Mon Sep 17 00:00:00 2001 From: Ted Date: Wed, 8 Jan 2020 11:53:56 +0900 Subject: [PATCH] avfilter/mpegaudiodec_template: Fix wrong decision of illegal intensity stereo position for MPEG-2 LSF Signed-off-by: Ted --- libavcodec/mpegaudiodec_template.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) tab0 = g0->sb_hybrid + 576; @@ -1077,6 +1077,8 @@ static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1) } } sf = g1->scale_factors[k + l]; + if (s->lsf) + sf_max = sf_max_table[k + 1]; if (sf >= sf_max) goto found1; @@ -1122,6 +1124,8 @@ found1: /* for last band, use previous scale factor */ k = (i == 21) ? 20 : i; sf = g1->scale_factors[k]; + if (s->lsf) + sf_max = sf_max_table[k + 1]; if (sf >= sf_max) goto found2; v1 = is_tab[0][sf]; @@ -1523,11 +1527,15 @@ static int mp_decode_layer3(MPADecodeContext *s) n = lsf_nsf_table[tindex2][tindex][k]; sl = slen[k]; if (sl) { - for (i = 0; i < n; i++) + for (i = 0; i < n; i++) { + sf_max_table[j] = (uint8_t) exp2(sl) - 1; g->scale_factors[j++] = get_bits(&s->gb, sl); + } } else { - for (i = 0; i < n; i++) + for (i = 0; i < n; i++) { + sf_max_table[j] = 0; g->scale_factors[j++] = 0; + } } } /* XXX: should compute exact size */ diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c index 3f1674e827..d6d7cd5ad0 100644 --- a/libavcodec/mpegaudiodec_template.c +++ b/libavcodec/mpegaudiodec_template.c @@ -115,6 +115,7 @@ static uint16_t band_index_long[9][23]; static INTFLOAT is_table[2][16]; static INTFLOAT is_table_lsf[2][2][16]; static INTFLOAT csa_table[8][4]; +static uint8_t sf_max_table[40]; static int16_t division_tab3[1<<6 ]; static int16_t division_tab5[1<<8 ]; @@ -1050,7 +1051,6 @@ static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1) sf_max = 7; } else { is_tab = is_table_lsf[g1->scalefac_compress & 1]; - sf_max = 16; }