shithub: aubio

Download patch

ref: 5e9c68a7e84dccb4a0d6780f60b8c850b9854fbe
parent: 28d8c4aa38dfbbb65fcc01c83037c0fb223e791a
author: Paul Brossier <piem@altern.org>
date: Tue Aug 9 13:56:21 EDT 2005

rename file_ to aubio_sndfile, protect aubio_pitdetection_{mode,type} enumerators

--- a/examples/utils.c
+++ b/examples/utils.c
@@ -39,8 +39,8 @@
 uint_t samplerate                     = 44100;
 
 
-aubio_file_t * file = NULL;
-aubio_file_t * fileout = NULL;
+aubio_sndfile_t * file = NULL;
+aubio_sndfile_t * fileout = NULL;
 
 aubio_pvoc_t * pv;
 fvec_t * ibuf;
@@ -58,7 +58,7 @@
 /* pitch objects */
 smpl_t pitch               = 0.;
 aubio_pitchdetection_t * pitchdet;
-aubio_pitchdetection_type mode = aubio_yin; // aubio_mcomb
+aubio_pitchdetection_type mode = aubio_pitch_yin; // aubio_pitch_mcomb
 uint_t median         = 6;
 
 fvec_t * note_buffer  = NULL;
@@ -204,28 +204,28 @@
 void examples_common_init(int argc,char ** argv) {
 
 
-  aubio_file_t * onsetfile;
+  aubio_sndfile_t * onsetfile;
   /* parse command line arguments */
   parse_args(argc, argv);
 
   woodblock = new_fvec(buffer_size,1);
   if (output_filename || usejack) {
-          (onsetfile = new_file_ro(onset_filename)) ||
-                  (onsetfile = new_file_ro("sounds/woodblock.aiff")) ||
-                  (onsetfile = new_file_ro("../sounds/woodblock.aiff"));
+          (onsetfile = new_aubio_sndfile_ro(onset_filename)) ||
+                  (onsetfile = new_aubio_sndfile_ro("sounds/woodblock.aiff")) ||
+                  (onsetfile = new_aubio_sndfile_ro("../sounds/woodblock.aiff"));
           /* read the output sound once */
-          file_read(onsetfile, overlap_size, woodblock);
+          aubio_sndfile_read(onsetfile, overlap_size, woodblock);
   }
 
   if(!usejack)
   {
     debug("Opening files ...\n");
-    file = new_file_ro (input_filename);
-    if (verbose) file_info(file);
-    channels = aubio_file_channels(file);
-    samplerate = aubio_file_samplerate(file);
+    file = new_aubio_sndfile_ro (input_filename);
+    if (verbose) aubio_sndfile_info(file);
+    channels = aubio_sndfile_channels(file);
+    samplerate = aubio_sndfile_samplerate(file);
     if (output_filename != NULL)
-      fileout = new_file_wo(file, output_filename);
+      fileout = new_aubio_sndfile_wo(file, output_filename);
   }
 
   ibuf      = new_fvec(overlap_size, channels);
@@ -234,7 +234,7 @@
 
   if (usepitch) {
     pitchdet = new_aubio_pitchdetection(buffer_size*4, 
-                    overlap_size, channels, samplerate, mode, aubio_freq);
+                    overlap_size, channels, samplerate, mode, aubio_pitchm_freq);
   
   if (median) {
           note_buffer = new_fvec(median, 1);
@@ -305,22 +305,22 @@
 
     frames = 0;
 
-    while (overlap_size == file_read(file, overlap_size, ibuf))
+    while (overlap_size == aubio_sndfile_read(file, overlap_size, ibuf))
     {
       isonset=0;
       process_func(ibuf->data, obuf->data, overlap_size);
       print(); 
       if (output_filename != NULL) {
-        file_write(fileout,overlap_size,obuf);
+        aubio_sndfile_write(fileout,overlap_size,obuf);
       }
       frames++;
     }
 
     debug("Processed %d frames of %d samples.\n", frames, buffer_size);
-    del_file(file);
+    del_aubio_sndfile(file);
 
     if (output_filename != NULL)
-      del_file(fileout);
+      del_aubio_sndfile(fileout);
 
   }
 }
--- a/examples/utils.h
+++ b/examples/utils.h
@@ -75,8 +75,8 @@
 extern uint_t samplerate;
 
 
-extern aubio_file_t * file;
-extern aubio_file_t * fileout;
+extern aubio_sndfile_t * file;
+extern aubio_sndfile_t * fileout;
 
 extern aubio_pvoc_t * pv;
 extern fvec_t * ibuf;
--- a/ext/sndfileio.c
+++ b/ext/sndfileio.c
@@ -29,7 +29,7 @@
 #define MAX_CHANNELS 6
 #define MAX_SIZE 4096
 
-struct _aubio_file_t {
+struct _aubio_sndfile_t {
         SNDFILE *handle;
         int samplerate;
         int channels;
@@ -38,8 +38,8 @@
         int size;       /** store the size to check if realloc needed */
 };
 
-aubio_file_t * new_file_ro(const char* outputname) {
-        aubio_file_t * f = AUBIO_NEW(aubio_file_t);
+aubio_sndfile_t * new_aubio_sndfile_ro(const char* outputname) {
+        aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
         SF_INFO sfinfo;
         AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
 
@@ -64,7 +64,7 @@
         return f;
 }
 
-int file_open_wo(aubio_file_t * f, const char* inputname) {
+int aubio_sndfile_open_wo(aubio_sndfile_t * f, const char* inputname) {
         SF_INFO sfinfo;
         memset (&sfinfo, 0, sizeof (sfinfo));
 
@@ -89,18 +89,18 @@
 }
 
 /* setup file struct from existing one */
-aubio_file_t * new_file_wo(aubio_file_t * fmodel, const char *outputname) {
-        aubio_file_t * f = AUBIO_NEW(aubio_file_t);
+aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * fmodel, const char *outputname) {
+        aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
         f->samplerate    = fmodel->samplerate;
         f->channels      = fmodel->channels;
         f->format        = fmodel->format;
-        file_open_wo(f, outputname);
+        aubio_sndfile_open_wo(f, outputname);
         return f;
 }
 
 
 /* return 0 if properly closed, 1 otherwise */
-int del_file(aubio_file_t * f) {
+int del_aubio_sndfile(aubio_sndfile_t * f) {
         if (sf_close(f->handle)) {
                 AUBIO_ERR("Error closing file.");
                 puts (sf_strerror (NULL));
@@ -121,7 +121,7 @@
 
 /* read frames from file in data 
  *  return the number of frames actually read */
-int file_read(aubio_file_t * f, int frames, fvec_t * read) {
+int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) {
         sf_count_t read_frames;
         int i,j, channels = f->channels;
         int nsamples = frames*channels;
@@ -130,7 +130,7 @@
 
         /* allocate data for de/interleaving reallocated when needed. */
         if (nsamples >= f->size) {
-                AUBIO_ERR("Maximum file_read buffer size exceeded.");
+                AUBIO_ERR("Maximum aubio_sndfile_read buffer size exceeded.");
                 return -1;
                 /*
                 AUBIO_FREE(f->tmpdata);
@@ -157,7 +157,7 @@
 /* write 'frames' samples to file from data 
  *   return the number of frames actually written 
  */
-int file_write(aubio_file_t * f, int frames, fvec_t * write) {
+int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) {
         sf_count_t written_frames = 0;
         int i, j,	channels = f->channels;
         int nsamples = channels*frames;
@@ -165,7 +165,7 @@
 
         /* allocate data for de/interleaving reallocated when needed. */
         if (nsamples >= f->size) {
-                AUBIO_ERR("Maximum file_write buffer size exceeded.");
+                AUBIO_ERR("Maximum aubio_sndfile_write buffer size exceeded.");
                 return -1;
                 /*
                 AUBIO_FREE(f->tmpdata);
@@ -191,15 +191,15 @@
  *
  */
 
-uint_t aubio_file_channels(aubio_file_t * f) {
+uint_t aubio_sndfile_channels(aubio_sndfile_t * f) {
         return f->channels;
 }
 
-uint_t aubio_file_samplerate(aubio_file_t * f) {
+uint_t aubio_sndfile_samplerate(aubio_sndfile_t * f) {
         return f->samplerate;
 }
 
-void file_info(aubio_file_t * f) {
+void aubio_sndfile_info(aubio_sndfile_t * f) {
         AUBIO_DBG("srate    : %d\n", f->samplerate);
         AUBIO_DBG("channels : %d\n", f->channels);
         AUBIO_DBG("format   : %d\n", f->format);
--- a/ext/sndfileio.h
+++ b/ext/sndfileio.h
@@ -30,40 +30,40 @@
 /**
  * sndfile object
  */
-typedef struct _aubio_file_t aubio_file_t;
+typedef struct _aubio_sndfile_t aubio_sndfile_t;
 /** 
  * Open a sound file for reading
  */
-aubio_file_t * new_file_ro (const char * inputfile);
+aubio_sndfile_t * new_aubio_sndfile_ro (const char * inputfile);
 /**
  * Copy file model from previously opened sound file.
  */
-aubio_file_t * new_file_wo(aubio_file_t * existingfile, const char * outputname);
+aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * existingfile, const char * outputname);
 /** 
  * Open a sound file for writing
  */
-int file_open_wo (aubio_file_t * file, const char * outputname);
+int aubio_sndfile_open_wo (aubio_sndfile_t * file, const char * outputname);
 /** 
  * Read frames data from file 
  */
-int file_read(aubio_file_t * file, int frames, fvec_t * read);
+int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read);
 /** 
  * Write data of length frames to file
  */
-int file_write(aubio_file_t * file, int frames, fvec_t * write);
+int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write);
 /**
  * Close file and delete file object
  */
-int del_file(aubio_file_t * file);
+int del_aubio_sndfile(aubio_sndfile_t * file);
 /**
  * Return some files facts
  */
-void file_info(aubio_file_t * file);
+void aubio_sndfile_info(aubio_sndfile_t * file);
 /**
  * Return number of channel in file
  */
-uint_t aubio_file_channels(aubio_file_t * file);
-uint_t aubio_file_samplerate(aubio_file_t * file);
+uint_t aubio_sndfile_channels(aubio_sndfile_t * file);
+uint_t aubio_sndfile_samplerate(aubio_sndfile_t * file);
 
 #ifdef __cplusplus
 }
--- a/python/aubio/aubioclass.py
+++ b/python/aubio/aubioclass.py
@@ -29,21 +29,21 @@
 class sndfile:
     def __init__(self,filename,model=None):
         if (model!=None):
-            self.file = new_file_wo(model.file,filename)
+            self.file = new_aubio_sndfile_wo(model.file,filename)
         else:
-            self.file = new_file_ro(filename)
+            self.file = new_aubio_sndfile_ro(filename)
     def __del__(self):
-        del_file(self.file)
+        del_aubio_sndfile(self.file)
     def info(self):
-        file_info(self.file)
+        aubio_sndfile_info(self.file)
     def samplerate(self):
-        return aubio_file_samplerate(self.file)
+        return aubio_sndfile_samplerate(self.file)
     def channels(self):
-        return aubio_file_channels(self.file)
+        return aubio_sndfile_channels(self.file)
     def read(self,nfram,vecread):
-        return file_read(self.file,nfram,vecread())
+        return aubio_sndfile_read(self.file,nfram,vecread())
     def write(self,nfram,vecwrite):
-        return file_write(self.file,nfram,vecwrite())
+        return aubio_sndfile_write(self.file,nfram,vecwrite())
 
 class pvoc:
     def __init__(self,buf,hop,chan):
@@ -204,7 +204,7 @@
         frameread += 1
     return mylist
 
-def getpitch(filein,mode=aubio_mcomb,bufsize=1024,hopsize=512,omode=aubio_freq,
+def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_pitchm_freq,
         samplerate=44100.,silence=-70):
     frameread = 0
     filei     = sndfile(filein)
@@ -227,8 +227,8 @@
     return mylist
 
 class pitchdetection:
-    def __init__(self,mode=aubio_mcomb,bufsize=2048,hopsize=1024,
-        channels=1,samplerate=44100.,omode=aubio_freq):
+    def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
+        channels=1,samplerate=44100.,omode=aubio_pitchm_freq):
         self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,
                 samplerate,mode,omode)
         #self.filt     = filter(srate,"adsgn")
--- a/python/aubiopitch
+++ b/python/aubiopitch
@@ -13,13 +13,13 @@
 def check_mode(option, opt, value, parser):
         nvalue = parser.rargs[0]
         if   nvalue == 'mcomb' :
-                 setattr(parser.values, option.dest, aubio_mcomb)
+                 setattr(parser.values, option.dest, aubio_pitch_mcomb)
         elif nvalue == 'yin'           :
-                 setattr(parser.values, option.dest, aubio_yin)
+                 setattr(parser.values, option.dest, aubio_pitch_yin)
         elif nvalue == 'fcomb'         :
-                 setattr(parser.values, option.dest, aubio_fcomb)
+                 setattr(parser.values, option.dest, aubio_pitch_fcomb)
         elif nvalue == 'schmitt'      :
-                 setattr(parser.values, option.dest, aubio_schmitt)
+                 setattr(parser.values, option.dest, aubio_pitch_schmitt)
 
 
 def parse_args():
@@ -29,7 +29,7 @@
                           action="store", dest="filename", 
                           help="input sound file")
         parser.add_option("-m","--mode", action="callback", 
-                          callback=check_mode, dest="mode", default=aubio_mcomb,
+                          callback=check_mode, dest="mode", default=aubio_pitch_mcomb,
                           help="pitch detection mode [default=mcomb] \
                           mcomb|yin|fcomb|schmitt")
         parser.add_option("-B","--bufsize",
--- a/src/pitchdetection.c
+++ b/src/pitchdetection.c
@@ -61,23 +61,23 @@
 	p->type = type;
 	p->bufsize = bufsize;
 	switch(p->type) {
-		case aubio_yin:
+		case aubio_pitch_yin:
 			p->buf      = new_fvec(bufsize,channels);
 			p->yin      = new_fvec(bufsize/2,channels);
                         p->callback = aubio_pitchdetection_yin;
 			break;
-		case aubio_mcomb:
+		case aubio_pitch_mcomb:
 			p->pv       = new_aubio_pvoc(bufsize, hopsize, channels);
 			p->fftgrain = new_cvec(bufsize, channels);
 			p->mcomb    = new_aubio_pitchmcomb(bufsize,channels);
                         p->callback = aubio_pitchdetection_mcomb;
 			break;
-                case aubio_fcomb:
+                case aubio_pitch_fcomb:
 			p->buf      = new_fvec(bufsize,channels);
                         p->fcomb    = new_aubio_pitchfcomb(bufsize,samplerate);
                         p->callback = aubio_pitchdetection_fcomb;
                         break;
-                case aubio_schmitt:
+                case aubio_pitch_schmitt:
 			p->buf      = new_fvec(bufsize,channels);
                         p->schmitt  = new_aubio_pitchschmitt(bufsize,samplerate);
                         p->callback = aubio_pitchdetection_schmitt;
@@ -90,20 +90,20 @@
 
 void del_aubio_pitchdetection(aubio_pitchdetection_t * p) {
 	switch(p->type) {
-		case aubio_yin:
+		case aubio_pitch_yin:
 			del_fvec(p->yin);
 			del_fvec(p->buf);
 			break;
-		case aubio_mcomb:
+		case aubio_pitch_mcomb:
 			del_aubio_pvoc(p->pv);
 			del_cvec(p->fftgrain);
 			del_aubio_pitchmcomb(p->mcomb);
 			break;
-                case aubio_schmitt:
+                case aubio_pitch_schmitt:
 			del_fvec(p->buf);
                         del_aubio_pitchschmitt(p->schmitt);
                         break;
-                case aubio_fcomb:
+                case aubio_pitch_fcomb:
 			del_fvec(p->buf);
                         del_aubio_pitchfcomb(p->fcomb);
                         break;
--- a/src/pitchdetection.h
+++ b/src/pitchdetection.h
@@ -24,17 +24,17 @@
 #endif
 
 typedef enum {
-	aubio_yin,
-	aubio_mcomb,
-        aubio_schmitt,
-        aubio_fcomb
+        aubio_pitch_yin,
+        aubio_pitch_mcomb,
+        aubio_pitch_schmitt,
+        aubio_pitch_fcomb
 } aubio_pitchdetection_type;
 
 typedef enum {
-	aubio_freq,
-	aubio_midi,
-	aubio_cent,
-	aubio_bin
+        aubio_pitchm_freq,
+        aubio_pitchm_midi,
+        aubio_pitchm_cent,
+        aubio_pitchm_bin
 } aubio_pitchdetection_mode;
 
 typedef struct _aubio_pitchdetection_t aubio_pitchdetection_t;
--- a/swig/aubio.i
+++ b/swig/aubio.i
@@ -51,14 +51,14 @@
 
 
 /* sndfile */
-extern aubio_file_t * new_file_ro (const char * inputfile);
-extern aubio_file_t * new_file_wo(aubio_file_t * existingfile, const char * outputname);
-extern void file_info(aubio_file_t * file);
-extern int file_write(aubio_file_t * file, int frames, fvec_t * write);
-extern int file_read(aubio_file_t * file, int frames, fvec_t * read);
-extern int del_file(aubio_file_t * file);
-extern uint_t aubio_file_channels(aubio_file_t * file);
-extern uint_t aubio_file_samplerate(aubio_file_t * file);
+extern aubio_sndfile_t * new_aubio_sndfile_ro (const char * inputfile);
+extern aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * existingfile, const char * outputname);
+extern void aubio_sndfile_info(aubio_sndfile_t * file);
+extern int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write);
+extern int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read);
+extern int del_aubio_sndfile(aubio_sndfile_t * file);
+extern uint_t aubio_sndfile_channels(aubio_sndfile_t * file);
+extern uint_t aubio_sndfile_samplerate(aubio_sndfile_t * file);
 
 /* fft */
 extern void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size);
@@ -158,17 +158,17 @@
 
 /* pitch detection */
 typedef enum {
-	aubio_yin,
-	aubio_mcomb,
-        aubio_schmitt,
-        aubio_fcomb
+        aubio_pitch_yin,
+        aubio_pitch_mcomb,
+        aubio_pitch_schmitt,
+        aubio_pitch_fcomb
 } aubio_pitchdetection_type;
 
 typedef enum {
-	aubio_freq,
-	aubio_midi,
-	aubio_cent,
-	aubio_bin
+        aubio_pitchm_freq,
+        aubio_pitchm_midi,
+        aubio_pitchm_cent,
+        aubio_pitchm_bin
 } aubio_pitchdetection_mode;
 
 smpl_t aubio_pitchdetection(aubio_pitchdetection_t * p, fvec_t * ibuf);