From 086ac9c59ff0554ca34db17e51f3f9302a656b40 Mon Sep 17 00:00:00 2001 From: Comment Date: Mon, 3 Feb 2014 08:48:44 +0000 Subject: NT refactoring audio analysis --- NT/src/graph.cpp | 2 +- NT/src/nodes_audio_analysis.cpp | 20 ++++++++++---------- NT/src/rotor.h | 36 ++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 31 deletions(-) (limited to 'NT/src') diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp index ad89061..f108f55 100644 --- a/NT/src/graph.cpp +++ b/NT/src/graph.cpp @@ -46,7 +46,7 @@ bool Graph::load_audio(const std::string &filename) { } } for (auto p: processors) { - if(!p->init(channels,bits,samples,rate) ){ + if(!p->init_vamp(channels,bits,samples,rate) ){ logger.error("ERROR: Audio plugin failed to initialse"); return false; } diff --git a/NT/src/nodes_audio_analysis.cpp b/NT/src/nodes_audio_analysis.cpp index 34ad325..2a3793d 100644 --- a/NT/src/nodes_audio_analysis.cpp +++ b/NT/src/nodes_audio_analysis.cpp @@ -219,7 +219,7 @@ namespace Rotor{ if (intensityfirst<<" to "<first<<" average tempo: "<value)+(intensity*parameters["intensity_weight"]->value)<first<<" to "<first<<" average tempo: "<get())+(intensity*intensity_weight->get())<value)+(intensities[i]*parameters["intensity_weight"]->value))); - totalsmap.push_back((tempos[i]*parameters["tempo_weight"]->value)+(intensities[i]*parameters["intensity_weight"]->value)); + totals.push_back(make_pair(i,(tempos[i]*tempo_weight->get())+(intensities[i]*intensity_weight->get()))); + totalsmap.push_back((tempos[i]*tempo_weight->get())+(intensities[i]*intensity_weight->get())); } /* @@ -253,7 +253,7 @@ namespace Rotor{ for (auto t:totals) bucketoffsets.push_back(0.0); if (parameters["levels"]->value>0.0&¶meters["levels"]->valuevalue); + int numbertoredistribute=totals.size()-(levels->get()); double numberperbin=((double)numbertoredistribute/totals.size()); double toadd=0.5f; int added=0; @@ -359,9 +359,9 @@ nned to retrieve total intensity by segment } */ - if (((int)parameters["levels"]->value)>0) { - if (seggrps.size()>(int)parameters["levels"]->value){ - while (seggrps.size()>(int)parameters["levels"]->value){ + if ((levels->get())>0) { + if (seggrps.size()>levels->get()){ + while (seggrps.size()>levels->get()){ //reduce similarity groups //decide the best 2 to merge vector diffs; @@ -383,9 +383,9 @@ nned to retrieve total intensity by segment } cerr<<"intensities merged, "<value<<" levels requested, "<<(int)totalsmap.size()<<" original segments"<value,(int)totalsmap.size())){ - while (seggrps.size()value,(int)totalsmap.size())) { + //cerr<get()<<" levels requested, "<<(int)totalsmap.size()<<" original segments"<get(),(int)totalsmap.size())){ + while (seggrps.size()get(),(int)totalsmap.size())) { //split groups //calculate standard deviation of intensity variation vector devs; diff --git a/NT/src/rotor.h b/NT/src/rotor.h index f2e19b5..038334b 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -90,14 +90,21 @@ namespace Rotor { public: Enum(std::initializer_list init={},int def=0) : labels(init), value(def){}; int get_value(){return value;}; - operator int () const { + operator int () const { //overload C style cast to int return value; } + friend istream& operator>> (istream &in, Enum &en); private: std::vector labels; int value; }; - + + istream& operator>> (istream &in, Enum &en) + { + in >> en.value; + return in; + } + class Audio_frame{ public: Audio_frame(uint16_t *_samples,int _channels,int _numsamples){ @@ -212,9 +219,7 @@ namespace Rotor { void init(Json::Value s){ name=s["name"].asString(); if (!s["input"].empty()){ - for (uint32_t i=0;i &nodes){ @@ -229,17 +234,17 @@ namespace Rotor { } Json::Value to_json(); std::string get_type(){ - return TypeName::Get(); + return TypeName::Get(); } bool connect(Node* target){ //array does not connect this way return false; } - void add(std::string _name,std::string _input,bool _connectable=true){ - values.push_back(Variable_type(_name,_input,_connectable)); + void add(std::string _name="",std::string _description="",std::string _title="",bool _connectable=true){ + values.push_back(Variable_type(_name,_description,_title,_connectable)); } - void add(std::string _name="",bool _connectable=true,int num=1){ - for (int i=0;i(_name,"",_connectable)); + void add(int num,std::string _name="",std::string _description="",std::string _title="",bool _connectable=true){ + for (int i=0;i(_name,_description,_title,_connectable)); } bool connect(uint32_t which,Node* target){ if (values.size()>which){ @@ -261,16 +266,7 @@ namespace Rotor { std::vector> values; T value; }; - //don't forget the dupliicate inlets - //it needs to be a property of a var - //vars need to be: - //std::unordered_map>> - //?? - //or could it be that a var has properties - //var needs to be a class? - //or multi var could be a subclass of var? - //with an extra accessor const T& get(int which,const Frame_parameters &frame) - //in Node we could have create_multi_inlet() and add_multi_inlet() + //could specialise a variable type operator double() etc to allow direct cast class Node { //base type for node pointers public: Node(){type="";type_id="";id="";description="";}; -- cgit v1.2.3