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

This commit is contained in:
Jean-Marc Valin 2013-05-18 23:33:48 -04:00
parent 359306985b
commit b7bd4c20ac
5 changed files with 10 additions and 10 deletions

View file

@ -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

View file

@ -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 */

View file

@ -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 */

View file

@ -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

View file

@ -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++)