annotate vamp/__init__.py @ 56:3db99d3f2e30

Start Python module, add framer
author Chris Cannam
date Wed, 14 Jan 2015 09:52:33 +0000
parents
children c444be7637c0
rev   line source
Chris@56 1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.'''
Chris@56 2
Chris@56 3 import vampyhost
Chris@56 4 import numpy
Chris@56 5
Chris@56 6 def listPlugins():
Chris@56 7 return vampyhost.listPlugins()
Chris@56 8
Chris@56 9 def framesFromArray(arr, stepSize, frameSize):
Chris@56 10 """Generate a list of frames of size frameSize, extracted from the input array arr at stepSize intervals"""
Chris@56 11 # presumably such a function exists in many places, but I need practice
Chris@56 12 assert(stepSize > 0)
Chris@56 13 if arr.ndim == 1: # turn 1d into 2d array with 1 channel
Chris@56 14 arr = numpy.reshape(arr, (1, arr.shape[0]))
Chris@56 15 assert(arr.ndim == 2)
Chris@56 16 n = arr.shape[1]
Chris@56 17 i = 0
Chris@56 18 while (i < n):
Chris@56 19 frame = arr[:, i : i + frameSize]
Chris@56 20 w = frame.shape[1]
Chris@56 21 if (w < frameSize):
Chris@56 22 pad = numpy.zeros((frame.shape[0], frameSize - w))
Chris@56 23 frame = numpy.concatenate((frame, pad), 1)
Chris@56 24 yield frame
Chris@56 25 i = i + stepSize
Chris@56 26
Chris@56 27 def process(data, samplerate, key, parameters, outputs):
Chris@56 28 plug = vampyhost.loadPlugin(key, samplerate, vampyhost.AdaptNone) ##!!! input domain
Chris@56 29 stepSize = plug.getPreferredStepSize()
Chris@56 30 blockSize = plug.getPreferredBlockSize()
Chris@56 31 ff = framesFromArray(data, stepSize, blockSize)
Chris@56 32 return True