python/aubio: more changes for mono
authorPaul Brossier <piem@piem.org>
Wed, 14 Apr 2010 15:36:49 +0000 (17:36 +0200)
committerPaul Brossier <piem@piem.org>
Wed, 14 Apr 2010 15:36:49 +0000 (17:36 +0200)
python/aubio/aubioclass.py
python/aubio/task/onset.py
python/aubio/task/pitch.py
python/aubio/task/task.py

index ded9548559562e84c591b5ac4f2533825d24b4a9..dd13775ce611ef29d259e3870f5f2292adb39c4c 100644 (file)
@@ -1,40 +1,38 @@
 from aubiowrapper import *
 
 class fvec:
-    def __init__(self,size,chan):
-        self.vec = new_fvec(size,chan)
+    def __init__(self,size):
+        self.vec = new_fvec(size)
     def __call__(self):
         return self.vec
     def __del__(self):
         del_fvec(self())
-    def get(self,pos,chan):
-        return fvec_read_sample(self(),chan,pos)
-    def set(self,value,pos,chan):
-        return fvec_write_sample(self(),value,chan,pos)
-    def channel(self,chan):
-        return fvec_get_channel(self(),chan)
+    def get(self,pos):
+        return fvec_read_sample(self(),pos)
+    def set(self,value,pos):
+        return fvec_write_sample(self(),value,pos)
     def data(self):
         return fvec_get_data(self())
 
 class cvec:
-    def __init__(self,size,chan):
-        self.vec = new_cvec(size,chan)
+    def __init__(self,size):
+        self.vec = new_cvec(size)
     def __call__(self):
         return self.vec
     def __del__(self):
         del_cvec(self())
-    def get(self,pos,chan):
-        return self.get_norm(pos,chan)
-    def set(self,val,pos,chan):
-        self.set_norm(val,chan,pos)
-    def get_norm(self,pos,chan):
-        return cvec_read_norm(self(),chan,pos)
-    def set_norm(self,val,pos,chan):
-        cvec_write_norm(self(),val,chan,pos)
-    def get_phas(self,pos,chan):
-        return cvec_read_phas(self(),chan,pos)
-    def set_phas(self,val,pos,chan):
-        cvec_write_phas(self(),val,chan,pos)
+    def get(self,pos):
+        return self.get_norm(pos)
+    def set(self,val,pos):
+        self.set_norm(val,pos)
+    def get_norm(self,pos):
+        return cvec_read_norm(self(),pos)
+    def set_norm(self,val,pos):
+        cvec_write_norm(self(),val,pos)
+    def get_phas(self,pos):
+        return cvec_read_phas(self(),pos)
+    def set_phas(self,val,pos):
+        cvec_write_phas(self(),val,pos)
 
 class sndfile:
     def __init__(self,filename,model=None):
@@ -53,13 +51,13 @@ class sndfile:
     def channels(self):
         return aubio_sndfile_channels(self.file)
     def read(self,nfram,vecread):
-        return aubio_sndfile_read(self.file,nfram,vecread())
+        return aubio_sndfile_read_mono(self.file,nfram,vecread())
     def write(self,nfram,vecwrite):
         return aubio_sndfile_write(self.file,nfram,vecwrite())
 
 class pvoc:
-    def __init__(self,buf,hop,chan):
-        self.pv = new_aubio_pvoc(buf,hop,chan)
+    def __init__(self,buf,hop):
+        self.pv = new_aubio_pvoc(buf,hop)
     def __del__(self):
         del_aubio_pvoc(self.pv)
     def do(self,tf,tc):
@@ -69,8 +67,8 @@ class pvoc:
 
 class onsetdetection:
     """ class for aubio_specdesc """
-    def __init__(self,mode,buf,chan):
-        self.od = new_aubio_specdesc(mode,buf,chan)
+    def __init__(self,mode,buf):
+        self.od = new_aubio_specdesc(mode,buf)
     def do(self,tc,tf):
         aubio_specdesc_do(self.od,tc(),tf())
     def __del__(self):
@@ -79,12 +77,12 @@ class onsetdetection:
 class peakpick:
     """ class for aubio_peakpicker """
     def __init__(self,threshold=0.1):
-        self.pp = new_aubio_peakpicker(1)
-        self.out = new_fvec(1, 1)
+        self.pp = new_aubio_peakpicker()
+        self.out = new_fvec(1)
         aubio_peakpicker_set_threshold (self.pp, threshold)
     def do(self,fv):
         aubio_peakpicker_do(self.pp, fv(), self.out)
-        return fvec_read_sample(self.out, 0, 0)
+        return fvec_read_sample(self.out, 0)
     def getval(self):
         return aubio_peakpicker_get_adaptive_threshold(self.pp)
     def __del__(self):
@@ -92,17 +90,17 @@ class peakpick:
 
 class onsetpick:
     """ superclass for aubio_pvoc + aubio_specdesc + aubio_peakpicker """
-    def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False,dcthreshold=0):
-        self.myfft    = cvec(bufsize,channels)
-        self.pv       = pvoc(bufsize,hopsize,channels)
+    def __init__(self,bufsize,hopsize,myvec,threshold,mode='dual',derivate=False,dcthreshold=0):
+        self.myfft    = cvec(bufsize)
+        self.pv       = pvoc(bufsize,hopsize)
         if mode in ['dual'] :
-                self.myod     = onsetdetection("hfc",bufsize,channels)
-                self.myod2    = onsetdetection("mkl",bufsize,channels)
-                self.myonset  = fvec(1,channels)
-                self.myonset2 = fvec(1,channels)
+                self.myod     = onsetdetection("hfc",bufsize)
+                self.myod2    = onsetdetection("mkl",bufsize)
+                self.myonset  = fvec(1)
+                self.myonset2 = fvec(1)
         else: 
-                self.myod     = onsetdetection(mode,bufsize,channels)
-                self.myonset  = fvec(1,channels)
+                self.myod     = onsetdetection(mode,bufsize)
+                self.myonset  = fvec(1)
         self.mode     = mode
         self.pp       = peakpick(float(threshold))
         self.derivate = derivate
@@ -114,24 +112,24 @@ class onsetpick:
         self.myod.do(self.myfft,self.myonset)
         if self.mode == 'dual':
            self.myod2.do(self.myfft,self.myonset2)
-           self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0)
+           self.myonset.set(self.myonset.get(0)*self.myonset2.get(0),0)
         if self.derivate:
-           val         = self.myonset.get(0,0)
+           val         = self.myonset.get(0)
            dval        = val - self.oldval
            self.oldval = val
-           if dval > 0: self.myonset.set(dval,0,0)
+           if dval > 0: self.myonset.set(dval,0)
            else:  self.myonset.set(0.,0,0)
-        isonset, dval = self.pp.do(self.myonset),self.myonset.get(0,0)
+        isonset, dval = self.pp.do(self.myonset),self.myonset.get(0)
         if self.dcthreshold:
            if dval < self.dcthreshold: isonset = 0 
         return isonset, dval
 
 class pitch:
     def __init__(self,mode="mcomb",bufsize=2048,hopsize=1024,
-        channels=1,samplerate=44100.,omode="freq",tolerance=0.1):
-        self.pitchp = new_aubio_pitch(mode,bufsize,hopsize,channels,
+        samplerate=44100.,omode="freq",tolerance=0.1):
+        self.pitchp = new_aubio_pitch(mode,bufsize,hopsize,
             samplerate)
-        self.mypitch = fvec(1, channels)
+        self.mypitch = fvec(1)
         aubio_pitch_set_unit(self.pitchp,omode)
         aubio_pitch_set_tolerance(self.pitchp,tolerance)
         #self.filt     = filter(srate,"adsgn")
@@ -139,7 +137,7 @@ class pitch:
         del_aubio_pitch(self.pitchp)
     def __call__(self,myvec): 
         aubio_pitch_do(self.pitchp,myvec(), self.mypitch())
-        return self.mypitch.get(0,0)
+        return self.mypitch.get(0)
 
 class filter:
     def __init__(self,srate,type=None):
index 83835b8ef849f88e3213b37f2abc9ac426d6de32..71117b0694412782e1b3ba39b2bd8a95f084df49 100644 (file)
@@ -9,7 +9,6 @@ class taskonset(task):
                task.__init__(self,input,params=params)
                self.opick = onsetpick(self.params.bufsize,
                        self.params.hopsize,
-                       self.channels,
                        self.myvec,
                        self.params.threshold,
                        mode=self.params.onsetmode,
index 7573c57809fa5942b571ba0f936733e1b15402f8..643b1c231d272026dfb813ecf22adc51e47a17a4 100644 (file)
@@ -15,7 +15,6 @@ class taskpitch(task):
                self.pitchdet   = pitch(mode=self.params.pitchmode,
                        bufsize=self.params.bufsize,
                        hopsize=self.params.hopsize,
-                       channels=self.channels,
                        samplerate=self.srate,
                        omode=self.params.omode,
                        tolerance = tolerance)
index 8979f3b0e1a63a9adad6429dda7b623b0208f3f0..9ad61c27611593c1e74d79c07fdb7c14f98a63f4 100644 (file)
@@ -16,9 +16,8 @@ class task(taskparams):
                self.input     = input
                self.filei     = sndfile(self.input)
                self.srate     = self.filei.samplerate()
-               self.channels  = self.filei.channels()
                self.params.step = float(self.params.hopsize)/float(self.srate)
-               self.myvec     = fvec(self.params.hopsize,self.channels)
+               self.myvec     = fvec(self.params.hopsize)
                self.output    = output
 
        def __call__(self):