Desirable goals » History » Version 2

Chris Cannam, 2015-01-12 12:15 PM

1 1 Chris Cannam
h1. Desirable goals
2 1 Chris Cannam
3 1 Chris Cannam
Dan writes:
4 1 Chris Cannam
5 2 Chris Cannam
_I would request that a function returning data block-by-block should be a "generator":https://wiki.python.org/moin/Generators which would make
6 2 Chris Cannam
it very flexible, and could also be used to avoid having to have all the data in memory at once._
7 2 Chris Cannam
8 2 Chris Cannam
...
9 2 Chris Cannam
10 2 Chris Cannam
_from my point of view, and not having thought through all the flexible types of output that vamp provides, I'd be hoping to type things like:_
11 1 Chris Cannam
12 1 Chris Cannam
<pre>
13 1 Chris Cannam
# all in-memory:
14 1 Chris Cannam
15 1 Chris Cannam
plug = vh.loadPlugin('vamp-example-plugins:mfcc', 44100)
16 1 Chris Cannam
mfccs = np.array([features[0] for features in plug.processall([-0.1, 0, 0.1, 0, -0.1, 0, 0.1, 0])])  # this gives a 2D numpy array of shape [nframes, nmfccs]
17 1 Chris Cannam
18 1 Chris Cannam
plug = vh.loadPlugin('vamp-example-plugins:onsetdetector', 44100)
19 1 Chris Cannam
onsets = np.array([features[0] for features in plug.processall([-0.1, 0, 0.1, 0, -0.1, 0, 0.1, 0])])  # this gives a 1D numpy array, a list of onset times I guess
20 1 Chris Cannam
21 1 Chris Cannam
22 1 Chris Cannam
# from disk, to memory:
23 1 Chris Cannam
24 1 Chris Cannam
plug = vh.loadPlugin('vamp-example-plugins:mfcc', 44100)
25 1 Chris Cannam
with open(filepath) as f:
26 1 Chris Cannam
	mfccs = np.array([features[0] for features in plug.processall(f)])
27 1 Chris Cannam
plt.matshow(mfccs, interpolate='nearest') # a simple pyplot
28 1 Chris Cannam
29 1 Chris Cannam
30 1 Chris Cannam
# fully streaming:
31 1 Chris Cannam
32 1 Chris Cannam
plug = vh.loadPlugin('vamp-example-plugins:mfcc', 44100)
33 1 Chris Cannam
with open(filepath) as f:
34 1 Chris Cannam
	with open(outpath, 'wb') as outf:
35 1 Chris Cannam
		for features in plug.processall(f):
36 1 Chris Cannam
			outpath.write("%g\n" % features[0][0] ** 2)
37 1 Chris Cannam
</pre>
38 1 Chris Cannam
39 1 Chris Cannam
_BTW I noticed I made a couple of mistakes in there_