comparison host/vamp-simple-host.cpp @ 29:d97aafa99828

* Deal properly with the fact that the host doesn't support non-power-of-two blocksizes in frequency domain
author cannam
date Tue, 16 May 2006 11:33:50 +0000
parents 1eb44d33a371
children 13eae6cc6bac
comparison
equal deleted inserted replaced
28:ca1309b937b6 29:d97aafa99828
167 167
168 int blockSize = plugin->getPreferredBlockSize(); 168 int blockSize = plugin->getPreferredBlockSize();
169 int stepSize = plugin->getPreferredStepSize(); 169 int stepSize = plugin->getPreferredStepSize();
170 170
171 cerr << "Preferred block size = " << blockSize << ", step size = " 171 cerr << "Preferred block size = " << blockSize << ", step size = "
172 << stepSize << endl; 172 << stepSize << endl;
173 173
174 if (blockSize == 0) blockSize = 1024; 174 if (blockSize == 0) blockSize = 1024;
175 if (stepSize == 0) stepSize = blockSize; 175 if (stepSize == 0) stepSize = blockSize;
176
177 bool rightBlockSize = true;
178 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
179 int p = 1, b = blockSize;
180 while (b) {
181 p <<= 1;
182 b >>= 1;
183 }
184 if (p != blockSize * 2) {
185 cerr << "WARNING: Plugin requested non-power-of-two block size of "
186 << blockSize << ",\nwhich is not supported by this host. ";
187 blockSize = p;
188 cerr << "Rounding up to " << blockSize << "." << endl;
189 rightBlockSize = false;
190 }
191 }
176 192
177 int channels = sfinfo.channels; 193 int channels = sfinfo.channels;
178 194
179 float *filebuf = new float[blockSize * channels]; 195 float *filebuf = new float[blockSize * channels];
180 float **plugbuf = new float*[channels]; 196 float **plugbuf = new float*[channels];
187 int maxch = plugin->getMaxChannelCount(); 203 int maxch = plugin->getMaxChannelCount();
188 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl; 204 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl;
189 205
190 Vamp::Plugin::OutputList outputs = plugin->getOutputDescriptors(); 206 Vamp::Plugin::OutputList outputs = plugin->getOutputDescriptors();
191 Vamp::Plugin::OutputDescriptor od; 207 Vamp::Plugin::OutputDescriptor od;
208
209 int returnValue = 1;
192 210
193 int output = 0; 211 int output = 0;
194 if (argc == 4) output = atoi(argv[3]); 212 if (argc == 4) output = atoi(argv[3]);
195 213
196 bool mix = false; 214 bool mix = false;
217 } 235 }
218 236
219 od = outputs[output]; 237 od = outputs[output];
220 cerr << "Output is " << od.name << endl; 238 cerr << "Output is " << od.name << endl;
221 239
222 plugin->initialise(channels, stepSize, blockSize); 240 if (!plugin->initialise(channels, stepSize, blockSize)) {
241 cerr << "ERROR: Plugin initialise (channels = " << channels
242 << ", stepSize = " << stepSize << ", blockSize = "
243 << blockSize << ") failed." << endl;
244 if (!rightBlockSize) {
245 cerr << "(Probably because I couldn't provide the plugin's preferred block size.)" << endl;
246 }
247 goto done;
248 }
223 249
224 for (size_t i = 0; i < sfinfo.frames; i += stepSize) { 250 for (size_t i = 0; i < sfinfo.frames; i += stepSize) {
225 251
226 int count; 252 int count;
227 253
259 } 285 }
260 286
261 printFeatures(sfinfo.frames, sfinfo.samplerate, output, 287 printFeatures(sfinfo.frames, sfinfo.samplerate, output,
262 plugin->getRemainingFeatures()); 288 plugin->getRemainingFeatures());
263 289
290 returnValue = 0;
291
264 done: 292 done:
265 delete plugin; 293 delete plugin;
266 294
267 DLCLOSE(libraryHandle); 295 DLCLOSE(libraryHandle);
268 sf_close(sndfile); 296 sf_close(sndfile);
269 return 0; 297 return returnValue;
270 } 298 }
271 299
272 void 300 void
273 printFeatures(int frame, int sr, int output, Vamp::Plugin::FeatureSet features) 301 printFeatures(int frame, int sr, int output, Vamp::Plugin::FeatureSet features)
274 { 302 {