[FFmpeg-cvslog] g723.1: simplify and fix multiplication overflow

Mans Rullgard git at videolan.org
Fri Aug 10 16:31:45 CEST 2012


ffmpeg | branch: master | Mans Rullgard <mans at mansr.com> | Fri Aug 10 01:14:32 2012 +0100| [52aa3015a3c895cf74e555c4bb56c08cd067383e] | committer: Mans Rullgard

g723.1: simplify and fix multiplication overflow

In 16-bit arithmetic, x * 0xffffc is simply x * -4 with extra overflows,
(and the constant was probably meant to be 0xfffc).  Combined with the
shift, this simplifies to -x >> 1.  Finally, clearing the low two bits
with a 32-bit mask and switching to a 32-bit type allows more efficient
code on 32-bit machines.

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=52aa3015a3c895cf74e555c4bb56c08cd067383e
---

 libavcodec/g723_1.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c
index c337deb..53b9ade 100644
--- a/libavcodec/g723_1.c
+++ b/libavcodec/g723_1.c
@@ -956,7 +956,7 @@ static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf)
     signal_ptr = filter_signal + LPC_ORDER;
     for (i = 0; i < SUBFRAMES; i++) {
         int16_t temp_vector[SUBFRAME_LEN];
-        int16_t temp;
+        int temp;
         int auto_corr[2];
         int scale, energy;
 
@@ -975,7 +975,7 @@ static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf)
             temp = (auto_corr[0] >> 2) / temp;
         }
         p->reflection_coef = (3 * p->reflection_coef + temp + 2) >> 2;
-        temp = (p->reflection_coef * 0xffffc >> 3) & 0xfffc;
+        temp = -p->reflection_coef >> 1 & ~3;
 
         /* Compensation filter */
         for (j = 0; j < SUBFRAME_LEN; j++) {



More information about the ffmpeg-cvslog mailing list