Desirable goals » History » Version 2

« Previous - Version 2/5 (diff) - Next » - Current version
Chris Cannam, 2015-01-12 12:15 PM


Desirable goals

Dan writes:

I would request that a function returning data block-by-block should be a generator which would make
it very flexible, and could also be used to avoid having to have all the data in memory at once.

...

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:

# 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)

BTW I noticed I made a couple of mistakes in there