source: python/aubio/aubioclass.py @ 0484dc1

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

fix norm in aubioclass
fix norm in aubioclass

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