From f55454777c94b255eb52bdd2506fd8156a648a4a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 23 Dec 2007 20:15:03 +0000 Subject: [PATCH] add API for resetting allocated resamplers git-svn-id: svn://svn.0pointer.net/pulseaudio/trunk@2088 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/resampler.c | 38 +++++++++++++++++++++++++++++++------- src/pulsecore/resampler.h | 4 ++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 429759f0..40fc2800 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -72,6 +72,7 @@ struct pa_resampler { void (*impl_free)(pa_resampler *r); void (*impl_update_rates)(pa_resampler *r); void (*impl_resample)(pa_resampler *r, const pa_memchunk *in, unsigned in_samples, pa_memchunk *out, unsigned *out_samples); + void (*impl_reset)(pa_resampler *r); struct { /* data specific to the trivial resampler */ unsigned o_counter; @@ -208,6 +209,7 @@ pa_resampler* pa_resampler_new( r->impl_free = NULL; r->impl_update_rates = NULL; r->impl_resample = NULL; + r->impl_reset = NULL; /* Fill sample specs */ r->i_ss = *a; @@ -374,6 +376,13 @@ size_t pa_resampler_max_block_size(pa_resampler *r) { return (((block_size_max/fs + EXTRA_SAMPLES)*r->i_ss.rate)/ss.rate)*r->i_fz; } +void pa_resampler_reset(pa_resampler *r) { + pa_assert(r); + + if (r->impl_reset) + r->impl_reset(r); +} + pa_resample_method_t pa_resampler_get_method(pa_resampler *r) { pa_assert(r); @@ -1181,6 +1190,12 @@ static void libsamplerate_update_rates(pa_resampler *r) { pa_assert_se(src_set_ratio(r->src.state, (double) r->o_ss.rate / r->i_ss.rate) == 0); } +static void libsamplerate_reset(pa_resampler *r) { + pa_assert(r); + + pa_assert_se(src_reset(r->src.state) == 0); +} + static void libsamplerate_free(pa_resampler *r) { pa_assert(r); @@ -1199,6 +1214,7 @@ static int libsamplerate_init(pa_resampler *r) { r->impl_free = libsamplerate_free; r->impl_update_rates = libsamplerate_update_rates; r->impl_resample = libsamplerate_resample; + r->impl_reset = libsamplerate_reset; return 0; } @@ -1259,6 +1275,17 @@ static void speex_update_rates(pa_resampler *r) { } } +static void speex_reset(pa_resampler *r) { + pa_assert(r); + + if (r->method >= PA_RESAMPLER_SPEEX_FIXED_BASE && r->method <= PA_RESAMPLER_SPEEX_FIXED_MAX) + pa_assert_se(paspfx_resampler_reset_mem(r->speex.state) == 0); + else { + pa_assert(r->method >= PA_RESAMPLER_SPEEX_FLOAT_BASE && r->method <= PA_RESAMPLER_SPEEX_FLOAT_MAX); + pa_assert_se(paspfl_resampler_reset_mem(r->speex.state) == 0); + } +} + static void speex_free(pa_resampler *r) { pa_assert(r); @@ -1280,6 +1307,7 @@ static int speex_init(pa_resampler *r) { r->impl_free = speex_free; r->impl_update_rates = speex_update_rates; + r->impl_reset = speex_reset; if (r->method >= PA_RESAMPLER_SPEEX_FIXED_BASE && r->method <= PA_RESAMPLER_SPEEX_FIXED_MAX) { q = r->method - PA_RESAMPLER_SPEEX_FIXED_BASE; @@ -1353,7 +1381,7 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned } } -static void trivial_update_rates(pa_resampler *r) { +static void trivial_update_rates_or_reset(pa_resampler *r) { pa_assert(r); r->trivial.i_counter = 0; @@ -1366,8 +1394,8 @@ static int trivial_init(pa_resampler*r) { r->trivial.o_counter = r->trivial.i_counter = 0; r->impl_resample = trivial_resample; - r->impl_update_rates = trivial_update_rates; - r->impl_free = NULL; + r->impl_update_rates = trivial_update_rates_or_reset; + r->impl_reset = trivial_update_rates_or_reset; return 0; } @@ -1495,9 +1523,5 @@ static int copy_init(pa_resampler *r) { pa_assert(r->o_ss.rate == r->i_ss.rate); - r->impl_free = NULL; - r->impl_resample = NULL; - r->impl_update_rates = NULL; - return 0; } diff --git a/src/pulsecore/resampler.h b/src/pulsecore/resampler.h index 778c738d..82d01082 100644 --- a/src/pulsecore/resampler.h +++ b/src/pulsecore/resampler.h @@ -81,6 +81,9 @@ void pa_resampler_set_input_rate(pa_resampler *r, uint32_t rate); /* Change the output rate of the resampler object */ void pa_resampler_set_output_rate(pa_resampler *r, uint32_t rate); +/* Reinitialize state of the resampler, possibly due to seeking or other discontinuities */ +void pa_resampler_reset(pa_resampler *r); + /* Return the resampling method of the resampler object */ pa_resample_method_t pa_resampler_get_method(pa_resampler *r); @@ -93,4 +96,5 @@ const char *pa_resample_method_to_string(pa_resample_method_t m); /* Return 1 when the specified resampling method is supported */ int pa_resample_method_supported(pa_resample_method_t m); + #endif -- 2.11.4.GIT