speeding up yin
authorPaul Brossier <piem@altern.org>
Mon, 22 Aug 2005 19:30:10 +0000 (19:30 +0000)
committerPaul Brossier <piem@altern.org>
Mon, 22 Aug 2005 19:30:10 +0000 (19:30 +0000)
src/pitchyin.c

index 1bdf71c288a71cc1774d411f77479f711b5bbc94..efd6db993289ad6c98b8fd06a64c524fac5ef5d3 100644 (file)
@@ -90,38 +90,23 @@ uint_t aubio_pitchyin_getpitch(fvec_t * yin) {
 /* all the above in one */
 uint_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t * yin, smpl_t tol){
        uint_t c=0,j,tau = 0;
-       smpl_t tmp = 0;
-       for (tau=0;tau<yin->length;tau++)
-       {
-               yin->data[c][tau] = 0.;
-       }
+       smpl_t tmp = 0., tmp2 = 0.;
+       yin->data[c][0] = 1.;
        for (tau=1;tau<yin->length;tau++)
        {
+               yin->data[c][tau] = 0.;
                for (j=0;j<yin->length;j++)
                {
                        tmp = input->data[c][j] - input->data[c][j+tau];
                        yin->data[c][tau] += SQR(tmp);
                }
-       }
-       yin->data[c][0] = 1.;
-       tmp = 0.;
-       for (tau=1;tau<yin->length;tau++)
-       {
-               tmp += yin->data[c][tau];
-               yin->data[c][tau] *= tau/tmp;
-       }
-       /* should merge the following with above */
-        tau = 1;
-       do 
-       {
-               if(yin->data[c][tau] < tol) { 
-                       while (yin->data[c][tau+1] < yin->data[c][tau]) {
-                               tau++;
-                       }
-                       return tau;
+               tmp2 += yin->data[c][tau];
+               yin->data[c][tau] *= tau/tmp2;
+               if((yin->data[c][tau] < tol) && 
+                                (yin->data[c][tau-1] < yin->data[c][tau])) {
+                       return tau-1;
                }
-               tau++;
-       } while (tau<yin->length);
+        }
        return 0;
 }