diff options
author | Sebastian Dröge <slomo@circular-chaos.org> | 2007-11-23 08:48:50 +0000 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2007-11-23 08:48:50 +0000 |
commit | e8182f4d33a93374e586127e88c3d18fd9c13ffc (patch) | |
tree | 81068e58d1eb14987644273badaaee732d99cf76 /gst/speexresample/resample.c | |
parent | f219caaf015cf4bec440519008cba304e2270199 (diff) | |
download | gst-plugins-bad-e8182f4d33a93374e586127e88c3d18fd9c13ffc.tar.gz gst-plugins-bad-e8182f4d33a93374e586127e88c3d18fd9c13ffc.tar.bz2 gst-plugins-bad-e8182f4d33a93374e586127e88c3d18fd9c13ffc.zip |
gst/speexresample/: Add functions to push the remaining samples and to get the latency of the resampler. These will g...
Original commit message from CVS:
* gst/speexresample/resample.c: (speex_resampler_get_latency),
(speex_resampler_drain_float), (speex_resampler_drain_int),
(speex_resampler_drain_interleaved_float),
(speex_resampler_drain_interleaved_int):
* gst/speexresample/speex_resampler.h:
* gst/speexresample/speex_resampler_wrapper.h:
Add functions to push the remaining samples and to get the latency
of the resampler. These will get added to Speex SVN in this or a
slightly changed form at some point too and should get merged then
again.
* gst/speexresample/gstspeexresample.c: (gst_speex_resample_init),
(gst_speex_resample_init_state),
(gst_speex_resample_transform_size),
(gst_speex_resample_push_drain), (gst_speex_resample_event),
(gst_speex_fix_output_buffer), (gst_speex_resample_process),
(gst_speex_resample_query), (gst_speex_resample_query_type):
Drop the prepending zeroes and output the remaining samples on EOS.
Also properly implement the latency query for this. speexresample
should be completely ready for production use now.
Diffstat (limited to 'gst/speexresample/resample.c')
-rw-r--r-- | gst/speexresample/resample.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/gst/speexresample/resample.c b/gst/speexresample/resample.c index f01574f9..5b20f5ef 100644 --- a/gst/speexresample/resample.c +++ b/gst/speexresample/resample.c @@ -1273,6 +1273,136 @@ speex_resampler_get_output_stride (SpeexResamplerState * st, } int +speex_resampler_get_latency (SpeexResamplerState * st) +{ + return st->filt_len / 2; +} + +int +speex_resampler_drain_float (SpeexResamplerState * st, + spx_uint32_t channel_index, float *out, spx_uint32_t * out_len) +{ + spx_uint32_t in_len; + int ret; + float *in; + + in_len = speex_resampler_get_latency (st); + + in = speex_alloc (sizeof (float) * in_len); + *out_len = + MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate, + *out_len); + + ret = + speex_resampler_process_float (st, channel_index, in, &in_len, out, + out_len); + + speex_free (in); + + speex_resampler_reset_mem (st); + + return ret; +} + +int +speex_resampler_drain_int (SpeexResamplerState * st, + spx_uint32_t channel_index, spx_int16_t * out, spx_uint32_t * out_len) +{ + spx_uint32_t in_len; + int ret; + spx_int16_t *in; + + in_len = speex_resampler_get_latency (st); + + in = speex_alloc (sizeof (spx_int16_t) * in_len); + *out_len = + MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate, + *out_len); + + ret = + speex_resampler_process_int (st, channel_index, in, &in_len, out, + out_len); + + speex_free (in); + + speex_resampler_reset_mem (st); + + return ret; +} + +int +speex_resampler_drain_interleaved_float (SpeexResamplerState * st, + float *out, spx_uint32_t * out_len) +{ + spx_uint32_t i; + int istride_save, ostride_save; + spx_uint32_t bak_len; + spx_uint32_t in_len; + float *in; + + in_len = speex_resampler_get_latency (st); + + in = speex_alloc (sizeof (float) * in_len); + *out_len = + MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate, + *out_len); + bak_len = *out_len; + + istride_save = st->in_stride; + ostride_save = st->out_stride; + st->in_stride = 1; + st->out_stride = st->nb_channels; + for (i = 0; i < st->nb_channels; i++) { + *out_len = bak_len; + speex_resampler_process_float (st, i, in, &in_len, out + i, out_len); + } + st->in_stride = istride_save; + st->out_stride = ostride_save; + + speex_free (in); + + speex_resampler_reset_mem (st); + + return RESAMPLER_ERR_SUCCESS; +} + +int +speex_resampler_drain_interleaved_int (SpeexResamplerState * st, + spx_int16_t * out, spx_uint32_t * out_len) +{ + spx_uint32_t i; + int istride_save, ostride_save; + spx_uint32_t bak_len; + spx_uint32_t in_len; + spx_int16_t *in; + + in_len = speex_resampler_get_latency (st); + + in = speex_alloc (sizeof (spx_int16_t) * in_len); + *out_len = + MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate, + *out_len); + bak_len = *out_len; + + istride_save = st->in_stride; + ostride_save = st->out_stride; + st->in_stride = 1; + st->out_stride = st->nb_channels; + for (i = 0; i < st->nb_channels; i++) { + *out_len = bak_len; + speex_resampler_process_int (st, i, in, &in_len, out + i, out_len); + } + st->in_stride = istride_save; + st->out_stride = ostride_save; + + speex_free (in); + + speex_resampler_reset_mem (st); + + return RESAMPLER_ERR_SUCCESS; +} + +int speex_resampler_skip_zeros (SpeexResamplerState * st) { spx_uint32_t i; |