[Speex-dev] bug fix for speex_resampler_reset_mem?
victor
victor at speech.sri.com
Wed Nov 10 13:23:51 PST 2010
I'm using resample.c from speex in my project, and was testing it by
processing the same waveform twice, with a reset() call in the middle,
as follows:
short *input_data = read_waveform_as_linear(infileName, &rate,
&num_samples, &num_channels);
SpeexResamplerState *state = speex_resampler_init_frac(num_channels,
in_rate, out_rate, in_rate, out_rate, quality, &error);
speex_resampler_skip_zeros(state);
speex_resampler_process_int(state, 0, input_data, ...)
write_waveform(...)
speex_resampler_reset_mem(m_resampler_state);
speex_resampler_skip_zeros(m_resampler_state);
speex_resampler_process_int(state, 0, input_data, ...)
write_waveform(...)
speex_resampler_destroy(state);
When I run it this way, my two output waveforms are not identical on a
binary basis.
Changing speex_resampler_reset_mem() as follows seems to fix the problem:
EXPORT int speex_resampler_reset_mem(SpeexResamplerState *st)
{
spx_uint32_t i;
for (i=0;i<st->nb_channels*(st->filt_len-1);i++)
st->mem[i] = 0;
// added bugfix below:
st->started = 0;
for (i=0;i<st->nb_channels;i++)
{
st->last_sample[i] = 0;
st->magic_samples[i] = 0;
st->samp_frac_num[i] = 0;
}
return RESAMPLER_ERR_SUCCESS;
}
Note that I have to call speex_resampler_skip_zeros() again after each
reset call, whether or not I zero st->last_sample[i] or not.
Also, I'm not 100% sure whether resetting st->started = 0 is strictly
necessary or not.
Thanks for a great addition to open source software,
Victor Abrash
More information about the Speex-dev
mailing list