]> code.delx.au - pulseaudio/commitdiff
resampler: Move the fix method logic into a separate function
authorpoljar (Damir Jelić) <poljarinho@gmail.com>
Wed, 26 Jun 2013 11:51:55 +0000 (13:51 +0200)
committerpoljar (Damir Jelić) <poljarinho@gmail.com>
Tue, 27 Aug 2013 10:33:09 +0000 (12:33 +0200)
src/pulsecore/resampler.c

index 235afdcf440d7c44e294bcc61275c2ce0b7e2450..00682c73ad80267017233c12fe966a275411bc2b 100644 (file)
@@ -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;