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()) |
---|
26 | |
---|
27 | class sndfile: |
---|
28 | def __init__(self,filename,model=None): |
---|
29 | if (model!=None): |
---|
30 | self.file = new_file_wo(model.file,filename) |
---|
31 | else: |
---|
32 | self.file = new_file_ro(filename) |
---|
33 | def __del__(self): |
---|
34 | del_file(self.file) |
---|
35 | def info(self): |
---|
36 | file_info(self.file) |
---|
37 | def samplerate(self): |
---|
38 | return aubio_file_samplerate(self.file) |
---|
39 | def channels(self): |
---|
40 | return aubio_file_channels(self.file) |
---|
41 | def read(self,nfram,vecread): |
---|
42 | return file_read(self.file,nfram,vecread()) |
---|
43 | def write(self,nfram,vecwrite): |
---|
44 | return file_write(self.file,nfram,vecwrite()) |
---|
45 | |
---|
46 | class pvoc: |
---|
47 | def __init__(self,buf,hop,chan): |
---|
48 | self.pv = new_aubio_pvoc(buf,hop,chan) |
---|
49 | def __del__(self): |
---|
50 | del_aubio_pvoc(self.pv) |
---|
51 | def do(self,tf,tc): |
---|
52 | aubio_pvoc_do(self.pv,tf(),tc()) |
---|
53 | def rdo(self,tc,tf): |
---|
54 | aubio_pvoc_rdo(self.pv,tc(),tf()) |
---|
55 | |
---|
56 | class onsetdetection: |
---|
57 | def __init__(self,type,buf,chan): |
---|
58 | self.od = new_aubio_onsetdetection(type,buf,chan) |
---|
59 | def do(self,tc,tf): |
---|
60 | aubio_onsetdetection(self.od,tc(),tf()) |
---|
61 | def __del__(self): |
---|
62 | aubio_onsetdetection_free(self.od) |
---|
63 | |
---|
64 | class peakpick: |
---|
65 | def __init__(self,threshold=0.1): |
---|
66 | self.pp = new_aubio_peakpicker(threshold) |
---|
67 | def do(self,fv): |
---|
68 | return aubio_peakpick_pimrt(fv(),self.pp) |
---|
69 | def __del__(self): |
---|
70 | del_aubio_peakpicker(self.pp) |
---|
71 | |
---|
72 | class onsetpick: |
---|
73 | def __init__(self,bufsize,hopsize,channels,myvec,threshold): |
---|
74 | self.myfft = cvec(bufsize,channels) |
---|
75 | self.pv = pvoc(bufsize,hopsize,channels) |
---|
76 | self.myod = onsetdetection(hfc,bufsize,channels) |
---|
77 | self.myod2 = onsetdetection(complexdomain,bufsize,channels) |
---|
78 | self.myonset = fvec(1,channels) |
---|
79 | self.myonset2 = fvec(1,channels) |
---|
80 | self.pp = peakpick(float(threshold)) |
---|
81 | |
---|
82 | def do(self,myvec): |
---|
83 | self.pv.do(myvec,self.myfft) |
---|
84 | self.myod.do(self.myfft,self.myonset) |
---|
85 | self.myod2.do(self.myfft,self.myonset2) |
---|
86 | self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0) |
---|
87 | return self.pp.do(self.myonset),self.myonset.get(0,0) |
---|
88 | |
---|
89 | class pitchpick: |
---|
90 | def __init__(self,bufsize,hopsize,channels,myvec,srate): |
---|
91 | self.myfft = cvec(bufsize,channels) |
---|
92 | self.pv = pvoc(bufsize,hopsize,channels) |
---|
93 | self.pitchp = new_aubio_pitchmcomb(bufsize,channels) |
---|
94 | self.filt = filter(srate,"adsgn") |
---|
95 | |
---|
96 | def do(self,myvec): |
---|
97 | #self.filt.do(myvec) |
---|
98 | #self.filt.do(myvec) |
---|
99 | self.pv.do(myvec,self.myfft) |
---|
100 | return aubio_pitchmcomb_detect(self.pitchp,self.myfft()) |
---|
101 | |
---|
102 | class filter: |
---|
103 | def __init__(self,srate,type=None): |
---|
104 | if (type=="adsgn"): |
---|
105 | self.filter = new_aubio_adsgn_filter(srate) |
---|
106 | def __del__(self): |
---|
107 | #del_aubio_filter(self.filter) |
---|
108 | pass |
---|
109 | def do(self,myvec): |
---|
110 | aubio_filter_do(self.filter,myvec()) |
---|