--- src/pulsecore/resampler.c | 52 ++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index f70f186..35bcaf9 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -192,28 +192,18 @@ static int (* const init_table[])(pa_resampler*r) = { [PA_RESAMPLER_PEAKS] = peaks_init, }; -pa_resampler* pa_resampler_new( - pa_mempool *pool, - const pa_sample_spec *a, - const pa_channel_map *am, - const pa_sample_spec *b, - const pa_channel_map *bm, - pa_resample_method_t method, - pa_resample_flags_t flags) { - - pa_resampler *r = NULL; - - pa_assert(pool); - pa_assert(a); - pa_assert(b); - pa_assert(pa_sample_spec_valid(a)); - pa_assert(pa_sample_spec_valid(b)); +static pa_resample_method_t pa_resampler_fix_method( + pa_resample_flags_t flags, + pa_resample_method_t method, + const uint32_t rate_a, + const uint32_t rate_b) { + + pa_assert(rate_a > 0 && rate_a <= PA_RATE_MAX); + pa_assert(rate_b > 0 && rate_b <= PA_RATE_MAX); pa_assert(method >= 0); pa_assert(method < PA_RESAMPLER_MAX); - /* Fix method */ - - if (!(flags & PA_RESAMPLER_VARIABLE_RATE) && a->rate == b->rate) { + if (!(flags & PA_RESAMPLER_VARIABLE_RATE) && rate_a == rate_b) { pa_log_info("Forcing resampler 'copy', because of fixed, identical sample rates."); method = PA_RESAMPLER_COPY; } @@ -244,6 +234,30 @@ pa_resampler* pa_resampler_new( #endif } + return method; +} + +pa_resampler* pa_resampler_new( + pa_mempool *pool, + const pa_sample_spec *a, + const pa_channel_map *am, + const pa_sample_spec *b, + const pa_channel_map *bm, + pa_resample_method_t method, + pa_resample_flags_t flags) { + + pa_resampler *r = NULL; + + pa_assert(pool); + pa_assert(a); + pa_assert(b); + pa_assert(pa_sample_spec_valid(a)); + pa_assert(pa_sample_spec_valid(b)); + pa_assert(method >= 0); + pa_assert(method < PA_RESAMPLER_MAX); + + method = pa_resampler_fix_method(flags, method, a->rate, b->rate); + r = pa_xnew0(pa_resampler, 1); r->mempool = pool; r->method = method; -- 1.8.3.2