From b7bd4c20acfd951ba46647e07411285997d952f4 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin <jmvalin@jmvalin.ca> Date: Sat, 18 May 2013 23:33:48 -0400 Subject: [PATCH] celt_maxabs16() now returns an opus_val32 to avoid problems with -32768 --- celt/celt_encoder.c | 8 ++++---- celt/fixed_c5x.h | 2 +- celt/fixed_c6x.h | 2 +- celt/mathops.h | 4 ++-- celt/pitch.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/celt/celt_encoder.c b/celt/celt_encoder.c index 41bbe88f1..26e6ebbc4 100644 --- a/celt/celt_encoder.c +++ b/celt/celt_encoder.c @@ -106,7 +106,7 @@ struct OpusCustomEncoder { 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 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, 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 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, 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 diff --git a/celt/fixed_c5x.h b/celt/fixed_c5x.h index f0c4291ba..156ba45d0 100644 --- a/celt/fixed_c5x.h +++ b/celt/fixed_c5x.h @@ -73,7 +73,7 @@ static inline long IMUL32(long i, long j) #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 */ diff --git a/celt/fixed_c6x.h b/celt/fixed_c6x.h index fae92fd03..bb6ad9278 100644 --- 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 */ diff --git a/celt/mathops.h b/celt/mathops.h index cb0b9c86e..18a66be16 100644 --- 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 @@ static inline opus_val16 celt_maxabs16(const opus_val16 *x, int len) maxval = MAX16(maxval, x[i]); minval = MIN16(minval, x[i]); } - return MAX16(maxval,-minval); + return MAX32(EXTEND32(maxval),-EXTEND32(minval)); } #endif diff --git a/celt/pitch.c b/celt/pitch.c index c5b70e590..26f961700 100644 --- a/celt/pitch.c +++ b/celt/pitch.c @@ -180,7 +180,7 @@ void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR 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 @@ void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR #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++) -- GitLab