[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) |
---|
| 73 | def __del__(self): |
---|
| 74 | del_aubio_peakpicker(self.pp) |
---|
| 75 | |
---|
| 76 | class onsetpick: |
---|
[71f98f1] | 77 | """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """ |
---|
[80c0417] | 78 | def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False): |
---|
[96fb8ad] | 79 | self.myfft = cvec(bufsize,channels) |
---|
| 80 | self.pv = pvoc(bufsize,hopsize,channels) |
---|
[b31f262] | 81 | if mode in ['dual'] : |
---|
[5cf415f] | 82 | self.myod = onsetdetection(aubio_onset_hfc,bufsize,channels) |
---|
| 83 | self.myod2 = onsetdetection(aubio_onset_complex,bufsize,channels) |
---|
[19b56b0] | 84 | self.myonset = fvec(1,channels) |
---|
| 85 | self.myonset2 = fvec(1,channels) |
---|
[b31f262] | 86 | else: |
---|
| 87 | self.myod = onsetdetection(mode,bufsize,channels) |
---|
| 88 | self.myonset = fvec(1,channels) |
---|
[19b56b0] | 89 | self.mode = mode |
---|
[96fb8ad] | 90 | self.pp = peakpick(float(threshold)) |
---|
[80c0417] | 91 | self.derivate = derivate |
---|
| 92 | self.oldval = 0. |
---|
[96fb8ad] | 93 | |
---|
| 94 | def do(self,myvec): |
---|
| 95 | self.pv.do(myvec,self.myfft) |
---|
| 96 | self.myod.do(self.myfft,self.myonset) |
---|
[19b56b0] | 97 | if self.mode == 'dual': |
---|
| 98 | self.myod2.do(self.myfft,self.myonset2) |
---|
| 99 | self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0) |
---|
[80c0417] | 100 | if self.derivate: |
---|
| 101 | val = self.myonset.get(0,0) |
---|
| 102 | dval = val - self.oldval |
---|
| 103 | self.oldval = val |
---|
| 104 | if dval > 0: self.myonset.set(dval,0,0) |
---|
| 105 | else: self.myonset.set(0.,0,0) |
---|
[96fb8ad] | 106 | return self.pp.do(self.myonset),self.myonset.get(0,0) |
---|
| 107 | |
---|
[d53e4df] | 108 | class pitchdetection: |
---|
[5e9c68a] | 109 | def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024, |
---|
| 110 | channels=1,samplerate=44100.,omode=aubio_pitchm_freq): |
---|
[d53e4df] | 111 | self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels, |
---|
| 112 | samplerate,mode,omode) |
---|
| 113 | #self.filt = filter(srate,"adsgn") |
---|
| 114 | def __del__(self): |
---|
| 115 | del_aubio_pitchdetection(self.pitchp) |
---|
| 116 | def __call__(self,myvec): |
---|
| 117 | #self.filt(myvec) |
---|
| 118 | return aubio_pitchdetection(self.pitchp,myvec()) |
---|
[96fb8ad] | 119 | |
---|
| 120 | class filter: |
---|
| 121 | def __init__(self,srate,type=None): |
---|
| 122 | if (type=="adsgn"): |
---|
| 123 | self.filter = new_aubio_adsgn_filter(srate) |
---|
| 124 | def __del__(self): |
---|
| 125 | #del_aubio_filter(self.filter) |
---|
| 126 | pass |
---|
[d53e4df] | 127 | def __call__(self,myvec): |
---|
[96fb8ad] | 128 | aubio_filter_do(self.filter,myvec()) |
---|