1 #include <vamp-sdk/hostext/PluginLoader.h>
2 #include <glibmm/miscutils.h>
3 #include <glibmm/fileutils.h>
4 #include <glib/gstdio.h> // for g_remove()
8 #include <ardour/audioanalyser.h>
9 #include <ardour/readable.h>
10 #include <ardour/readable.h>
17 using namespace ARDOUR;
19 AudioAnalyser::AudioAnalyser (float sr, AnalysisPluginKey key)
26 AudioAnalyser::~AudioAnalyser ()
31 AudioAnalyser::initialize_plugin (AnalysisPluginKey key, float sr)
33 using namespace Vamp::HostExt;
35 PluginLoader* loader (PluginLoader::getInstance());
37 plugin = loader->loadPlugin (key, sr, PluginLoader::ADAPT_ALL);
40 error << string_compose (_("VAMP Plugin \"%1\" could not be loaded"), key) << endmsg;
44 /* we asked for the buffering adapter, so set the blocksize to
45 something that makes for efficient disk i/o
51 if (plugin->getMinChannelCount() > 1) {
56 if (!plugin->initialise (1, stepsize, bufsize)) {
65 AudioAnalyser::reset ()
73 AudioAnalyser::analyse (const string& path, Readable* src, uint32_t channel)
76 Plugin::FeatureSet onsets;
80 nframes64_t len = src->readable_length();
82 float* bufs[1] = { 0 };
85 ofile.open (path.c_str());
91 /* create VAMP percussion onset plugin and initialize */
94 if (initialize_plugin (plugin_key, sample_rate)) {
99 data = new Sample[bufsize];
106 /* read from source */
108 to_read = min ((len - pos), bufsize);
110 if (src->read (data, pos, to_read, channel) != to_read) {
111 cerr << "bad read\n";
115 /* zero fill buffer if necessary */
117 if (to_read != bufsize) {
118 memset (data + to_read, 0, (bufsize - to_read));
121 onsets = plugin->process (bufs, RealTime::fromSeconds ((double) pos / sample_rate));
123 if (use_features (onsets, (path.empty() ? &ofile : 0))) {
134 /* finish up VAMP plugin */
136 onsets = plugin->getRemainingFeatures ();
138 if (use_features (onsets, (path.empty() ? &ofile : 0))) {
145 /* works even if it has not been opened */
149 g_remove (path.c_str());