b=913854 add speex_resampler_set_skip_frac_num r=jmspeex

This allows a client to align output samples consistently for independent
resampling of contiguous input buffers.

--HG--
extra : rebase_source : 58caba11ac7f78418b173a98556276d3b4644603
This commit is contained in:
Karl Tomlinson 2014-02-27 11:44:40 +13:00
parent 2e56670ab5
commit d5e8ef47f8
5 changed files with 146 additions and 0 deletions

View File

@ -127,6 +127,7 @@ speex_resampler_get_output_stride
speex_resampler_get_input_latency
speex_resampler_get_output_latency
speex_resampler_skip_zeros
speex_resampler_set_skip_frac_num
speex_resampler_reset_mem
speex_resampler_strerror
cubeb_destroy

View File

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

View File

@ -1143,6 +1143,18 @@ SPX_RESAMPLE_EXPORT int speex_resampler_skip_zeros(SpeexResamplerState *st)
return RESAMPLER_ERR_SUCCESS;
}
SPX_RESAMPLE_EXPORT int speex_resampler_set_skip_frac_num(SpeexResamplerState *st, spx_uint32_t skip_frac_num)
{
spx_uint32_t i;
spx_uint32_t last_sample = skip_frac_num / st->den_rate;
spx_uint32_t samp_frac_num = skip_frac_num % st->den_rate;
for (i=0;i<st->nb_channels;i++) {
st->last_sample[i] = last_sample;
st->samp_frac_num[i] = samp_frac_num;
}
return RESAMPLER_ERR_SUCCESS;
}
SPX_RESAMPLE_EXPORT int speex_resampler_reset_mem(SpeexResamplerState *st)
{
spx_uint32_t i;

View File

@ -74,6 +74,7 @@
#define speex_resampler_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency)
#define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency)
#define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
#define speex_resampler_set_skip_frac_num CAT_PREFIX(RANDOM_PREFIX,_resampler_set_skip_frac_num)
#define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
#define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
@ -326,6 +327,22 @@ int speex_resampler_get_output_latency(SpeexResamplerState *st);
*/
int speex_resampler_skip_zeros(SpeexResamplerState *st);
/** Set the numerator in a fraction determining the advance through input
* samples before writing any output samples. The denominator of the fraction
* is the value returned from speex_resampler_get_ratio() in ratio_den. This
* is only useful before starting to use a newly created or reset resampler.
* If the first input sample is interpreted as the signal at time
* input_latency*in_rate, then the first output sample represents the signal
* at the time frac_num/ratio_num*out_rate.
* This is intended for careful alignment of output sample points wrt input
* sample points. Large values are not an efficient offset into the in buffer.
* @param st Resampler state
* @param skip_frac_num Numerator of the offset fraction,
* between 0 and ratio_den-1.
*/
int speex_resampler_set_skip_frac_num(SpeexResamplerState *st,
spx_uint32_t skip_frac_num);
/** Reset a resampler so a new (unrelated) stream can be processed.
* @param st Resampler state
*/

View File

@ -20,3 +20,4 @@ cp $1/COPYING .
# apply outstanding local patches
patch -p1 < sse-detect-runtime.patch
patch -p3 < reset.patch
patch -p3 < set-skip-frac.patch