source: python/aubio/aubioclass.py @ 677b267

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

adds peakpick_pimrt_getval and beattracking functions
adds peakpick_pimrt_getval and beattracking functions

  • Property mode set to 100644
File size: 4.8 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 getval(self):
74        return aubio_peakpick_pimrt_getval(self.pp)
75    def __del__(self):
76        del_aubio_peakpicker(self.pp)
77
78class onsetpick:
79    """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """
80    def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False):
81        self.myfft    = cvec(bufsize,channels)
82        self.pv       = pvoc(bufsize,hopsize,channels)
83        if mode in ['dual'] :
84                self.myod     = onsetdetection(aubio_onset_hfc,bufsize,channels)
85                self.myod2    = onsetdetection(aubio_onset_complex,bufsize,channels)
86                self.myonset  = fvec(1,channels)
87                self.myonset2 = fvec(1,channels)
88        else: 
89                self.myod     = onsetdetection(mode,bufsize,channels)
90                self.myonset  = fvec(1,channels)
91        self.mode     = mode
92        self.pp       = peakpick(float(threshold))
93        self.derivate = derivate
94        self.oldval   = 0.
95
96    def do(self,myvec): 
97        self.pv.do(myvec,self.myfft)
98        self.myod.do(self.myfft,self.myonset)
99        if self.mode == 'dual':
100                self.myod2.do(self.myfft,self.myonset2)
101                self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0)
102        if self.derivate:
103                val         = self.myonset.get(0,0)
104                dval        = val - self.oldval
105                self.oldval = val
106                if dval > 0: self.myonset.set(dval,0,0)
107                else:  self.myonset.set(0.,0,0)
108        return self.pp.do(self.myonset),self.myonset.get(0,0)
109
110class pitchdetection:
111    def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
112        channels=1,samplerate=44100.,omode=aubio_pitchm_freq):
113        self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,
114                samplerate,mode,omode)
115        #self.filt     = filter(srate,"adsgn")
116    def __del__(self):
117        del_aubio_pitchdetection(self.pitchp)
118    def __call__(self,myvec): 
119        #self.filt(myvec)
120        return aubio_pitchdetection(self.pitchp,myvec())
121
122class filter:
123    def __init__(self,srate,type=None):
124        if (type=="adsgn"):
125            self.filter = new_aubio_adsgn_filter(srate)
126    def __del__(self):
127        #del_aubio_filter(self.filter)
128        pass
129    def __call__(self,myvec):
130        aubio_filter_do(self.filter,myvec())
131
132class beattracking:
133    """ class for aubio_beattracking """
134    def __init__(self,winlen,channels):
135        self.p = new_aubio_beattracking(winlen,channels)
136    def do(self,dfframe,out):
137        return aubio_beattracking_do(self.p,dfframe(),out())
138    def __del__(self):
139        del_aubio_beattracking(self.p)
140
Note: See TracBrowser for help on using the repository browser.