Mercurial > hg > vampy-host
comparison vamp/__init__.py @ 68:e15e684d2af4
Some tricky tests for returned values from the test plugin
author | Chris Cannam |
---|---|
date | Wed, 14 Jan 2015 14:31:01 +0000 |
parents | 6f6a54963ce8 |
children | ffdeb8808fc1 |
comparison
equal
deleted
inserted
replaced
67:6f6a54963ce8 | 68:e15e684d2af4 |
---|---|
1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.''' | 1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.''' |
2 | |
3 ###!!! todo: move all the real code out of __init__.py | |
2 | 4 |
3 import vampyhost | 5 import vampyhost |
4 import numpy | 6 import numpy |
5 | 7 |
6 def listPlugins(): | 8 def listPlugins(): |
22 pad = numpy.zeros((frame.shape[0], frameSize - w)) | 24 pad = numpy.zeros((frame.shape[0], frameSize - w)) |
23 frame = numpy.concatenate((frame, pad), 1) | 25 frame = numpy.concatenate((frame, pad), 1) |
24 yield frame | 26 yield frame |
25 i = i + stepSize | 27 i = i + stepSize |
26 | 28 |
27 def process(data, samplerate, key, parameters = {}, outputs = []): | 29 |
28 #!!! docstring | 30 def loadAndConfigureFor(data, samplerate, key, parameters): |
29 plug = vampyhost.loadPlugin(key, samplerate, | 31 plug = vampyhost.loadPlugin(key, samplerate, |
30 vampyhost.AdaptInputDomain + | 32 vampyhost.AdaptInputDomain + |
31 vampyhost.AdaptChannelCount) | 33 vampyhost.AdaptChannelCount) |
32 | 34 |
35 plug.setParameterValues(parameters) | |
36 | |
37 stepSize = plug.getPreferredStepSize() | |
38 blockSize = plug.getPreferredBlockSize() | |
39 | |
40 if blockSize == 0: | |
41 blockSize = 1024 | |
42 if stepSize == 0: | |
43 stepSize = blockSize ##!!! or blockSize/2, but check this with input domain adapter | |
44 | |
45 channels = 1 | |
46 if data.ndim > 1: | |
47 channels = data.shape[0] | |
48 | |
49 plug.initialise(channels, stepSize, blockSize) | |
50 return (plug, stepSize, blockSize) | |
51 | |
52 | |
53 def process(data, samplerate, key, parameters = {}, outputs = []): | |
54 #!!! docstring | |
55 | |
56 plug, stepSize, blockSize = loadAndConfigureFor(data, samplerate, key, parameters) | |
57 | |
33 plugOuts = plug.getOutputs() | 58 plugOuts = plug.getOutputs() |
59 if plugOuts == []: | |
60 return | |
34 | 61 |
35 outIndices = dict(zip([o["identifier"] for o in plugOuts], | 62 outIndices = dict(zip([o["identifier"] for o in plugOuts], |
36 range(0, len(plugOuts)))) # id -> n | 63 range(0, len(plugOuts)))) # id -> n |
37 | 64 |
38 for o in outputs: | 65 for o in outputs: |
41 if outputs == []: | 68 if outputs == []: |
42 outputs = [plugOuts[0]["identifier"]] | 69 outputs = [plugOuts[0]["identifier"]] |
43 | 70 |
44 singleOutput = (len(outputs) == 1) | 71 singleOutput = (len(outputs) == 1) |
45 | 72 |
46 stepSize = plug.getPreferredStepSize() | |
47 blockSize = plug.getPreferredBlockSize() | |
48 if blockSize == 0: | |
49 blockSize = 1024 | |
50 if stepSize == 0: | |
51 stepSize = blockSize ##!!! or blockSize/2, but check this with input domain adapter | |
52 channels = 1 | |
53 if data.ndim > 1: | |
54 channels = data.shape[0] | |
55 | |
56 plug.initialise(channels, stepSize, blockSize) | |
57 ff = framesFromArray(data, stepSize, blockSize) | 73 ff = framesFromArray(data, stepSize, blockSize) |
58 fi = 0 | 74 fi = 0 |
59 | 75 |
60 for f in ff: | 76 for f in ff: |
61 results = plug.processBlock(f, vampyhost.frame2RealTime(fi, samplerate)) | 77 results = plug.processBlock(f, vampyhost.frame2RealTime(fi, samplerate)) |