]> code.delx.au - pulseaudio/commitdiff
resamplers: Optimize trivial resampler
authorMaarten Bosmans <mkbosmans@gmail.com>
Wed, 23 Nov 2011 10:40:08 +0000 (11:40 +0100)
committerColin Guthrie <colin@mageia.org>
Sun, 27 Nov 2011 14:54:01 +0000 (14:54 +0000)
This improves the performance of a typical s16 2ch resampling by 88%.

src/pulsecore/resampler.c

index 32a6071ec8ab43fe491246628409fd8de4f6e922..c432a6f3d837da91d3f02595c09d1e06461e13d4 100644 (file)
@@ -1376,6 +1376,7 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned
     pa_assert(input);
     pa_assert(output);
     pa_assert(out_n_frames);
+    pa_assert(r->i_ss.channels == r->o_ss.channels);
 
     fz = r->w_sz * r->o_ss.channels;
 
@@ -1391,7 +1392,16 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned
 
         pa_assert_fp(o_index * fz < pa_memblock_get_length(output->memblock));
 
-        memcpy((uint8_t*) dst + fz * o_index, (uint8_t*) src + fz * i_index, (int) fz);
+        /* Directly assign some common sample sizes, use memcpy as fallback */
+        if (r->w_sz == 2) {
+            for (unsigned c = 0; c < r->o_ss.channels; c++)
+                ((uint16_t *) dst)[o_index+c] = ((uint16_t *) src)[i_index+c];
+        } else if (r->w_sz == 4) {
+            for (unsigned c = 0; c < r->o_ss.channels; c++)
+                ((uint32_t *) dst)[o_index+c] = ((uint32_t *) src)[i_index+c];
+        } else {
+            memcpy((uint8_t *) dst + fz * o_index, (uint8_t *) src + fz * i_index, (int) fz);
+        }
     }
 
     pa_memblock_release(input->memblock);