comparison vamp/collect.py @ 99:7764eb74a3c6

Docs
author Chris Cannam
date Tue, 03 Feb 2015 16:24:37 +0000
parents 06c4afba4fc5
children 72be91c3cb3d
comparison
equal deleted inserted replaced
98:f0c18ba7b54e 99:7764eb74a3c6
79 79
80 return rv 80 return rv
81 81
82 82
83 def collect(data, sample_rate, key, output = "", parameters = {}): 83 def collect(data, sample_rate, key, output = "", parameters = {}):
84 """Process audio data with a Vamp plugin, and make the results from a
85 single plugin output available as a single structure.
84 86
87 The provided data should be a 1- or 2-dimensional list or NumPy
88 array of floats. If it is 2-dimensional, the first dimension is
89 taken to be the channel count.
90
91 The returned results will be those calculated by the plugin with
92 the given key and returned through its output with the given
93 output identifier. If the requested output is the empty string,
94 the first output provided by the plugin will be used.
95
96 If the parameters dict is non-empty, the plugin will be configured
97 by setting its parameters according to the (string) key and
98 (float) value data found in the dict.
99
100 The structure in which the results are returned depends upon the
101 output descriptor for the requested plugin output, as follows:
102
103 * If the plugin output emits single-valued features at a fixed
104 sample-rate, then this function will return a tuple of step time
105 (the time in seconds between consecutive feature values) and a
106 one-dimensional NumPy array of feature values. An example of
107 such a feature might be a loudness curve against time.
108
109 * If the plugin output emits multiple-valued features, with an
110 equal number of bins per feature, at a fixed sample-rate, then
111 this function will return a tuple of step time (the time in
112 seconds between consecutive feature values) and a
113 two-dimensional NumPy array of feature values. An example of
114 such a feature might be a spectrogram.
115
116 * Otherwise this function will return a list of features, where
117 each feature is represented as a dictionary containing a
118 timestamp (always) and a duration (optionally), a label
119 (string), and a 1-dimensional array of float values.
120
121 If you would prefer to obtain features as they are calculated
122 (where the plugin supports this) and with the format in which the
123 plugin returns them, via an asynchronous generator function, use
124 vamp.process() instead.
125 """
126
85 plugin, step_size, block_size = load.load_and_configure(data, sample_rate, key, parameters) 127 plugin, step_size, block_size = load.load_and_configure(data, sample_rate, key, parameters)
86 128
87 if output == "": 129 if output == "":
88 output_desc = plugin.get_output(0) 130 output_desc = plugin.get_output(0)
89 output = output_desc["identifier"] 131 output = output_desc["identifier"]
97 rv = reshape(results, sample_rate, step_size, output_desc) 139 rv = reshape(results, sample_rate, step_size, output_desc)
98 140
99 plugin.unload() 141 plugin.unload()
100 return rv 142 return rv
101 143
144
145 #!!! restore & complete this once process is refactored:
102 146
103 def collect_frames(ff, channels, sample_rate, step_size, key, output = "", parameters = {}): 147 # def collect_frames(ff, channels, sample_rate, step_size, key, output = "", parameters = {}):
104 148
105 plug = vampyhost.load_plugin(key, sample_rate, 149 # plug = vampyhost.load_plugin(key, sample_rate,
106 vampyhost.ADAPT_INPUT_DOMAIN + 150 # vampyhost.ADAPT_INPUT_DOMAIN +
107 vampyhost.ADAPT_BUFFER_SIZE + 151 # vampyhost.ADAPT_BUFFER_SIZE +
108 vampyhost.ADAPT_CHANNEL_COUNT) 152 # vampyhost.ADAPT_CHANNEL_COUNT)
109 153
110 plug.set_parameter_values(parameters) 154 # plug.set_parameter_values(parameters)
111 155
112 if not plug.initialise(channels, step_size, block_size): 156 # if not plug.initialise(channels, step_size, block_size):
113 raise "Failed to initialise plugin" 157 # raise "Failed to initialise plugin"
114 158
115 if output == "": 159 # if output == "":
116 output_desc = plugin.get_output(0) 160 # output_desc = plugin.get_output(0)
117 output = output_desc["identifier"] 161 # output = output_desc["identifier"]
118 else: 162 # else:
119 output_desc = plugin.get_output(output) 163 # output_desc = plugin.get_output(output)
120 164
121 results = process.process_frames_with_plugin(ff, sample_rate, step_size, plugin, [output]) 165 # results = process.process_frames_with_plugin(ff, sample_rate, step_size, plugin, [output])
122 166
123 rv = reshape(results, sample_rate, step_size, output_desc) 167 # rv = reshape(results, sample_rate, step_size, output_desc)
124 168
125 plugin.unload() 169 # plugin.unload()
126 return rv 170 # return rv
127 171