comparison vamp/collect.py @ 89:1a08dd72f4d2

Tidy, refactor
author Chris Cannam
date Wed, 21 Jan 2015 18:27:07 +0000
parents 7228921e8425
children 4bed6bf67243
comparison
equal deleted inserted replaced
88:7228921e8425 89:1a08dd72f4d2
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 2
3 import vampyhost 3 import vampyhost
4 import load 4 import load
5 import process 5 import process
6 import frames
7
6 8
7 def timestamp_features(sample_rate, step_size, output_desc, features): 9 def timestamp_features(sample_rate, step_size, output_desc, features):
8 n = -1 10 n = -1
9 if output_desc["sample_type"] == vampyhost.ONE_SAMPLE_PER_STEP: 11 if output_desc["sample_type"] == vampyhost.ONE_SAMPLE_PER_STEP:
10 for f in features: 12 for f in features:
24 else: 26 else:
25 for f in features: 27 for f in features:
26 yield f 28 yield f
27 29
28 30
29 def collect(data, sample_rate, key, output, parameters = {}): 31 def process_and_fill_timestamps(data, sample_rate, key, output, parameters = {}):
30 32
31 plug, step_size, block_size = load.load_and_configure(data, sample_rate, key, parameters) 33 plugin, step_size, block_size = load.load_and_configure(data, sample_rate, key, parameters)
32 34
33 if output == "": 35 if output == "":
34 out = plug.get_output(0) 36 output_desc = plugin.get_output(0)
37 output = output_desc["identifier"]
35 else: 38 else:
36 out = plug.get_output(output) 39 output_desc = plugin.get_output(output)
37 40
38 plug.unload() 41 ff = frames.frames_from_array(data, step_size, block_size)
42
43 results = process.process_frames_with_plugin(ff, sample_rate, step_size, plugin, [output])
44
45 selected = [ r[output] for r in results ]
46
47 stamped = timestamp_features(sample_rate, step_size, output_desc, selected)
48
49 for s in stamped:
50 yield s
51
52 plugin.unload()
39 53
40 results = process.process(data, sample_rate, key, output, parameters)
41
42 return timestamp_features(sample_rate, step_size, out, results)
43 54
44 55 def collect(data, sample_rate, key, output, parameters = {}):
45 56 return process_and_fill_timestamps(data, sample_rate, key, output, parameters)