update pitchyin.[ch] and pitchdetection.c
authorPaul Brossier <piem@altern.org>
Mon, 11 Apr 2005 16:31:48 +0000 (16:31 +0000)
committerPaul Brossier <piem@altern.org>
Mon, 11 Apr 2005 16:31:48 +0000 (16:31 +0000)
src/pitchdetection.c
src/pitchyin.c
src/pitchyin.h

index d5eb72da3ed5925bebfd78a8c7535964a2e27e1b..038988a0ac2179766ccaa65ca3b045d89e37e911 100644 (file)
@@ -103,16 +103,12 @@ smpl_t aubio_pitchdetection(aubio_pitchdetection_t *p, fvec_t * ibuf) {
                                        p->buf->data[i][j] = ibuf->data[i][j];
                                }
                        }
-                       /* get the autocorr and pitch */
-                       aubio_pitchyin_diff(p->buf,p->yin);
-                       aubio_pitchyin_getcum(p->yin);
-                       pitch = aubio_pitchyin_getpitch(p->yin);
+                       pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, 0.5);
                        if (pitch>0) {
                                pitch = p->srate/(pitch+0.);
                        } else {
                                pitch = 0.;
                        }
-                       //fprintf(stderr,"%f\n",pitch);
                        break;
                case mcomb:
                        aubio_filter_do(p->filter,ibuf);
index bbfeb2b20255daef55166e4e204b8ceb3ffd847f..15d64b15e35c0719ddfe80314bea10dfca9ff9d4 100644 (file)
@@ -82,41 +82,39 @@ uint_t aubio_pitchyin_getpitch(fvec_t * yin) {
                }
                tau++;
        } while (tau<yin->length);
-       //AUBIO_DBG("No pitch found");
+       AUBIO_DBG("No pitch found");
        return 0;
 }
 
 
 /* all the above in one */
-uint_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t * yin){
-       uint_t c,j,tau = 0;
+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, tmp2;
-       for (c=0;c<input->channels;c++)
+       for (tau=0;tau<yin->length;tau++)
        {
-               for (tau=0;tau<yin->length;tau++)
-               {
-                       yin->data[c][tau] = 0.;
-               }
-               for (tau=1;tau<yin->length;tau++)
-               {
-                       for (j=0;j<yin->length;j++)
-                       {
-                               tmp = input->data[c][j] - input->data[c][j+tau];
-                               yin->data[c][tau] += SQR(tmp);
-                       }
-               }
-               tmp2 = 0.;
-               yin->data[c][0] = 1.;
-               for (tau=1;tau<yin->length;tau++)
+               yin->data[c][tau] = 0.;
+       }
+       for (tau=1;tau<yin->length;tau++)
+       {
+               for (j=0;j<yin->length;j++)
                {
-                       tmp += yin->data[c][tau];
-                       yin->data[c][tau] *= tau/tmp;
+                       tmp = input->data[c][j] - input->data[c][j+tau];
+                       yin->data[c][tau] += SQR(tmp);
                }
        }
+       tmp2 = 0.;
+       yin->data[c][0] = 1.;
+       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] < 0.1) { 
+               if(yin->data[c][tau] < tol) { 
                        while (yin->data[c][tau+1] < yin->data[c][tau]) {
                                tau++;
                        }
index 653631e8fe9e04a8b20835859b0f8e9f95402e1b..b50de01a7e9785f635efdaf5bf19b2c14cdbd4ec 100644 (file)
@@ -38,7 +38,7 @@ void aubio_pitchyin_getcum(fvec_t * yinbuf);
 
 uint_t aubio_pitchyin_getpitch(fvec_t *yinbuf);
 
-uint_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t *yinbuf);
+uint_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t *yinbuf, smpl_t tol);
 
 #ifdef __cplusplus
 }