shithub: aubio

Download patch

ref: f162cf9b6087f77398c97b7b16b3079460f06a14
parent: e5757cf8d14e4d3678632d274870f08a4056753e
author: Paul Brossier <piem@piem.org>
date: Thu Oct 8 16:20:19 EDT 2009

src/pitch/pitchschmitt.c: remove unneeded samplerate parameter, update prototypes, make multichannel

--- a/src/pitch/pitchschmitt.c
+++ b/src/pitch/pitchschmitt.c
@@ -31,7 +31,7 @@
         signed short int *buf;
 };
 
-aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size, uint_t samplerate)
+aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size)
 {
   aubio_pitchschmitt_t * p = AUBIO_NEW(aubio_pitchschmitt_t);
   p->blockSize = size;
@@ -38,17 +38,20 @@
   p->schmittBuffer = AUBIO_ARRAY(signed short int,p->blockSize);
   p->buf = AUBIO_ARRAY(signed short int,p->blockSize);
   p->schmittPointer = p->schmittBuffer;
-  p->rate = samplerate;
   return p;
 }
 
-smpl_t aubio_pitchschmitt_do (aubio_pitchschmitt_t *p, fvec_t * input)
+void
+aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * input,
+    fvec_t * output)
 {
-  uint_t i;
-  for (i=0; i<input->length; i++) {
-    p->buf[i] = input->data[0][i]*32768.;
+  uint_t i, j;
+  for (i = 0; i < input->channels; i++) {
+    for (j = 0; j < input->length; j++) {
+      p->buf[j] = input->data[i][j] * 32768.;
+    }
+    output->data[i][0] = aubio_schmittS16LE (p, input->length, p->buf);
   }
-  return aubio_schmittS16LE(p, input->length, p->buf);
 }
 
 smpl_t aubio_schmittS16LE (aubio_pitchschmitt_t *p, uint_t nframes, signed short int *indata)
@@ -58,7 +61,7 @@
   signed short int *schmittBuffer = p->schmittBuffer;
   signed short int *schmittPointer = p->schmittPointer;
 
-  smpl_t freq = 0., trigfact = 0.6;
+  smpl_t period = 0., trigfact = 0.6;
 
   for (i=0; i<nframes; i++) {
     *schmittPointer++ = indata[i];
@@ -89,8 +92,8 @@
 	  schmittTriggered = 0;
 	}
       }
-      if (endpoint > startpoint) {
-	freq = ((smpl_t)p->rate*(tc/(smpl_t)(endpoint-startpoint)));
+      if ((endpoint > startpoint) && (tc > 0)) {
+	period = (smpl_t)(endpoint-startpoint)/tc;
       }
     }
   }
@@ -97,7 +100,7 @@
 
   p->schmittBuffer  = schmittBuffer;
   p->schmittPointer = schmittPointer;
-  return freq;
+  return period;
 }
 
 void del_aubio_pitchschmitt (aubio_pitchschmitt_t *p)
--- a/src/pitch/pitchschmitt.h
+++ b/src/pitch/pitchschmitt.h
@@ -45,16 +45,16 @@
  
   \param p pitch detection object as returned by new_aubio_pitchschmitt 
   \param input input signal window (length as specified at creation time) 
+  \param output pitch period estimates, in samples
  
 */
-smpl_t aubio_pitchschmitt_do (aubio_pitchschmitt_t *p, fvec_t * input);
+void aubio_pitchschmitt_do (aubio_pitchschmitt_t *p, fvec_t * input, fvec_t * output);
 /** creation of the pitch detection object
  
   \param size size of the input buffer to analyse 
-  \param samplerate sampling rate of the signal 
  
 */
-aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size, uint_t samplerate);
+aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size);
 /** deletion of the pitch detection object
  
   \param p pitch detection object as returned by new_aubio_pitchschmitt 
--- a/tests/src/test-pitchschmitt.c
+++ b/tests/src/test-pitchschmitt.c
@@ -3,19 +3,19 @@
 int main(){
         /* allocate some memory */
         uint_t win_s      = 1024;                       /* window size */
-        uint_t samplerate = 44100;                          /* number of channel */
         fvec_t * in       = new_fvec (win_s, 1); /* input buffer */
-        aubio_pitchschmitt_t * o  = new_aubio_pitchschmitt(
-          win_s, samplerate );
+        fvec_t * out = new_fvec (1, 1); /* input buffer */
+        aubio_pitchschmitt_t * o  = new_aubio_pitchschmitt(win_s);
         uint_t i = 0;
 
         while (i < 1000) {
-          aubio_pitchschmitt_do (o,in);
+          aubio_pitchschmitt_do (o,in, out);
           i++;
         };
 
         del_aubio_pitchschmitt(o);
         del_fvec(in);
+        del_fvec(out);
         aubio_cleanup();
 
         return 0;