summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2016-02-11 19:47:04 +0100
committerWim Taymans <wtaymans@redhat.com>2016-02-11 19:54:11 +0100
commite1f5ecb963e6bd761707903a1f1f24eac09d9f15 (patch)
tree3f2b1189b390b854bcfe7d577f9bdb979111350e
parent01c994b48d9e51a70c30f710107923ffa33b1631 (diff)
downloadgstreamer-plugins-base-e1f5ecb963e6bd761707903a1f1f24eac09d9f15.tar.gz
resample: avoid overflows
Avoid overflow in rate calculation. This can cause the resampler to start on the wrong phase after a rate change. Avoid overflow in cubic fraction calculation. This can cause noise when dealing with higher samplerates.
-rw-r--r--gst/audioresample/resample.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/gst/audioresample/resample.c b/gst/audioresample/resample.c
index c9b1825d3..c37553590 100644
--- a/gst/audioresample/resample.c
+++ b/gst/audioresample/resample.c
@@ -598,8 +598,8 @@ resampler_basic_interpolate_single (SpeexResamplerState * st,
const int offset = samp_frac_num * st->oversample / st->den_rate;
#ifdef FIXED_POINT
const spx_word16_t frac =
- PDIV32 (SHL32 ((samp_frac_num * st->oversample) % st->den_rate, 15),
- st->den_rate);
+ ((((gint64) samp_frac_num * (gint64) st->oversample) % st->den_rate)
+ << 15) / st->den_rate;
#else
const spx_word16_t frac =
((float) ((samp_frac_num * st->oversample) % st->den_rate)) /
@@ -1386,7 +1386,8 @@ speex_resampler_set_rate_frac (SpeexResamplerState * st, spx_uint32_t ratio_num,
if (old_den > 0) {
for (i = 0; i < st->nb_channels; i++) {
- st->samp_frac_num[i] = st->samp_frac_num[i] * st->den_rate / old_den;
+ st->samp_frac_num[i] =
+ (gint64) st->samp_frac_num[i] * (gint64) st->den_rate / old_den;
/* Safety net */
if (st->samp_frac_num[i] >= st->den_rate)
st->samp_frac_num[i] = st->den_rate - 1;