From patchwork Wed Sep 28 18:58:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38453 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp444210pzh; Wed, 28 Sep 2022 11:58:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Lre+g7tSv1e+WSRv8gg08Y3eNF1jY8wxCfpIKVfzgv1BupG1Kzfo5m4e8P2FnltY39AnE X-Received: by 2002:a05:6402:1f84:b0:455:27b8:27aa with SMTP id c4-20020a0564021f8400b0045527b827aamr33426706edc.243.1664391511014; Wed, 28 Sep 2022 11:58:31 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n22-20020a170906725600b007824cd8d165si4882063ejk.577.2022.09.28.11.58.30; Wed, 28 Sep 2022 11:58:31 -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=@outlook.com header.s=selector1 header.b=CMIFhrua; arc=fail (body hash mismatch); 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=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA9D868BBCA; Wed, 28 Sep 2022 21:58:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2096.outbound.protection.outlook.com [40.92.91.96]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CEA3268BBC0 for ; Wed, 28 Sep 2022 21:58:21 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rd7g7s8IASGcpb8BP3gKofzXi6zEL9N4dTk1F+3e3pAuazgNzNVGf7wHha01q1yMbiFU1bOlb2Qd0my8Nlgf3pMPaylPZCu1g4n8WLXe1uVZtS7VpIx9HK8nOUnB3YRIG/GA3HnWYlJCaRRt2c0ApMfsNVdQDkN4pRtgBc0uPmQFqJGtnD1SYZakuspakfOD4KbdWP7CH5vRCQRHv25S2u10uaRa+rDjuZG1yhaaIYoGblCuKW7tGtZ0J+SxybLThty4b23Hy0IXbYNvlKS+8aLQkjrGlUVkBcpv0e/SJLEEJFo2jr/Jq563pXk1LT8g6LyboL5Z7t2KGMQHL1QfzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yYMBpA12A6PG7TCC30humVcSNjTSJBzttwgUZ0lVmdQ=; b=KE9Fe+wTAUE7uYQ+d4KSA9Laqo3o0ccvXTm4tgDyIVoml9G1/Dde0W0idIgUcQR36ZQ2hez22oU5vUVgHufgMFzGxWJKII1b4I5Y1/PX8/DcxZYkS5OGZglP1FiVb1r4OL5DpEiEhJYbDE8De8qWX6UmEiMxRSnx6AALAsq9Fq7rv0BLFjqgmG8qjeydJRV2IUOMW00X7fvMVe/yB5RIZ3/etgNQn5iIqfDPHuRblRObj2rqHaGvorHGtZS5/HIts5tjQdtaAe9JGUKpZPTRomoYXl9Fid2pOqbza0Qqt+UKo2EBMRXanZkX0gn1UR8jajN3wB6tZHcSp5CdpnxuvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yYMBpA12A6PG7TCC30humVcSNjTSJBzttwgUZ0lVmdQ=; b=CMIFhrua/TsoBnVIiuU8j77en9HHJsRirfsT4/ZLekzs5gv8jHCRT2xkvub++ibhXqF7yyC66VG7mU0XGIag4NS1vrW23GTk7r48CgxuvVwwFjSJY3WRwbMjIAzA1551V4zSqzolXaYEovNLuutkOGlG0qedxtRhaFkuB/pDtUTQ8O9UV5ST79dCt6Nh4xqXprCiLODdJ/vAxMM50deVFzl0pS03Kbd+F26R3wSGf0YbTt5j4Ej9hbc23SHRVvlORRxNGLcyiR+2l8OJQ7aAXIfIrnIRF5C8d7YBSDvBnXYH8smeApBQam4IIfV00Nur2Ox+fc3pqs6YD447czrZlg== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0014.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:2b7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Wed, 28 Sep 2022 18:58:19 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5654.025; Wed, 28 Sep 2022 18:58:19 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 20:58:14 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [F2NTc4JPsz2GuaHYdR876Q9CdKF+Mv9wmD2SCBfxdiw=] X-ClientProxiedBy: FR0P281CA0051.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::12) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220928185818.1074689-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0014:EE_ X-MS-Office365-Filtering-Correlation-Id: d0a2f1e3-82c9-4eca-1049-08daa1836861 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpPcoZqFl/i/jhf7c/pX34TY967m/IjD11CuwgsfHovdSLLdyQfxy4uC3SN07XZJWsryHv+053Jnxm8R8I4ZCiL3ECNuzcWsHyyTAEaphJmlAjBuFoH/8tXtOWL73y2HpPEkuVChYYPnNJjfcRjnLYBOryiHhXPPZNglKfKtVmi0g/ZzRViRE6gKSlGgll32yRWTlW8wKu8ZXhzfJCdNdlRsJiweNqJRkvaed1bSW3TLBn8toEgyUdt9cEOtx9h1dn3RxE5WZXwSotpZE8hEnsadUDoQ8k9J+WjzlgEDsDh31M87ikyrvjjCeQegKyew2pavHjHKtMNTphJvhJK8ZTSjbyAtVEarhejSqsRLsA4GkPzefxi1xJHeDCZjloLTVeW1N9kVUiNS3mMD1bcVx8WM3VT+kg/ZoS9dfa8mp77DbIvHk7mzC/tKedzO2dv+pY6w7VnD5ibDkU56Va0bgx9lCBQ46XRpjA8+/1pqZOievwZwXgmwxz+B6syWF4jZ48cTAXS2MB6gOpuiF9ywTgrEklaA0Rvyqjba4yFAKkB7XoxHCMzzOUcrl0HtxJ+jLGKLzSqf8vVg2Yow+mFv6fbdTTPhBV/oQxedQ/ViH1DI8MM1STFiQt91vT568l0Ro+tdL+m5m91lET8urTu+9Zpan73QNHHjNZjlsGZuyPlANYAdyfVvHITm8UDdy6Fc70SSWUpS5E6xVCxitWE35H8Bqu4r2kZksceVdnVTbK5xEBpZjbchxFBvV77AexbGw0= X-Microsoft-Antispam: BCL:0; X-Microsoft-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-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2022 18:58:19.2045 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2P250MB0014 Subject: [FFmpeg-devel] [PATCH 2/6] avcodec/g723_1enc: Fix undefined left-shifts of negative numbers 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: damtCJ2m2miw Affected the acodec-g723_1 FATE-test. Signed-off-by: Andreas Rheinhardt --- libavcodec/g723_1enc.c | 71 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c index a22985ca44..8466067185 100644 --- a/libavcodec/g723_1enc.c +++ b/libavcodec/g723_1enc.c @@ -126,7 +126,7 @@ static void highpass_filter(int16_t *buf, int16_t *fir, int *iir) { int i; for (i = 0; i < FRAME_LEN; i++) { - *iir = (buf[i] << 15) + ((-*fir) << 15) + MULL2(*iir, 0x7f00); + *iir = (buf[i] - *fir) * (1 << 15) + MULL2(*iir, 0x7f00); *fir = buf[i]; buf[i] = av_clipl_int32((int64_t)*iir + (1 << 15)) >> 16; } @@ -166,7 +166,7 @@ static void comp_autocorr(int16_t *buf, int16_t *autocorr) } else { for (i = 1; i <= LPC_ORDER; i++) { temp = ff_dot_product(vector, vector + i, LPC_FRAME - i); - temp = MULL2((temp << scale), binomial_window[i - 1]); + temp = MULL2(temp * (1 << scale), binomial_window[i - 1]); autocorr[i] = av_clipl_int32((int64_t) temp + (1 << 15)) >> 16; } } @@ -193,7 +193,7 @@ static void levinson_durbin(int16_t *lpc, int16_t *autocorr, int16_t error) temp = 0; for (j = 0; j < i; j++) temp -= lpc[j] * autocorr[i - j - 1]; - temp = ((autocorr[i] << 13) + temp) << 3; + temp = (autocorr[i] * (1 << 13) + temp) * (1 << 3); if (FFABS(temp) >= (error << 16)) break; @@ -209,8 +209,8 @@ static void levinson_durbin(int16_t *lpc, int16_t *autocorr, int16_t error) memcpy(vector, lpc, i * sizeof(int16_t)); for (j = 0; j < i; j++) { - temp = partial_corr * vector[i - j - 1] << 1; - lpc[j] = av_clipl_int32((int64_t) (lpc[j] << 16) - temp + + temp = partial_corr * vector[i - j - 1] * 2; + lpc[j] = av_clipl_int32((int64_t) (lpc[j] * (1 << 16)) - temp + (1 << 15)) >> 16; } } @@ -259,9 +259,9 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp) /* Compute the remaining coefficients */ for (i = 0; i < LPC_ORDER / 2; i++) { /* f1 */ - f[2 * i + 2] = -f[2 * i] - ((lsp[i] + lsp[LPC_ORDER - 1 - i]) << 12); + f[2 * i + 2] = -f[2 * i] - (lsp[i] + lsp[LPC_ORDER - 1 - i]) * (1 << 12); /* f2 */ - f[2 * i + 3] = f[2 * i + 1] - ((lsp[i] - lsp[LPC_ORDER - 1 - i]) << 12); + f[2 * i + 3] = f[2 * i + 1] - (lsp[i] - lsp[LPC_ORDER - 1 - i]) * (1 << 12); } /* Divide f1[5] and f2[5] by 2 for use in polynomial evaluation */ @@ -276,7 +276,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp) shift = ff_g723_1_normalize_bits(max, 31); for (i = 0; i < LPC_ORDER + 2; i++) - f[i] = av_clipl_int32((int64_t) (f[i] << shift) + (1 << 15)) >> 16; + f[i] = av_clipl_int32((int64_t) (f[i] * (1 << shift)) + (1 << 15)) >> 16; /** * Evaluate F1 and F2 at uniform intervals of pi/256 along the @@ -293,7 +293,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp) temp = 0; for (j = 0; j <= LPC_ORDER / 2; j++) temp += f[LPC_ORDER - 2 * j + p] * ff_g723_1_cos_tab[i * j % COS_TBL_SIZE]; - cur_val = av_clipl_int32(temp << 1); + cur_val = av_clipl_int32(temp * 2); /* Check for sign change, indicating a zero crossing */ if ((cur_val ^ prev_val) < 0) { @@ -317,7 +317,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp) for (j = 0; j <= LPC_ORDER / 2; j++) temp += f[LPC_ORDER - 2 * j + p] * ff_g723_1_cos_tab[i * j % COS_TBL_SIZE]; - cur_val = av_clipl_int32(temp << 1); + cur_val = av_clipl_int32(temp * 2); } prev_val = cur_val; } @@ -344,7 +344,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp) temp[j] = (weight[j + (offset)] * ff_g723_1_lsp_band##num[i][j] + \ (1 << 14)) >> 15; \ } \ - error = ff_g723_1_dot_product(lsp + (offset), temp, size) << 1; \ + error = ff_g723_1_dot_product(lsp + (offset), temp, size) * 2; \ error -= ff_g723_1_dot_product(ff_g723_1_lsp_band##num[i], temp, size); \ if (error > max) { \ max = error; \ @@ -419,7 +419,7 @@ static void iir_filter(int16_t *fir_coef, int16_t *iir_coef, iir_coef[n - 1] * dest[m - n]; } - dest[m] = av_clipl_int32((src[m] << 16) + (filter << 3) + + dest[m] = av_clipl_int32(src[m] * (1 << 16) + filter * (1 << 3) + (1 << 15)) >> 16; } } @@ -559,7 +559,7 @@ static void comp_harmonic_coeff(int16_t *buf, int16_t pitch_lag, HFParam *hf) exp = ff_g723_1_normalize_bits(max, 31); for (i = 0; i < 15; i++) { - energy[i] = av_clipl_int32((int64_t)(energy[i] << exp) + + energy[i] = av_clipl_int32((int64_t)(energy[i] * (1 << exp)) + (1 << 15)) >> 16; } @@ -613,8 +613,8 @@ static void harmonic_filter(HFParam *hf, const int16_t *src, int16_t *dest) int i; for (i = 0; i < SUBFRAME_LEN; i++) { - int64_t temp = hf->gain * src[i - hf->index] << 1; - dest[i] = av_clipl_int32((src[i] << 16) - temp + (1 << 15)) >> 16; + int64_t temp = hf->gain * src[i - hf->index] * 2; + dest[i] = av_clipl_int32(src[i] * (1 << 16) - temp + (1 << 15)) >> 16; } } @@ -622,8 +622,8 @@ static void harmonic_noise_sub(HFParam *hf, const int16_t *src, int16_t *dest) { int i; for (i = 0; i < SUBFRAME_LEN; i++) { - int64_t temp = hf->gain * src[i - hf->index] << 1; - dest[i] = av_clipl_int32(((dest[i] - src[i]) << 16) + temp + + int64_t temp = hf->gain * src[i - hf->index] * 2; + dest[i] = av_clipl_int32((dest[i] - src[i]) * (1 << 16) + temp + (1 << 15)) >> 16; } } @@ -655,7 +655,7 @@ static void synth_percept_filter(int16_t *qnt_lpc, int16_t *perf_lpc, for (j = 1; j <= LPC_ORDER; j++) temp -= qnt_lpc[j - 1] * bptr_16[i - j]; - buf[i] = (src[i] << 15) + (temp << 3); + buf[i] = src[i] * (1 << 15) + temp * (1 << 3); bptr_16[i] = av_clipl_int32(buf[i] + (1 << 15)) >> 16; } @@ -665,7 +665,7 @@ static void synth_percept_filter(int16_t *qnt_lpc, int16_t *perf_lpc, fir -= perf_lpc[j - 1] * bptr_16[i - j]; iir += perf_lpc[j + LPC_ORDER - 1] * dest[i - j]; } - dest[i] = av_clipl_int32(((buf[i] + (fir << 3)) << scale) + (iir << 3) + + dest[i] = av_clipl_int32((buf[i] + fir * (1 << 3)) * (1 << scale) + iir * (1 << 3) + (1 << 15)) >> 16; } memcpy(perf_fir, buf_16 + SUBFRAME_LEN, sizeof(int16_t) * LPC_ORDER); @@ -714,23 +714,22 @@ static void acb_search(G723_1_ChannelContext *p, int16_t *residual, temp = 0; for (k = 0; k <= j; k++) temp += residual[PITCH_ORDER - 1 + k] * impulse_resp[j - k]; - flt_buf[PITCH_ORDER - 1][j] = av_clipl_int32((temp << 1) + - (1 << 15)) >> 16; + flt_buf[PITCH_ORDER - 1][j] = av_clipl_int32(temp * 2 + (1 << 15)) >> 16; } for (j = PITCH_ORDER - 2; j >= 0; j--) { - flt_buf[j][0] = ((residual[j] << 13) + (1 << 14)) >> 15; + flt_buf[j][0] = (residual[j] + (1 << 1)) >> 2; for (k = 1; k < SUBFRAME_LEN; k++) { - temp = (flt_buf[j + 1][k - 1] << 15) + + temp = flt_buf[j + 1][k - 1] * (1 << 15) + residual[j] * impulse_resp[k]; - flt_buf[j][k] = av_clipl_int32((temp << 1) + (1 << 15)) >> 16; + flt_buf[j][k] = av_clipl_int32(temp * 2 + (1 << 15)) >> 16; } } /* Compute crosscorrelation with the signal */ for (j = 0; j < PITCH_ORDER; j++) { temp = ff_dot_product(buf, flt_buf[j], SUBFRAME_LEN); - ccr_buf[count++] = av_clipl_int32(temp << 1); + ccr_buf[count++] = av_clipl_int32(temp * 2); } /* Compute energies */ @@ -742,7 +741,7 @@ static void acb_search(G723_1_ChannelContext *p, int16_t *residual, for (j = 1; j < PITCH_ORDER; j++) { for (k = 0; k < j; k++) { temp = ff_dot_product(flt_buf[j], flt_buf[k], SUBFRAME_LEN); - ccr_buf[count++] = av_clipl_int32(temp << 2); + ccr_buf[count++] = av_clipl_int32(temp * (1 << 2)); } } } @@ -755,7 +754,7 @@ static void acb_search(G723_1_ChannelContext *p, int16_t *residual, temp = ff_g723_1_normalize_bits(max, 31); for (i = 0; i < 20 * iter; i++) - ccr_buf[i] = av_clipl_int32((int64_t) (ccr_buf[i] << temp) + + ccr_buf[i] = av_clipl_int32((int64_t) (ccr_buf[i] * (1 << temp)) + (1 << 15)) >> 16; max = 0; @@ -803,11 +802,11 @@ static void sub_acb_contrib(const int16_t *residual, const int16_t *impulse_resp int i, j; /* Subtract adaptive CB contribution to obtain the residual */ for (i = 0; i < SUBFRAME_LEN; i++) { - int64_t temp = buf[i] << 14; + int64_t temp = buf[i] * (1 << 14); for (j = 0; j <= i; j++) temp -= residual[j] * impulse_resp[i - j]; - buf[i] = av_clipl_int32((temp << 2) + (1 << 15)) >> 16; + buf[i] = av_clipl_int32(temp * (1 << 2) + (1 << 15)) >> 16; } } @@ -851,7 +850,7 @@ static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp, for (i = 1; i < SUBFRAME_LEN; i++) { temp = ff_g723_1_dot_product(temp_corr + i, temp_corr, SUBFRAME_LEN - i); - impulse_corr[i] = av_clipl_int32((temp << scale) + (1 << 15)) >> 16; + impulse_corr[i] = av_clipl_int32(temp * (1 << scale) + (1 << 15)) >> 16; } /* Compute crosscorrelation of impulse response with residual signal */ @@ -861,7 +860,7 @@ static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp, if (scale < 0) ccr1[i] = temp >> -scale; else - ccr1[i] = av_clipl_int32(temp << scale); + ccr1[i] = av_clipl_int32(temp * (1 << scale)); } /* Search loop */ @@ -910,7 +909,7 @@ static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp, continue; temp = impulse_corr[FFABS(l - param.pulse_pos[k - 1])]; temp = av_clipl_int32((int64_t) temp * - param.pulse_sign[k - 1] << 1); + param.pulse_sign[k - 1] * 2); ccr2[l] -= temp; temp = FFABS(ccr2[l]); if (temp > max) { @@ -934,17 +933,17 @@ static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp, temp = 0; for (l = 0; l <= k; l++) { int prod = av_clipl_int32((int64_t) temp_corr[l] * - impulse_r[k - l] << 1); + impulse_r[k - l] * 2); temp = av_clipl_int32(temp + prod); } - temp_corr[k] = temp << 2 >> 16; + temp_corr[k] = temp >> 14; } /* Compute square of error */ err = 0; for (k = 0; k < SUBFRAME_LEN; k++) { int64_t prod; - prod = av_clipl_int32((int64_t) buf[k] * temp_corr[k] << 1); + prod = av_clipl_int32((int64_t) buf[k] * temp_corr[k] * 2); err = av_clipl_int32(err - prod); prod = av_clipl_int32((int64_t) temp_corr[k] * temp_corr[k]); err = av_clipl_int32(err + prod); @@ -1204,7 +1203,7 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, memmove(p->prev_excitation, p->prev_excitation + SUBFRAME_LEN, sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN)); for (j = 0; j < SUBFRAME_LEN; j++) - in[j] = av_clip_int16((in[j] << 1) + impulse_resp[j]); + in[j] = av_clip_int16(in[j] * 2 + impulse_resp[j]); memcpy(p->prev_excitation + PITCH_MAX - SUBFRAME_LEN, in, sizeof(int16_t) * SUBFRAME_LEN);