Mercurial > hg > vampy-host
comparison vampyhost_test.py @ 0:68f3f32565b4
Import the early draft version
author | Chris Cannam |
---|---|
date | Mon, 22 Oct 2012 16:10:46 +0100 |
parents | |
children | cb0d3af1be4d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:68f3f32565b4 |
---|---|
1 | |
2 import sys | |
3 sys.path.append('/Users/Shared/Development/python-extensions') | |
4 sys.path.append('/Users/Shared/Development/vampy-host-experiments/') | |
5 #from melscale import melscale | |
6 #from melscale import initialize | |
7 import wave | |
8 from wave import * | |
9 from pylab import * | |
10 # from melscale import * | |
11 from numpy import * | |
12 from pylab import * | |
13 from time import * | |
14 | |
15 from vampyhost import * | |
16 import vampyhost | |
17 import vampyhost as vh | |
18 #import pyRealTime | |
19 #from pyRealTime import * | |
20 | |
21 | |
22 #deal with an audio file | |
23 wavfile='/Users/Shared/multitrack (small)/mix.wav' | |
24 | |
25 wavobj = wave.open(wavfile,'r') | |
26 samplerate = wavobj.getframerate() | |
27 print "samplerate: ",samplerate | |
28 print "number of samples (frames): ",wavobj.getnframes() #total number of samples 4647744 | |
29 channels = wavobj.getnchannels(); | |
30 print "channels: ",channels | |
31 print "sample-width: ",wavobj.getsampwidth() | |
32 print "position: ",wavobj.tell() | |
33 wavobj.setpos(1000000) | |
34 | |
35 print wavobj.tell() | |
36 audio = wavobj.readframes(1024) #returns an 8-bit buffer | |
37 print wavobj.tell() | |
38 print dir(audio) | |
39 print len(audio) | |
40 wavobj.close() | |
41 | |
42 | |
43 | |
44 rt=realtime(4,70) | |
45 | |
46 #test RealTime Object | |
47 for i in [0,1,2] : | |
48 if (i==0) : rtl=[] | |
49 rtl.append(realtime()) | |
50 print ">>>>>RealTime's method: ", rtl[i].values() | |
51 | |
52 | |
53 class feature_example(): | |
54 def __init__(self): | |
55 self.hasTimestamp | |
56 self.timestamp | |
57 self.values | |
58 self.label | |
59 | |
60 pluginlist = vh.enumeratePlugins() | |
61 for i,n in enumerate(pluginlist) : print i,":",n | |
62 pluginKey=pluginlist[12]; | |
63 | |
64 retval = vh.getLibraryPath(pluginKey) | |
65 print pluginKey | |
66 print retval | |
67 | |
68 print vh.getPluginCategory(pluginKey) | |
69 print vh.getOutputList(pluginKey) | |
70 handle = vh.loadPlugin(pluginKey,samplerate); | |
71 print "\n\nPlugin handle: ",handle | |
72 | |
73 print "Output list of: ",pluginKey,"\n",vh.getOutputList(handle) | |
74 | |
75 #initialise: pluginhandle, channels, stepSize, blockSize | |
76 vh.initialise(handle,1,1024,1024) | |
77 | |
78 rt=frame2RealTime(100000,22050) | |
79 print type(rt) | |
80 | |
81 out=vh.process(handle,audio,rt) | |
82 output = vh.getOutput(handle,1); | |
83 | |
84 print type(output) | |
85 print output | |
86 #print output[1].label | |
87 | |
88 print "_______________OUTPUT TYPE_________:",type(out) | |
89 in_audio = frombuffer(audio,int16,-1,0) | |
90 out_audio = frombuffer(out,float32,-1,0) | |
91 subplot(211) | |
92 plot(in_audio) | |
93 subplot(212) | |
94 plot(out_audio) | |
95 | |
96 show() | |
97 #do some processing here | |
98 | |
99 #buffer is a multichannel frame or a numpy array containing samples | |
100 #buffer = vh.frame(audiodata,stepSize,blockSize) | |
101 | |
102 #output = vh.process(handle,buffer) | |
103 | |
104 #output is a list of list of features | |
105 | |
106 vh.unloadPlugin(handle); | |
107 vh.unloadPlugin(handle); # test if it chrashes... | |
108 | |
109 print vh.getOutputList(handle) | |
110 | |
111 #cases: | |
112 #buffer = blockSize : evaluate | |
113 #buffer > blockSize : enframe and zeropad | |
114 #return: | |
115 #oneSamplePerStep, FixedSamplerate : can return numpy array | |
116 #variableSamplerate : list of featres only | |
117 | |
118 #print dir(vampyhost) |