[96fb8ad] | 1 | from aubiowrapper import * |
---|
| 2 | |
---|
| 3 | class 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 | |
---|
| 19 | class 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 | |
---|
| 39 | class 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) |
---|
[96fb8ad] | 45 | def __del__(self): |
---|
[5e9c68a] | 46 | del_aubio_sndfile(self.file) |
---|
[96fb8ad] | 47 | def info(self): |
---|
[5e9c68a] | 48 | aubio_sndfile_info(self.file) |
---|
[96fb8ad] | 49 | def samplerate(self): |
---|
[5e9c68a] | 50 | return aubio_sndfile_samplerate(self.file) |
---|
[96fb8ad] | 51 | def channels(self): |
---|
[5e9c68a] | 52 | return aubio_sndfile_channels(self.file) |
---|
[96fb8ad] | 53 | def read(self,nfram,vecread): |
---|
[5e9c68a] | 54 | return aubio_sndfile_read(self.file,nfram,vecread()) |
---|
[96fb8ad] | 55 | def write(self,nfram,vecwrite): |
---|
[5e9c68a] | 56 | return aubio_sndfile_write(self.file,nfram,vecwrite()) |
---|
[96fb8ad] | 57 | |
---|
| 58 | class pvoc: |
---|
| 59 | def __init__(self,buf,hop,chan): |
---|
| 60 | self.pv = new_aubio_pvoc(buf,hop,chan) |
---|
| 61 | def __del__(self): |
---|
| 62 | del_aubio_pvoc(self.pv) |
---|
| 63 | def do(self,tf,tc): |
---|
| 64 | aubio_pvoc_do(self.pv,tf(),tc()) |
---|
| 65 | def rdo(self,tc,tf): |
---|
| 66 | aubio_pvoc_rdo(self.pv,tc(),tf()) |
---|
| 67 | |
---|
| 68 | class onsetdetection: |
---|
[71f98f1] | 69 | """ class for aubio_onsetdetection """ |
---|
[96fb8ad] | 70 | def __init__(self,type,buf,chan): |
---|
| 71 | self.od = new_aubio_onsetdetection(type,buf,chan) |
---|
| 72 | def do(self,tc,tf): |
---|
| 73 | aubio_onsetdetection(self.od,tc(),tf()) |
---|
| 74 | def __del__(self): |
---|
| 75 | aubio_onsetdetection_free(self.od) |
---|
| 76 | |
---|
| 77 | class peakpick: |
---|
[71f98f1] | 78 | """ class for aubio_peakpicker """ |
---|
[96fb8ad] | 79 | def __init__(self,threshold=0.1): |
---|
| 80 | self.pp = new_aubio_peakpicker(threshold) |
---|
| 81 | def do(self,fv): |
---|
| 82 | return aubio_peakpick_pimrt(fv(),self.pp) |
---|
[27f2c08] | 83 | def getval(self): |
---|
| 84 | return aubio_peakpick_pimrt_getval(self.pp) |
---|
[96fb8ad] | 85 | def __del__(self): |
---|
| 86 | del_aubio_peakpicker(self.pp) |
---|
| 87 | |
---|
| 88 | class onsetpick: |
---|
[71f98f1] | 89 | """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """ |
---|
[897b455] | 90 | def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False,dcthreshold=0): |
---|
[96fb8ad] | 91 | self.myfft = cvec(bufsize,channels) |
---|
| 92 | self.pv = pvoc(bufsize,hopsize,channels) |
---|
[b31f262] | 93 | if mode in ['dual'] : |
---|
[5cf415f] | 94 | self.myod = onsetdetection(aubio_onset_hfc,bufsize,channels) |
---|
[f72a10d] | 95 | self.myod2 = onsetdetection(aubio_onset_mkl,bufsize,channels) |
---|
[19b56b0] | 96 | self.myonset = fvec(1,channels) |
---|
| 97 | self.myonset2 = fvec(1,channels) |
---|
[b31f262] | 98 | else: |
---|
| 99 | self.myod = onsetdetection(mode,bufsize,channels) |
---|
| 100 | self.myonset = fvec(1,channels) |
---|
[19b56b0] | 101 | self.mode = mode |
---|
[96fb8ad] | 102 | self.pp = peakpick(float(threshold)) |
---|
[80c0417] | 103 | self.derivate = derivate |
---|
[cadf07b] | 104 | self.dcthreshold = dcthreshold |
---|
[80c0417] | 105 | self.oldval = 0. |
---|
[96fb8ad] | 106 | |
---|
| 107 | def do(self,myvec): |
---|
| 108 | self.pv.do(myvec,self.myfft) |
---|
| 109 | self.myod.do(self.myfft,self.myonset) |
---|
[19b56b0] | 110 | if self.mode == 'dual': |
---|
[cadf07b] | 111 | self.myod2.do(self.myfft,self.myonset2) |
---|
| 112 | self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0) |
---|
[80c0417] | 113 | if self.derivate: |
---|
[cadf07b] | 114 | val = self.myonset.get(0,0) |
---|
| 115 | dval = val - self.oldval |
---|
| 116 | self.oldval = val |
---|
| 117 | if dval > 0: self.myonset.set(dval,0,0) |
---|
| 118 | else: self.myonset.set(0.,0,0) |
---|
[08f6688] | 119 | isonset, dval = self.pp.do(self.myonset),self.myonset.get(0,0) |
---|
[cadf07b] | 120 | if self.dcthreshold: |
---|
[08f6688] | 121 | if dval < self.dcthreshold: isonset = 0 |
---|
| 122 | return isonset, dval |
---|
[96fb8ad] | 123 | |
---|
[d53e4df] | 124 | class pitchdetection: |
---|
[5e9c68a] | 125 | def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024, |
---|
[4dd235f] | 126 | channels=1,samplerate=44100.,omode=aubio_pitchm_freq,yinthresh=0.1): |
---|
[d53e4df] | 127 | self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels, |
---|
| 128 | samplerate,mode,omode) |
---|
[05468516] | 129 | aubio_pitchdetection_set_yinthresh(self.pitchp,yinthresh) |
---|
[d53e4df] | 130 | #self.filt = filter(srate,"adsgn") |
---|
| 131 | def __del__(self): |
---|
| 132 | del_aubio_pitchdetection(self.pitchp) |
---|
| 133 | def __call__(self,myvec): |
---|
| 134 | #self.filt(myvec) |
---|
| 135 | return aubio_pitchdetection(self.pitchp,myvec()) |
---|
[96fb8ad] | 136 | |
---|
| 137 | class filter: |
---|
| 138 | def __init__(self,srate,type=None): |
---|
| 139 | if (type=="adsgn"): |
---|
| 140 | self.filter = new_aubio_adsgn_filter(srate) |
---|
| 141 | def __del__(self): |
---|
| 142 | #del_aubio_filter(self.filter) |
---|
| 143 | pass |
---|
[d53e4df] | 144 | def __call__(self,myvec): |
---|
[96fb8ad] | 145 | aubio_filter_do(self.filter,myvec()) |
---|
[27f2c08] | 146 | |
---|
| 147 | class beattracking: |
---|
| 148 | """ class for aubio_beattracking """ |
---|
| 149 | def __init__(self,winlen,channels): |
---|
| 150 | self.p = new_aubio_beattracking(winlen,channels) |
---|
| 151 | def do(self,dfframe,out): |
---|
| 152 | return aubio_beattracking_do(self.p,dfframe(),out()) |
---|
| 153 | def __del__(self): |
---|
| 154 | del_aubio_beattracking(self.p) |
---|
| 155 | |
---|