diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-03-21 20:11:48 +0300 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-03-24 16:10:58 +0300 |
commit | be9e747bcc542c277d30f6c78a57b0940e0c5b5e (patch) | |
tree | 79158fc5841ac79b828672c0b63a0b1dba093220 | |
parent | 02f3ac225f99512364dc69e45e3a849f83b96363 (diff) |
Fixes overflows on CPUs with 16-bit ints
As reported by Giovanni Rovatti, this should fix some TI C55 issues.
-rw-r--r-- | celt/bands.c | 2 | ||||
-rw-r--r-- | celt/rate.c | 2 | ||||
-rw-r--r-- | src/opus_encoder.c | 8 |
3 files changed, 6 insertions, 6 deletions
diff --git a/celt/bands.c b/celt/bands.c index 25f229e2..22a0034b 100644 --- a/celt/bands.c +++ b/celt/bands.c @@ -714,7 +714,7 @@ static void compute_theta(struct band_ctx *ctx, struct split_ctx *sctx, if (qn!=1) { if (encode) - itheta = (itheta*qn+8192)>>14; + itheta = (itheta*(opus_int32)qn+8192)>>14; /* Entropy coding of the angle. We use a uniform pdf for the time split, a step for stereo, and a triangular one for the rest. */ diff --git a/celt/rate.c b/celt/rate.c index b28d8fec..7dfa5be8 100644 --- a/celt/rate.c +++ b/celt/rate.c @@ -296,7 +296,7 @@ static OPUS_INLINE int interp_bits2pulses(const CELTMode *m, int start, int end, done = 0; for (j=end;j-->start;) { - int tmp = bits1[j] + (lo*bits2[j]>>ALLOC_STEPS); + int tmp = bits1[j] + ((opus_int32)lo*bits2[j]>>ALLOC_STEPS); if (tmp < thresh[j] && !done) { if (tmp >= alloc_floor) diff --git a/src/opus_encoder.c b/src/opus_encoder.c index a7e19127..24d8f89a 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -871,7 +871,7 @@ opus_val16 compute_stereo_width(const opus_val16 *pcm, int frame_size, opus_int3 opus_val16 short_alpha; frame_rate = Fs/frame_size; - short_alpha = Q15ONE - 25*Q15ONE/IMAX(50,frame_rate); + short_alpha = Q15ONE - MULT16_16(25, Q15ONE)/IMAX(50,frame_rate); xx=xy=yy=0; for (i=0;i<frame_size;i+=4) { @@ -920,7 +920,7 @@ opus_val16 compute_stereo_width(const opus_val16 *pcm, int frame_size, opus_int3 mem->XY = MIN32(mem->XY, sqrt_xx*sqrt_yy); corr = SHR32(frac_div32(mem->XY,EPSILON+MULT16_16(sqrt_xx,sqrt_yy)),16); /* Approximate loudness difference */ - ldiff = Q15ONE*ABS16(qrrt_xx-qrrt_yy)/(EPSILON+qrrt_xx+qrrt_yy); + ldiff = MULT16_16(Q15ONE, ABS16(qrrt_xx-qrrt_yy))/(EPSILON+qrrt_xx+qrrt_yy); width = MULT16_16_Q15(celt_sqrt(QCONST32(1.f,30)-MULT16_16(corr,corr)), ldiff); /* Smoothing over one second */ mem->smoothed_width += (width-mem->smoothed_width)/frame_rate; @@ -932,7 +932,7 @@ opus_val16 compute_stereo_width(const opus_val16 *pcm, int frame_size, opus_int3 ldiff=0; } /*printf("%f %f %f %f %f ", corr/(float)Q15ONE, ldiff/(float)Q15ONE, width/(float)Q15ONE, mem->smoothed_width/(float)Q15ONE, mem->max_follower/(float)Q15ONE);*/ - return EXTRACT16(MIN32(Q15ONE,20*mem->max_follower)); + return EXTRACT16(MIN32(Q15ONE, MULT16_16(20, mem->max_follower))); } opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, @@ -1513,7 +1513,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ celt_rate = total_bitRate - st->silk_mode.bitRate; HB_gain_ref = (curr_bandwidth == OPUS_BANDWIDTH_SUPERWIDEBAND) ? 3000 : 3600; HB_gain = SHL32((opus_val32)celt_rate, 9) / SHR32((opus_val32)celt_rate + st->stream_channels * HB_gain_ref, 6); - HB_gain = HB_gain < Q15ONE*6/7 ? HB_gain + Q15ONE/7 : Q15ONE; + HB_gain = HB_gain < (opus_int32)Q15ONE*6/7 ? HB_gain + Q15ONE/7 : Q15ONE; } } else { /* SILK gets all bits */ |