source: python/aubio/aubioclass.py @ 31a5c0e8

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 31a5c0e8 was 634d238, checked in by Paul Brossier <piem@piem.org>, 15 years ago

python/aubio/aubioclass.py: print filename of file that failed opening

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[96fb8ad]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())
[b8976d6]26    def get(self,pos,chan):
[c7713b2]27        return self.get_norm(pos,chan)
28    def set(self,val,pos,chan):
29        self.set_norm(val,chan,pos)
30    def get_norm(self,pos,chan):
[dcc8d90]31        return cvec_read_norm(self(),chan,pos)
[c7713b2]32    def set_norm(self,val,pos,chan):
33        cvec_write_norm(self(),val,chan,pos)
34    def get_phas(self,pos,chan):
35        return cvec_read_phas(self(),chan,pos)
36    def set_phas(self,val,pos,chan):
37        cvec_write_phas(self(),val,chan,pos)
[96fb8ad]38
39class sndfile:
40    def __init__(self,filename,model=None):
41        if (model!=None):
[5e9c68a]42            self.file = new_aubio_sndfile_wo(model.file,filename)
[96fb8ad]43        else:
[5e9c68a]44            self.file = new_aubio_sndfile_ro(filename)
[634d238]45        if self.file == None:
46            raise(ValueError, "failed opening file %s" % filename)
[96fb8ad]47    def __del__(self):
[cea30b8]48        if self.file != None: del_aubio_sndfile(self.file)
[96fb8ad]49    def info(self):
[5e9c68a]50        aubio_sndfile_info(self.file)
[96fb8ad]51    def samplerate(self):
[5e9c68a]52        return aubio_sndfile_samplerate(self.file)
[96fb8ad]53    def channels(self):
[5e9c68a]54        return aubio_sndfile_channels(self.file)
[96fb8ad]55    def read(self,nfram,vecread):
[5e9c68a]56        return aubio_sndfile_read(self.file,nfram,vecread())
[96fb8ad]57    def write(self,nfram,vecwrite):
[5e9c68a]58        return aubio_sndfile_write(self.file,nfram,vecwrite())
[96fb8ad]59
60class pvoc:
61    def __init__(self,buf,hop,chan):
62        self.pv = new_aubio_pvoc(buf,hop,chan)
63    def __del__(self):
64        del_aubio_pvoc(self.pv)
65    def do(self,tf,tc):
66        aubio_pvoc_do(self.pv,tf(),tc())
67    def rdo(self,tc,tf):
68        aubio_pvoc_rdo(self.pv,tc(),tf())
69
70class onsetdetection:
[71f98f1]71    """ class for aubio_onsetdetection """
[96fb8ad]72    def __init__(self,type,buf,chan):
73        self.od = new_aubio_onsetdetection(type,buf,chan)
74    def do(self,tc,tf):
75        aubio_onsetdetection(self.od,tc(),tf())
76    def __del__(self):
[2a00568]77        del_aubio_onsetdetection(self.od)
[96fb8ad]78
79class peakpick:
[71f98f1]80    """ class for aubio_peakpicker """
[96fb8ad]81    def __init__(self,threshold=0.1):
82        self.pp = new_aubio_peakpicker(threshold)
83    def do(self,fv):
84        return aubio_peakpick_pimrt(fv(),self.pp)
[27f2c08]85    def getval(self):
86        return aubio_peakpick_pimrt_getval(self.pp)
[96fb8ad]87    def __del__(self):
88        del_aubio_peakpicker(self.pp)
89
90class onsetpick:
[71f98f1]91    """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """
[897b455]92    def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False,dcthreshold=0):
[96fb8ad]93        self.myfft    = cvec(bufsize,channels)
94        self.pv       = pvoc(bufsize,hopsize,channels)
[b31f262]95        if mode in ['dual'] :
[5cf415f]96                self.myod     = onsetdetection(aubio_onset_hfc,bufsize,channels)
[f72a10d]97                self.myod2    = onsetdetection(aubio_onset_mkl,bufsize,channels)
[19b56b0]98                self.myonset  = fvec(1,channels)
99                self.myonset2 = fvec(1,channels)
[b31f262]100        else: 
101                self.myod     = onsetdetection(mode,bufsize,channels)
102                self.myonset  = fvec(1,channels)
[19b56b0]103        self.mode     = mode
[96fb8ad]104        self.pp       = peakpick(float(threshold))
[80c0417]105        self.derivate = derivate
[cadf07b]106        self.dcthreshold = dcthreshold
[80c0417]107        self.oldval   = 0.
[96fb8ad]108
109    def do(self,myvec): 
110        self.pv.do(myvec,self.myfft)
111        self.myod.do(self.myfft,self.myonset)
[19b56b0]112        if self.mode == 'dual':
[cadf07b]113           self.myod2.do(self.myfft,self.myonset2)
114           self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0)
[80c0417]115        if self.derivate:
[cadf07b]116           val         = self.myonset.get(0,0)
117           dval        = val - self.oldval
118           self.oldval = val
119           if dval > 0: self.myonset.set(dval,0,0)
120           else:  self.myonset.set(0.,0,0)
[08f6688]121        isonset, dval = self.pp.do(self.myonset),self.myonset.get(0,0)
[cadf07b]122        if self.dcthreshold:
[08f6688]123           if dval < self.dcthreshold: isonset = 0 
124        return isonset, dval
[96fb8ad]125
[d53e4df]126class pitchdetection:
[5e9c68a]127    def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
[4dd235f]128        channels=1,samplerate=44100.,omode=aubio_pitchm_freq,yinthresh=0.1):
[d53e4df]129        self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,
130                samplerate,mode,omode)
[05468516]131        aubio_pitchdetection_set_yinthresh(self.pitchp,yinthresh)
[d53e4df]132        #self.filt     = filter(srate,"adsgn")
133    def __del__(self):
134        del_aubio_pitchdetection(self.pitchp)
135    def __call__(self,myvec): 
136        #self.filt(myvec)
137        return aubio_pitchdetection(self.pitchp,myvec())
[96fb8ad]138
139class filter:
140    def __init__(self,srate,type=None):
141        if (type=="adsgn"):
142            self.filter = new_aubio_adsgn_filter(srate)
143    def __del__(self):
144        #del_aubio_filter(self.filter)
145        pass
[d53e4df]146    def __call__(self,myvec):
[96fb8ad]147        aubio_filter_do(self.filter,myvec())
[27f2c08]148
149class beattracking:
150    """ class for aubio_beattracking """
151    def __init__(self,winlen,channels):
152        self.p = new_aubio_beattracking(winlen,channels)
153    def do(self,dfframe,out):
154        return aubio_beattracking_do(self.p,dfframe(),out())
155    def __del__(self):
156        del_aubio_beattracking(self.p)
157
Note: See TracBrowser for help on using the repository browser.