[FFmpeg-devel] [PATCH 10/11] avcodec/truespeech: Fix invalid shifts

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Fri Sep 20 01:17:05 EEST 2019


Fixes the truespeech FATE-test as well as the truespeech bugs reported
in ticket #8159.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavcodec/truespeech.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index d4ddfcbf9c..f08f5f2680 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -133,7 +133,7 @@ static void truespeech_correlate_filter(TSContext *dec)
             memcpy(tmp, dec->cvector, i * sizeof(*tmp));
             for(j = 0; j < i; j++)
                 dec->cvector[j] = ((tmp[i - j - 1] * dec->vector[i]) +
-                                   (dec->cvector[j] << 15) + 0x4000) >> 15;
+                                   dec->cvector[j] * (1 << 15) + 0x4000) >> 15;
         }
         dec->cvector[i] = (8 - dec->vector[i]) >> 3;
     }
@@ -256,7 +256,7 @@ static void truespeech_synth(TSContext *dec, int16_t *out, int quart)
         int sum = 0;
         for(k = 0; k < 8; k++)
             sum += ptr0[k] * ptr1[k];
-        sum = (sum + (out[i] << 12) + 0x800) >> 12;
+        sum = (sum + out[i] * (1 << 12) + 0x800) >> 12;
         out[i] = av_clip(sum, -0x7FFE, 0x7FFE);
         for(k = 7; k > 0; k--)
             ptr0[k] = ptr0[k - 1];
@@ -274,7 +274,7 @@ static void truespeech_synth(TSContext *dec, int16_t *out, int quart)
         for(k = 7; k > 0; k--)
             ptr0[k] = ptr0[k - 1];
         ptr0[0] = out[i];
-        out[i] = ((out[i] << 12) - sum) >> 12;
+        out[i] = (out[i] * (1 << 12) - sum) >> 12;
     }
 
     for(i = 0; i < 8; i++)
@@ -282,7 +282,7 @@ static void truespeech_synth(TSContext *dec, int16_t *out, int quart)
 
     ptr0 = dec->tmp3;
     for(i = 0; i < 60; i++){
-        int sum = out[i] << 12;
+        int sum = out[i] * (1 << 12);
         for(k = 0; k < 8; k++)
             sum += ptr0[k] * t[k];
         for(k = 7; k > 0; k--)
-- 
2.20.1



More information about the ffmpeg-devel mailing list