source: python/aubio/aubioclass.py @ 2bd1a2a

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 2bd1a2a was 5e491b3b, checked in by Paul Brossier <piem@altern.org>, 19 years ago

massive changes from cam

  • Property mode set to 100644
File size: 4.5 KB
Line 
1from aubiowrapper import *
2
3class fvec:
4    def __init__(self,size,chan):
5        self.vec = new_fvec(size,chan)
6    def __call__(self):
7        return self.vec
8    def __del__(self):
9        del_fvec(self())
10    def get(self,pos,chan):
11        return fvec_read_sample(self(),chan,pos)
12    def set(self,value,pos,chan):
13        return fvec_write_sample(self(),value,chan,pos)
14    def channel(self,chan):
15        return fvec_get_channel(self(),chan)
16    def data(self):
17        return fvec_get_data(self())
18
19class cvec:
20    def __init__(self,size,chan):
21        self.vec = new_cvec(size,chan)
22    def __call__(self):
23        return self.vec
24    def __del__(self):
25        del_cvec(self())
26    def get(self,pos,chan):
27        return fvec_read_sample(self(),chan,pos)
28
29class sndfile:
30    def __init__(self,filename,model=None):
31        if (model!=None):
32            self.file = new_aubio_sndfile_wo(model.file,filename)
33        else:
34            self.file = new_aubio_sndfile_ro(filename)
35    def __del__(self):
36        del_aubio_sndfile(self.file)
37    def info(self):
38        aubio_sndfile_info(self.file)
39    def samplerate(self):
40        return aubio_sndfile_samplerate(self.file)
41    def channels(self):
42        return aubio_sndfile_channels(self.file)
43    def read(self,nfram,vecread):
44        return aubio_sndfile_read(self.file,nfram,vecread())
45    def write(self,nfram,vecwrite):
46        return aubio_sndfile_write(self.file,nfram,vecwrite())
47
48class pvoc:
49    def __init__(self,buf,hop,chan):
50        self.pv = new_aubio_pvoc(buf,hop,chan)
51    def __del__(self):
52        del_aubio_pvoc(self.pv)
53    def do(self,tf,tc):
54        aubio_pvoc_do(self.pv,tf(),tc())
55    def rdo(self,tc,tf):
56        aubio_pvoc_rdo(self.pv,tc(),tf())
57
58class onsetdetection:
59    """ class for aubio_onsetdetection """
60    def __init__(self,type,buf,chan):
61        self.od = new_aubio_onsetdetection(type,buf,chan)
62    def do(self,tc,tf):
63        aubio_onsetdetection(self.od,tc(),tf())
64    def __del__(self):
65        aubio_onsetdetection_free(self.od)
66
67class peakpick:
68    """ class for aubio_peakpicker """
69    def __init__(self,threshold=0.1):
70        self.pp = new_aubio_peakpicker(threshold)
71    def do(self,fv):
72        return aubio_peakpick_pimrt(fv(),self.pp)
73    def __del__(self):
74        del_aubio_peakpicker(self.pp)
75
76class onsetpick:
77    """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """
78    def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False):
79        self.myfft    = cvec(bufsize,channels)
80        self.pv       = pvoc(bufsize,hopsize,channels)
81        if mode in ['dual'] :
82                self.myod     = onsetdetection(aubio_onset_hfc,bufsize,channels)
83                self.myod2    = onsetdetection(aubio_onset_complex,bufsize,channels)
84                self.myonset  = fvec(1,channels)
85                self.myonset2 = fvec(1,channels)
86        else: 
87                self.myod     = onsetdetection(mode,bufsize,channels)
88                self.myonset  = fvec(1,channels)
89        self.mode     = mode
90        self.pp       = peakpick(float(threshold))
91        self.derivate = derivate
92        self.oldval   = 0.
93
94    def do(self,myvec): 
95        self.pv.do(myvec,self.myfft)
96        self.myod.do(self.myfft,self.myonset)
97        if self.mode == 'dual':
98                self.myod2.do(self.myfft,self.myonset2)
99                self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0)
100        if self.derivate:
101                val         = self.myonset.get(0,0)
102                dval        = val - self.oldval
103                self.oldval = val
104                if dval > 0: self.myonset.set(dval,0,0)
105                else:  self.myonset.set(0.,0,0)
106        return self.pp.do(self.myonset),self.myonset.get(0,0)
107
108class pitchdetection:
109    def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
110        channels=1,samplerate=44100.,omode=aubio_pitchm_freq):
111        self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,
112                samplerate,mode,omode)
113        #self.filt     = filter(srate,"adsgn")
114    def __del__(self):
115        del_aubio_pitchdetection(self.pitchp)
116    def __call__(self,myvec): 
117        #self.filt(myvec)
118        return aubio_pitchdetection(self.pitchp,myvec())
119
120class filter:
121    def __init__(self,srate,type=None):
122        if (type=="adsgn"):
123            self.filter = new_aubio_adsgn_filter(srate)
124    def __del__(self):
125        #del_aubio_filter(self.filter)
126        pass
127    def __call__(self,myvec):
128        aubio_filter_do(self.filter,myvec())
Note: See TracBrowser for help on using the repository browser.