michael@0: # HG changeset patch michael@0: # Parent 091c02c13c8ba50903248432d0c7561104dace21 michael@0: # User Karl Tomlinson michael@0: b=913854 add speex_resampler_set_skip_frac_num r=jmspeex michael@0: michael@0: This allows a client to align output samples consistently for independent michael@0: resampling of contiguous input buffers. michael@0: michael@0: diff --git a/layout/media/symbols.def.in b/layout/media/symbols.def.in michael@0: --- a/layout/media/symbols.def.in michael@0: +++ b/layout/media/symbols.def.in michael@0: @@ -122,16 +122,17 @@ speex_resampler_set_quality michael@0: speex_resampler_get_quality michael@0: speex_resampler_set_input_stride michael@0: speex_resampler_get_input_stride michael@0: speex_resampler_set_output_stride michael@0: speex_resampler_get_output_stride michael@0: speex_resampler_get_input_latency michael@0: speex_resampler_get_output_latency michael@0: speex_resampler_skip_zeros michael@0: +speex_resampler_set_skip_frac_num michael@0: speex_resampler_reset_mem michael@0: speex_resampler_strerror michael@0: cubeb_destroy michael@0: cubeb_init michael@0: cubeb_get_max_channel_count michael@0: cubeb_get_min_latency michael@0: cubeb_get_preferred_sample_rate michael@0: cubeb_stream_destroy michael@0: diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c michael@0: --- a/media/libspeex_resampler/src/resample.c michael@0: +++ b/media/libspeex_resampler/src/resample.c michael@0: @@ -1138,16 +1138,28 @@ SPX_RESAMPLE_EXPORT int speex_resampler_ michael@0: SPX_RESAMPLE_EXPORT int speex_resampler_skip_zeros(SpeexResamplerState *st) michael@0: { michael@0: spx_uint32_t i; michael@0: for (i=0;inb_channels;i++) michael@0: st->last_sample[i] = st->filt_len/2; michael@0: return RESAMPLER_ERR_SUCCESS; michael@0: } michael@0: michael@0: +SPX_RESAMPLE_EXPORT int speex_resampler_set_skip_frac_num(SpeexResamplerState *st, spx_uint32_t skip_frac_num) michael@0: +{ michael@0: + spx_uint32_t i; michael@0: + spx_uint32_t last_sample = skip_frac_num / st->den_rate; michael@0: + spx_uint32_t samp_frac_num = skip_frac_num % st->den_rate; michael@0: + for (i=0;inb_channels;i++) { michael@0: + st->last_sample[i] = last_sample; michael@0: + st->samp_frac_num[i] = samp_frac_num; michael@0: + } michael@0: + return RESAMPLER_ERR_SUCCESS; michael@0: +} michael@0: + michael@0: SPX_RESAMPLE_EXPORT int speex_resampler_reset_mem(SpeexResamplerState *st) michael@0: { michael@0: spx_uint32_t i; michael@0: for (i=0;inb_channels;i++) michael@0: { michael@0: st->last_sample[i] = 0; michael@0: st->magic_samples[i] = 0; michael@0: st->samp_frac_num[i] = 0; michael@0: diff --git a/media/libspeex_resampler/src/speex_resampler.h b/media/libspeex_resampler/src/speex_resampler.h michael@0: --- a/media/libspeex_resampler/src/speex_resampler.h michael@0: +++ b/media/libspeex_resampler/src/speex_resampler.h michael@0: @@ -69,16 +69,17 @@ michael@0: #define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality) michael@0: #define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride) michael@0: #define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride) michael@0: #define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride) michael@0: #define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride) michael@0: #define speex_resampler_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency) michael@0: #define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency) michael@0: #define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros) michael@0: +#define speex_resampler_set_skip_frac_num CAT_PREFIX(RANDOM_PREFIX,_resampler_set_skip_frac_num) michael@0: #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem) michael@0: #define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror) michael@0: michael@0: #define spx_int16_t short michael@0: #define spx_int32_t int michael@0: #define spx_uint16_t unsigned short michael@0: #define spx_uint32_t unsigned int michael@0: michael@0: @@ -321,16 +322,32 @@ int speex_resampler_get_output_latency(S michael@0: * resampler. It is recommended to use that when resampling an audio file, as michael@0: * it will generate a file with the same length. For real-time processing, michael@0: * it is probably easier not to use this call (so that the output duration michael@0: * is the same for the first frame). michael@0: * @param st Resampler state michael@0: */ michael@0: int speex_resampler_skip_zeros(SpeexResamplerState *st); michael@0: michael@0: +/** Set the numerator in a fraction determining the advance through input michael@0: + * samples before writing any output samples. The denominator of the fraction michael@0: + * is the value returned from speex_resampler_get_ratio() in ratio_den. This michael@0: + * is only useful before starting to use a newly created or reset resampler. michael@0: + * If the first input sample is interpreted as the signal at time michael@0: + * input_latency*in_rate, then the first output sample represents the signal michael@0: + * at the time frac_num/ratio_num*out_rate. michael@0: + * This is intended for careful alignment of output sample points wrt input michael@0: + * sample points. Large values are not an efficient offset into the in buffer. michael@0: + * @param st Resampler state michael@0: + * @param skip_frac_num Numerator of the offset fraction, michael@0: + * between 0 and ratio_den-1. michael@0: + */ michael@0: +int speex_resampler_set_skip_frac_num(SpeexResamplerState *st, michael@0: + spx_uint32_t skip_frac_num); michael@0: + michael@0: /** Reset a resampler so a new (unrelated) stream can be processed. michael@0: * @param st Resampler state michael@0: */ michael@0: int speex_resampler_reset_mem(SpeexResamplerState *st); michael@0: michael@0: /** Returns the English meaning for an error code michael@0: * @param err Error code michael@0: * @return English string