source: python/aubio/aubioclass.py @ 7c206df

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

added support for dcthreshold
added support for dcthreshold

  • Property mode set to 100644
File size: 5.1 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,dcthreshold=0):
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_mkl,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.dcthreshold = dcthreshold
95        self.oldval   = 0.
96
97    def do(self,myvec): 
98        self.pv.do(myvec,self.myfft)
99        self.myod.do(self.myfft,self.myonset)
100        if self.mode == 'dual':
101                self.myod2.do(self.myfft,self.myonset2)
102                self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0)
103        if self.derivate:
104                val         = self.myonset.get(0,0)
105                dval        = val - self.oldval
106                self.oldval = val
107                if dval > 0: self.myonset.set(dval,0,0)
108                else:  self.myonset.set(0.,0,0)
109        if self.dcthreshold:
110                dval        = self.myonset.get(0,0) - self.dcthreshold
111                if dval > 0: self.myonset.set(dval,0,0)
112                else:  self.myonset.set(0.,0,0)
113        return self.pp.do(self.myonset),self.myonset.get(0,0)
114
115class pitchdetection:
116    def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
117        channels=1,samplerate=44100.,omode=aubio_pitchm_freq):
118        self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,
119                samplerate,mode,omode)
120        #self.filt     = filter(srate,"adsgn")
121    def __del__(self):
122        del_aubio_pitchdetection(self.pitchp)
123    def __call__(self,myvec): 
124        #self.filt(myvec)
125        return aubio_pitchdetection(self.pitchp,myvec())
126
127class filter:
128    def __init__(self,srate,type=None):
129        if (type=="adsgn"):
130            self.filter = new_aubio_adsgn_filter(srate)
131    def __del__(self):
132        #del_aubio_filter(self.filter)
133        pass
134    def __call__(self,myvec):
135        aubio_filter_do(self.filter,myvec())
136
137class beattracking:
138    """ class for aubio_beattracking """
139    def __init__(self,winlen,channels):
140        self.p = new_aubio_beattracking(winlen,channels)
141    def do(self,dfframe,out):
142        return aubio_beattracking_do(self.p,dfframe(),out())
143    def __del__(self):
144        del_aubio_beattracking(self.p)
145
Note: See TracBrowser for help on using the repository browser.