shithub: sox

Download patch

ref: 15bd4c16b1ba2307a0fd535d8db493da05ea1975
parent: c20cfab0e5605f6e57df4b14b0d2bd2ae44af195
author: Rob Sykes <robs@users.sourceforge.net>
date: Thu Dec 6 01:29:39 EST 2012

speed up small-factor downsampling; e.g. ~15% improvement for 48k->44100

--- a/src/rate.c
+++ b/src/rate.c
@@ -313,9 +313,9 @@
     double d, epsilon = 0, frac;
     upsample = arbM < 1;
     for (i = arbM * .5, shift = 0; i >>= 1; arbM *= .5, ++shift);
-    preM = 1 - (arbM > 2);
-    postM = 1 + (arbM > 1 && arbM < 2), arbM /= postM;
-    preL = 1 + (upsample && mode), arbM *= preL;
+    preM = upsample || (arbM > 1.5 && arbM < 2);
+    postM = 1 + (arbM > 1 && preM), arbM /= postM;
+    preL = 1 + (!preM && arbM < 2) + (upsample && mode), arbM *= preL;
     if ((frac = arbM - (int)arbM))
       epsilon = fabs((uint32_t)(frac * MULT32 + .5) / (frac * MULT32) - 1);
     for (i = 1, rational = !frac; i <= maxL && !rational; ++i) {