shithub: opus

Download patch

ref: b7bd4c20acfd951ba46647e07411285997d952f4
parent: 359306985b69086e260bb4cc9b053ba00f3125d1
author: Jean-Marc Valin <[email protected]>
date: Sat May 18 19:33:48 EDT 2013

celt_maxabs16() now returns an opus_val32 to avoid problems with -32768

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -106,7 +106,7 @@
    opus_int32 vbr_drift;
    opus_int32 vbr_offset;
    opus_int32 vbr_count;
-   opus_val16 overlap_max;
+   opus_val32 overlap_max;
    opus_val16 stereo_saving;
    int intensity;
    opus_val16 *energy_save;
@@ -1158,7 +1158,7 @@
    opus_val16 tf_estimate;
    int pitch_change=0;
    opus_int32 tot_boost;
-   opus_val16 sample_max;
+   opus_val32 sample_max;
    opus_val16 maxDepth;
    const OpusCustomMode *mode;
    int nbEBands;
@@ -1289,9 +1289,9 @@
 
    ALLOC(in, CC*(N+st->overlap), celt_sig);
 
-   sample_max=MAX16(st->overlap_max, celt_maxabs16(pcm, C*(N-overlap)/st->upsample));
+   sample_max=MAX32(st->overlap_max, celt_maxabs16(pcm, C*(N-overlap)/st->upsample));
    st->overlap_max=celt_maxabs16(pcm+C*(N-overlap)/st->upsample, C*overlap/st->upsample);
-   sample_max=MAX16(sample_max, st->overlap_max);
+   sample_max=MAX32(sample_max, st->overlap_max);
 #ifdef FIXED_POINT
    silence = (sample_max==0);
 #else
--- a/celt/fixed_c5x.h
+++ b/celt/fixed_c5x.h
@@ -73,7 +73,7 @@
 #define celt_ilog2(x) (30 - _lnorm(x))
 #define OVERRIDE_CELT_ILOG2
 
-#define celt_maxabs16(x, len) MAX16(maxval((DATA *)x, len),-minval((DATA *)x, len))
+#define celt_maxabs16(x, len) MAX32(EXTEND32(maxval((DATA *)x, len)),-EXTEND32(minval((DATA *)x, len)))
 #define OVERRIDE_CELT_MAXABS16
 
 #endif /* FIXED_C5X_H */
--- a/celt/fixed_c6x.h
+++ b/celt/fixed_c6x.h
@@ -64,7 +64,7 @@
 #undef MULT16_16_Q15
 #define MULT16_16_Q15(a,b) (_smpy(a,b))
 
-#define celt_maxabs16(x, len) MAX16(maxval((DATA *)x, len),-minval((DATA *)x, len))
+#define celt_maxabs16(x, len) MAX32(EXTEND32(maxval((DATA *)x, len)),-EXTEND32(minval((DATA *)x, len)))
 #define OVERRIDE_CELT_MAXABS16
 
 #endif /* FIXED_C6X_H */
--- a/celt/mathops.h
+++ b/celt/mathops.h
@@ -44,7 +44,7 @@
 unsigned isqrt32(opus_uint32 _val);
 
 #ifndef OVERRIDE_CELT_MAXABS16
-static inline opus_val16 celt_maxabs16(const opus_val16 *x, int len)
+static inline opus_val32 celt_maxabs16(const opus_val16 *x, int len)
 {
    int i;
    opus_val16 maxval = 0;
@@ -54,7 +54,7 @@
       maxval = MAX16(maxval, x[i]);
       minval = MIN16(minval, x[i]);
    }
-   return MAX16(maxval,-minval);
+   return MAX32(EXTEND32(maxval),-EXTEND32(minval));
 }
 #endif
 
--- a/celt/pitch.c
+++ b/celt/pitch.c
@@ -180,7 +180,7 @@
    VARDECL(opus_val32, xcorr);
 #ifdef FIXED_POINT
    opus_val32 maxcorr=1;
-   opus_val16 xmax, ymax;
+   opus_val32 xmax, ymax;
    int shift=0;
 #endif
    int offset;
@@ -204,7 +204,7 @@
 #ifdef FIXED_POINT
    xmax = celt_maxabs16(x_lp4, len>>2);
    ymax = celt_maxabs16(y_lp4, lag>>2);
-   shift = celt_ilog2(MAX16(1, MAX16(xmax, ymax)))-11;
+   shift = celt_ilog2(MAX32(1, MAX32(xmax, ymax)))-11;
    if (shift>0)
    {
       for (j=0;j<len>>2;j++)