From 628a21f4e5785f9d52ac5c9c4bd483819fa9cf2a Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 8 Apr 2013 17:28:37 +0100 Subject: thumbnailing --- rotord/rotor.cpp | 26 ++++++++-------- rotord/vampHost.cpp | 85 ++++++++++++++++++++++++++++++++--------------------- rotord/vampHost.h | 10 ++++++- 3 files changed, 73 insertions(+), 48 deletions(-) diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 73577f4..2cd894f 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -259,7 +259,7 @@ Command_response Render_context::session_command(const std::vector& //great to use c++11 features bool Render_context::load_audio(const string &filename,vector processors){ - + av_register_all(); AVFrame* frame = avcodec_alloc_frame(); @@ -363,22 +363,22 @@ bool Render_context::load_audio(const string &filename,vector doxygen" into google (like // "AVFrame doxygen" for AVFrame's docs) - + //av_get_channel_layout_string (char *buf, int buf_size, int nb_channels, uint64_t channel_layout) - - + + //now we can pass the data to the processor(s) for (auto p: processors) { sample_processed=p->process_frame(frame->data[0],frame->nb_samples); } - + mutex.lock(); progress=((double)sample_processed)/samples; mutex.unlock(); } } // You *must* call av_free_packet() after each call to av_read_frame() or else you'll leak memory - av_free_packet(&packet); + av_free_packet(&packet); } // Some codecs will cause frames to be buffered up in the decoding process. If the CODEC_CAP_DELAY flag @@ -399,14 +399,14 @@ bool Render_context::load_audio(const string &filename,vectorcleanup(); } - + av_free(frame); avcodec_close(codecContext); av_close_input_file(formatContext); @@ -471,7 +471,6 @@ bool Graph::load(string &filename){ } else return false; } - Node_factory::Node_factory(){ //for now, statically load prototype map in constructor add_type("audio_analysis",new Audio_analysis()); @@ -502,14 +501,13 @@ int Audio_thumbnailer::process_frame(uint8_t *_data,int samples_in_frame){ int stride=channels*bytes; int in_sample=0; while (in_sample& out){ - + /* - vamp-simple-host qm-vamp-plugins:qm-tempotracker 01.wav + vamp-simple-host qm-vamp-plugins:qm-tempotracker 01.wav 0.046439908: 156.61 bpm 0.429569160: 156.61 bpm 0.812698412: 161.50 bpm 1.184217686: 152.00 bpm - - + + vamp-simple-host qm-vamp-plugins:qm-segmenter 01.wav - + 0.000000000: 4 4 23.800000000: 6 6 44.600000000: 5 5 @@ -544,33 +544,33 @@ void vampHost::getTimestamps(int output,Plugin::FeatureSet features, vector>3); stride=channels*bytes; scale=(1.0f/pow(2.0f,bits)); - - + + loader = PluginLoader::getInstance(); key = loader->composePluginKey(soname, id); - Plugin *plugin = loader->loadPlugin(key, _rate, PluginLoader::ADAPT_ALL_SAFE); + plugin = loader->loadPlugin(key, _rate, PluginLoader::ADAPT_ALL_SAFE); if (!plugin) { cerr << ": ERROR: Failed to load plugin \"" << id << "\" from library \"" << soname << "\"" << endl; @@ -616,7 +616,7 @@ bool vampHost::Analyser::init(const string &soname,const string &id,const int &_ } cerr << "Running plugin: \"" << plugin->getIdentifier() << "\"..." << endl; - + blockSize = plugin->getPreferredBlockSize(); stepSize = plugin->getPreferredStepSize(); @@ -629,7 +629,7 @@ bool vampHost::Analyser::init(const string &soname,const string &id,const int &_ } else { stepSize = blockSize; } - } + } else if (stepSize > blockSize) { cerr << "WARNING: stepSize " << stepSize << " > blockSize " << blockSize << ", resetting blockSize to "; if (plugin->getInputDomain() == Plugin::FrequencyDomain) { @@ -642,7 +642,7 @@ bool vampHost::Analyser::init(const string &soname,const string &id,const int &_ overlapSize = blockSize - stepSize; currentStep = 0; finalStepsRemaining = max(1, (blockSize / stepSize) - 1); // at end of file, this many part-silent frames needed after we hit EOF - + plugbuf = new float*[channels]; for (int c = 0; c < channels; ++c) plugbuf[c] = new float[blockSize + 2]; @@ -684,7 +684,7 @@ bool vampHost::Analyser::init(const string &soname,const string &id,const int &_ cerr << "ERROR: Non-existent output \"" << output << "\" requested" << endl; return false; } - } + } else { if (int(outputs.size()) <= outputNo) { cerr << "ERROR: Output " << outputNo << " requested, but plugin has only " << outputs.size() << " output(s)" << endl; @@ -700,7 +700,7 @@ bool vampHost::Analyser::init(const string &soname,const string &id,const int &_ << blockSize << ") failed." << endl; return false; } - + wrapper = dynamic_cast(plugin); if (wrapper) { // See documentation for @@ -708,16 +708,20 @@ bool vampHost::Analyser::init(const string &soname,const string &id,const int &_ PluginInputDomainAdapter *ida =wrapper->getWrapper(); if (ida) adjustment = ida->getTimestampAdjustment(); } - + //everything is prepared to start consuming data in blocks - + in_block=0; blocks_processed=0; + currentStep=0; + featureNo=0; + return true; } void vampHost::Analyser::process_frame(uint8_t *data,int samples_in_frame){ int sample=0; + RealTime rt; //process the whole frame which may be f>1getIdentifier()<<" processed block "<process(plugbuf, rt); + + for (unsigned int i = 0; i < feat[outputNo].size(); ++i) { + features[((float)feat[outputNo][i].timestamp.sec)+(((float)feat[outputNo][i].timestamp.nsec)*.000000001)]=featureNo; + featureNo++; + } + + //all good but no features! what gives? + in_block=0; blocks_processed++; } } } void vampHost::Analyser::cleanup(){ + cerr<getIdentifier()<<" found "< beats; private: PluginLoader *loader; PluginLoader::PluginKey key; @@ -71,6 +70,15 @@ namespace vampHost { int in_block,blocks_processed; string output; float **plugbuf; + + int featureNo; + map features; + //what's the best way to store features? + //how will it be used? + //we ask for a signal at a time, return interpolated value representing feature number + fraction + //is there a quick way to search the keys and return the last one below a given value + + }; string getQMBeats(const string soundfile); -- cgit v1.2.3