oku at iki.fi
2012-May-02 14:28 UTC
[Speex-dev] [PATCH] resample: Fix input indexing bug from interleaved functions
From: Jyri Sarha <jsarha at ti.com> This bug happens quite often when resampling from a low to a high sample-rate with big enough factor. Also the resampling call has to be limited by the output buffer size and some unused samples needs be left in the input buffer. Sometimes when up-sampling with a big factor the resampling function wants to peek one more sample from the input buffer to produce one more output sample, but the inputs sample is not consumed because it is also needed to produce the next output sample. When resampling the next channel this peeked sample is not any more available because *in_len parameter value was updated when resampling the first channel. Signed-off-by: Jyri Sarha <jsarha at ti.com> --- libspeex/resample.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libspeex/resample.c b/libspeex/resample.c index 7957c61..d59508d 100644 --- a/libspeex/resample.c +++ b/libspeex/resample.c @@ -970,13 +970,15 @@ EXPORT int speex_resampler_process_interleaved_float(SpeexResamplerState *st, co { spx_uint32_t i; int istride_save, ostride_save; - spx_uint32_t bak_len = *out_len; + spx_uint32_t bak_out_len = *out_len; + spx_uint32_t bak_in_len = *in_len; istride_save = st->in_stride; ostride_save = st->out_stride; st->in_stride = st->out_stride = st->nb_channels; for (i=0;i<st->nb_channels;i++) { - *out_len = bak_len; + *out_len = bak_out_len; + *in_len = bak_in_len; if (in != NULL) speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len); else @@ -991,13 +993,15 @@ EXPORT int speex_resampler_process_interleaved_int(SpeexResamplerState *st, cons { spx_uint32_t i; int istride_save, ostride_save; - spx_uint32_t bak_len = *out_len; + spx_uint32_t bak_out_len = *out_len; + spx_uint32_t bak_in_len = *in_len; istride_save = st->in_stride; ostride_save = st->out_stride; st->in_stride = st->out_stride = st->nb_channels; for (i=0;i<st->nb_channels;i++) { - *out_len = bak_len; + *out_len = bak_out_len; + *in_len = bak_in_len; if (in != NULL) speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len); else -- 1.7.4.1
Nikos Chantziaras
2013-Jan-14 02:37 UTC
[Speex-dev] [PATCH] resample: Fix input indexing bug from interleaved functions
On 02/05/12 17:28, oku at iki.fi wrote:> From: Jyri Sarha <jsarha at ti.com> > > This bug happens quite often when resampling from a low to a high > sample-rate with big enough factor. Also the resampling call has to > be limited by the output buffer size and some unused samples needs be > left in the input buffer. > > Sometimes when up-sampling with a big factor the resampling function > wants to peek one more sample from the input buffer to produce one > more output sample, but the inputs sample is not consumed because it > is also needed to produce the next output sample. When resampling the > next channel this peeked sample is not any more available because > *in_len parameter value was updated when resampling the first channel. > > Signed-off-by: Jyri Sarha <jsarha at ti.com>I was wondering what's causing the (very noticeable) glitches when I resample from 44100Hz to 96000Hz by using speex_resampler_process_interleaved_float(). I applied this patch and I now get clear audio at last! I see this patch is from May 2012. Any chance of applying it in current Git? It's quite a serious audio quality bug.