From 332c7c24301700ca0a4ceb104051bcd3a3b3bc4b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 4 Apr 2013 18:03:14 +0100 Subject: analyser loader --- rotord/rotor.cpp | 101 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 47 deletions(-) (limited to 'rotord/rotor.cpp') diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index f7c017d..cd288e3 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -21,9 +21,13 @@ void Render_context::runTask() { mutex.unlock(); if (cmd==ANALYSE_AUDIO) { state=ANALYSING_AUDIO; - vector proc; - proc.push_back(audio_thumb); - if (load_audio(audio_filename,proc)) { + vector processors; + processors.push_back(audio_thumb); + vector analysers=graph.find_nodes("audio_analysis"); + for (auto a: analysers) { + processors.push_back(a); + } + if (load_audio(audio_filename,processors)) { state=AUDIO_READY; } else state=IDLE; @@ -118,9 +122,9 @@ Command_response Render_context::session_command(const std::vector& } if (command[2]=="graph") { if (command[0]=="GET") { - if (xml.bDocLoaded) { + if (graph.loaded) { response.status=HTTPResponse::HTTP_OK; - xml.copyXmlToString(response.description); + response.description=graph.toString(); } else { response.description="Rotor: graph not loaded\n"; @@ -134,14 +138,14 @@ Command_response Render_context::session_command(const std::vector& Poco::File f=Poco::File(command[3]); if (f.exists()) { string graph_filename=command[3]; - if (load_graph(graph_filename)) { + if (graph.load(graph_filename)) { response.status=HTTPResponse::HTTP_OK; //response.description="Rotor: loaded graph "+command[3]+"\n"; - string xmlstring; - xml.copyXmlToString(xmlstring); - response.description=xmlstring; + response.description=graph.toString(); //the graph could actually contain an xml object and we could just print it here? //or could our nodes even be subclassed from xml nodes? + //the graph or the audio could load first- have to analyse the audio with vamp after the graph is loaded + //for now the graph must load 1st } else { response.status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h @@ -248,13 +252,10 @@ Command_response Render_context::session_command(const std::vector& return response; } - - - //http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/ //great to use c++11 features -bool Render_context::load_audio(const string &filename,vector processors){ +bool Render_context::load_audio(const string &filename,vector processors){ av_register_all(); @@ -325,14 +326,12 @@ bool Render_context::load_audio(const string &filename,vectorsample_fmt<< " (aka "<< av_get_sample_fmt_name(codecContext->sample_fmt) << ") "<init(codecContext->channels,16,samples); + p->init(codecContext->channels,16,samples,codecContext->sample_rate); } AVPacket packet; av_init_packet(&packet); int sample_processed=0; - - bool diag=true; while (true) { @@ -361,11 +360,7 @@ bool Render_context::load_audio(const string &filename,vectornb_samples<<" samples in "<format)<<" format with channel layout "<channel_layout<< std::endl; - diag=false; - } - + //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); @@ -408,11 +403,19 @@ bool Render_context::load_audio(const string &filename,vectorcreate_signal_input(xml.getValue("signal_input","",i2)); + nodes[nodeID]->create_signal_input(xml.getValue("signal_input","",i2)); string fromID=xml.getAttribute("signal_input","from","",i2); - if (graph.nodes.find(fromID)!=graph.nodes.end()) { - if (!graph.nodes[nodeID]->inputs[i2]->connect((Signal_node*)graph.nodes[fromID])){ + if (nodes.find(fromID)!=nodes.end()) { + if (!nodes[nodeID]->inputs[i2]->connect((Signal_node*)nodes[fromID])){ cerr << "Rotor: graph loader cannot connect input " << i2 << " of node '" << nodeID << "' to node '" << fromID << "'" << endl; return false; } @@ -453,6 +456,7 @@ bool Render_context::load_graph(string &filename){ } xml.popTag(); } + loaded=true; return true; } else return false; @@ -465,15 +469,11 @@ Node_factory::Node_factory(){ add_type("==",new Is_new_integer()); add_type("signal_output",new Signal_output()); } -void audio_thumbnailer::init(int _channels,int _bits,int _samples) { +void Audio_thumbnailer::init(int _channels,int _bits,int _samples,int _rate) { //base_audio_processor::init(_channels,_bits,_samples); channels=_channels; bits=_bits; samples=_samples; - - cerr << "init audio thumbnailer with "<offset) this_val=-(this_val-(offset*2)); - - //this_val -=offset; + //presume 16 bits for now... double val=((double)((int16_t)this_val))*scale; accum+=val*val; samples++; @@ -539,7 +529,7 @@ int audio_thumbnailer::process_frame(uint8_t *_data,int samples_in_frame){ } return out_sample; } -string audio_thumbnailer::print(){ +string Audio_thumbnailer::print(){ string output; for (int j=0;j