Desirable goals » History » Version 2

Version 1 (Chris Cannam, 2015-01-12 12:14 PM) → Version 2/5 (Chris Cannam, 2015-01-12 12:15 PM)

h1. Desirable goals

Dan writes:

_I would request that a function returning data block-by-block should be a "generator":https://wiki.python.org/moin/Generators which would make
it very flexible, and could also be used to avoid having to have all the data in memory at once._

...

_from
_Well just 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:_

<pre>
# all in-memory:

plug = vh.loadPlugin('vamp-example-plugins:mfcc', 44100)
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]

plug = vh.loadPlugin('vamp-example-plugins:onsetdetector', 44100)
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

# from disk, to memory:

plug = vh.loadPlugin('vamp-example-plugins:mfcc', 44100)
with open(filepath) as f:
mfccs = np.array([features[0] for features in plug.processall(f)])
plt.matshow(mfccs, interpolate='nearest') # a simple pyplot

# fully streaming:

plug = vh.loadPlugin('vamp-example-plugins:mfcc', 44100)
with open(filepath) as f:
with open(outpath, 'wb') as outf:
for features in plug.processall(f):
outpath.write("%g\n" % features[0][0] ** 2)
</pre>

_BTW I noticed I made a couple of mistakes in there_