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);
43 /* we asked for the buffering adapter, so set the blocksize to
44 something that makes for efficient disk i/o
50 if (plugin->getMinChannelCount() > 1) {
55 if (!plugin->initialise (1, stepsize, bufsize)) {
64 AudioAnalyser::reset ()
72 AudioAnalyser::analyse (const string& path, boost::shared_ptr<Readable> src, uint32_t channel)
75 Plugin::FeatureSet onsets;
79 nframes64_t len = src->readable_length();
81 float* bufs[1] = { 0 };
84 ofile.open (path.c_str());
90 /* create VAMP percussion onset plugin and initialize */
93 if (initialize_plugin (plugin_key, sample_rate)) {
98 data = new Sample[bufsize];
105 /* read from source */
107 to_read = min ((len - pos), bufsize);
109 if (src->read (data, pos, to_read, channel) != to_read) {
110 cerr << "bad read\n";
114 /* zero fill buffer if necessary */
116 if (to_read != bufsize) {
117 memset (data + to_read, 0, (bufsize - to_read));
120 onsets = plugin->process (bufs, RealTime::fromSeconds ((double) pos / sample_rate));
122 if (use_features (onsets, (path.empty() ? &ofile : 0))) {
133 /* finish up VAMP plugin */
135 onsets = plugin->getRemainingFeatures ();
137 if (use_features (onsets, (path.empty() ? &ofile : 0))) {
144 /* works even if it has not been opened */
148 g_remove (path.c_str());