# HG changeset patch # User cannam # Date 1147779230 0 # Node ID d97aafa998280101ac3486a06334c73e104e4450 # Parent ca1309b937b6b79bd07a53920e3309edf3ac2e04 * Deal properly with the fact that the host doesn't support non-power-of-two blocksizes in frequency domain diff -r ca1309b937b6 -r d97aafa99828 host/vamp-simple-host.cpp --- a/host/vamp-simple-host.cpp Fri May 12 14:46:35 2006 +0000 +++ b/host/vamp-simple-host.cpp Tue May 16 11:33:50 2006 +0000 @@ -169,11 +169,27 @@ int stepSize = plugin->getPreferredStepSize(); cerr << "Preferred block size = " << blockSize << ", step size = " - << stepSize << endl; + << stepSize << endl; if (blockSize == 0) blockSize = 1024; if (stepSize == 0) stepSize = blockSize; + bool rightBlockSize = true; + if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) { + int p = 1, b = blockSize; + while (b) { + p <<= 1; + b >>= 1; + } + if (p != blockSize * 2) { + cerr << "WARNING: Plugin requested non-power-of-two block size of " + << blockSize << ",\nwhich is not supported by this host. "; + blockSize = p; + cerr << "Rounding up to " << blockSize << "." << endl; + rightBlockSize = false; + } + } + int channels = sfinfo.channels; float *filebuf = new float[blockSize * channels]; @@ -190,6 +206,8 @@ Vamp::Plugin::OutputList outputs = plugin->getOutputDescriptors(); Vamp::Plugin::OutputDescriptor od; + int returnValue = 1; + int output = 0; if (argc == 4) output = atoi(argv[3]); @@ -219,7 +237,15 @@ od = outputs[output]; cerr << "Output is " << od.name << endl; - plugin->initialise(channels, stepSize, blockSize); + if (!plugin->initialise(channels, stepSize, blockSize)) { + cerr << "ERROR: Plugin initialise (channels = " << channels + << ", stepSize = " << stepSize << ", blockSize = " + << blockSize << ") failed." << endl; + if (!rightBlockSize) { + cerr << "(Probably because I couldn't provide the plugin's preferred block size.)" << endl; + } + goto done; + } for (size_t i = 0; i < sfinfo.frames; i += stepSize) { @@ -261,12 +287,14 @@ printFeatures(sfinfo.frames, sfinfo.samplerate, output, plugin->getRemainingFeatures()); + returnValue = 0; + done: delete plugin; DLCLOSE(libraryHandle); sf_close(sndfile); - return 0; + return returnValue; } void