[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): |
---|
| 27 | return fvec_read_sample(self(),chan,pos) |
---|
[96fb8ad] | 28 | |
---|
| 29 | class sndfile: |
---|
| 30 | def __init__(self,filename,model=None): |
---|
| 31 | if (model!=None): |
---|
[5e9c68a] | 32 | self.file = new_aubio_sndfile_wo(model.file,filename) |
---|
[96fb8ad] | 33 | else: |
---|
[5e9c68a] | 34 | self.file = new_aubio_sndfile_ro(filename) |
---|
[96fb8ad] | 35 | def __del__(self): |
---|
[5e9c68a] | 36 | del_aubio_sndfile(self.file) |
---|
[96fb8ad] | 37 | def info(self): |
---|
[5e9c68a] | 38 | aubio_sndfile_info(self.file) |
---|
[96fb8ad] | 39 | def samplerate(self): |
---|
[5e9c68a] | 40 | return aubio_sndfile_samplerate(self.file) |
---|
[96fb8ad] | 41 | def channels(self): |
---|
[5e9c68a] | 42 | return aubio_sndfile_channels(self.file) |
---|
[96fb8ad] | 43 | def read(self,nfram,vecread): |
---|
[5e9c68a] | 44 | return aubio_sndfile_read(self.file,nfram,vecread()) |
---|
[96fb8ad] | 45 | def write(self,nfram,vecwrite): |
---|
[5e9c68a] | 46 | return aubio_sndfile_write(self.file,nfram,vecwrite()) |
---|
[96fb8ad] | 47 | |
---|
| 48 | class 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 | |
---|
| 58 | class onsetdetection: |
---|
[71f98f1] | 59 | """ class for aubio_onsetdetection """ |
---|
[96fb8ad] | 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 | |
---|
| 67 | class peakpick: |
---|
[71f98f1] | 68 | """ class for aubio_peakpicker """ |
---|
[96fb8ad] | 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) |
---|
[27f2c08] | 73 | def getval(self): |
---|
| 74 | return aubio_peakpick_pimrt_getval(self.pp) |
---|
[96fb8ad] | 75 | def __del__(self): |
---|
| 76 | del_aubio_peakpicker(self.pp) |
---|
| 77 | |
---|
| 78 | class onsetpick: |
---|
[71f98f1] | 79 | """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """ |
---|
[80c0417] | 80 | def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False): |
---|
[96fb8ad] | 81 | self.myfft = cvec(bufsize,channels) |
---|
| 82 | self.pv = pvoc(bufsize,hopsize,channels) |
---|
[b31f262] | 83 | if mode in ['dual'] : |
---|
[5cf415f] | 84 | self.myod = onsetdetection(aubio_onset_hfc,bufsize,channels) |
---|
[f72a10d] | 85 | self.myod2 = onsetdetection(aubio_onset_mkl,bufsize,channels) |
---|
[19b56b0] | 86 | self.myonset = fvec(1,channels) |
---|
| 87 | self.myonset2 = fvec(1,channels) |
---|
[b31f262] | 88 | else: |
---|
| 89 | self.myod = onsetdetection(mode,bufsize,channels) |
---|
| 90 | self.myonset = fvec(1,channels) |
---|
[19b56b0] | 91 | self.mode = mode |
---|
[96fb8ad] | 92 | self.pp = peakpick(float(threshold)) |
---|
[80c0417] | 93 | self.derivate = derivate |
---|
| 94 | self.oldval = 0. |
---|
[96fb8ad] | 95 | |
---|
| 96 | def do(self,myvec): |
---|
| 97 | self.pv.do(myvec,self.myfft) |
---|
| 98 | self.myod.do(self.myfft,self.myonset) |
---|
[19b56b0] | 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) |
---|
[80c0417] | 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) |
---|
[96fb8ad] | 108 | return self.pp.do(self.myonset),self.myonset.get(0,0) |
---|
| 109 | |
---|
[d53e4df] | 110 | class pitchdetection: |
---|
[5e9c68a] | 111 | def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024, |
---|
| 112 | channels=1,samplerate=44100.,omode=aubio_pitchm_freq): |
---|
[d53e4df] | 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()) |
---|
[96fb8ad] | 121 | |
---|
| 122 | class 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 |
---|
[d53e4df] | 129 | def __call__(self,myvec): |
---|
[96fb8ad] | 130 | aubio_filter_do(self.filter,myvec()) |
---|
[27f2c08] | 131 | |
---|
| 132 | class 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 | |
---|