summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-12-09 01:53:14 +0000
committerComment <tim@gray.(none)>2013-12-09 01:53:14 +0000
commit08e7c5e59b5a7bfecb60ec98bfa191629d522ec8 (patch)
tree95ee80e1c6b4ef9d4f927676d91ebaa128d06bfe
parent1d05d2380bb4f1fd265aef55744f432af38b08aa (diff)
audio analysis segments output fix
-rw-r--r--rotord/src/nodes_audio_analysis.h57
-rw-r--r--rotord/src/nodes_maths.h22
-rw-r--r--rotord/src/vampHost.h2
3 files changed, 50 insertions, 31 deletions
diff --git a/rotord/src/nodes_audio_analysis.h b/rotord/src/nodes_audio_analysis.h
index 7c4893a..3f0416f 100644
--- a/rotord/src/nodes_audio_analysis.h
+++ b/rotord/src/nodes_audio_analysis.h
@@ -57,25 +57,30 @@ namespace Rotor {
const double output(const Time_spec &time) {
if (features.size()) {
auto i=features.upper_bound(time.time); //the first element in the container whose key is considered to go after k
- if (i==features.end()) i--;
- double uk=i->first;
- double v1,v2;
- v1=v2=0.0;
+ double uk;
+ double v1,v2;
+ v1=v2=0.0;
+ if (i==features.end()) {
+ uk=time.duration;
+ }
+ else {
+ uk=i->first;
if (i->second.values.size()) v2=i->second.values[0];
- i--;
- double lk=i->first;
- int ln=i->second.number;
- if (i->second.values.size()) v1=i->second.values[0];
- switch (attributes["mode"]->intVal){
- case VAMPHOST_Timeline:
- return (((time.time-lk)/(uk-lk))+ln);
- case VAMPHOST_Timesteps:
- return (double)ln;
- case VAMPHOST_Valueline:
- return ((((time.time-lk)/(uk-lk))*(v2-v1))+v1);
- case VAMPHOST_Values:
- return v1;
- }
+ }
+ i--;
+ double lk=i->first;
+ int ln=i->second.number;
+ if (i->second.values.size()) v1=i->second.values[0];
+ switch (attributes["mode"]->intVal){
+ case VAMPHOST_Timeline:
+ return (((time.time-lk)/(uk-lk))+ln);
+ case VAMPHOST_Timesteps:
+ return (double)ln;
+ case VAMPHOST_Valueline:
+ return ((time.time-lk)/(uk-lk))+v1; //((((time.time-lk)/(uk-lk))*(v2-v1))+v1);
+ case VAMPHOST_Values:
+ return v1;
+ }
//}
//return (--features.end())->second.values[0];
}
@@ -89,7 +94,7 @@ namespace Rotor {
string soname,id;
int outputNo;
map <string,float> params;
- map<float,vampHost::feature> features;
+ map<double,vampHost::feature> features;
private:
vampHost::Analyser analyser;
};
@@ -177,7 +182,7 @@ namespace Rotor {
Act_segmenter* clone(map<string,string> &_settings) { return new Act_segmenter(_settings);};
void cleanup(){
Vamp_node::cleanup();
- map<float,vampHost::feature> acts; //temporary storage for new set of features
+ map<double,vampHost::feature> acts; //temporary storage for new set of features
vector<int> act_count;
for (int i=0;i<(int)parameters["acts"]->value;i++) act_count.push_back(0);
@@ -189,10 +194,10 @@ namespace Rotor {
//keep going
//finally copy out
while (features.size()<(uint32_t)parameters["acts"]->value+1){
- map<int,float> durations;
- map<int,float> times;
+ map<int,double> durations;
+ map<int,double> times;
int i=0;
- for (map<float,vampHost::feature>::iterator f=features.begin();f!=features.end();++f){
+ for (map<double,vampHost::feature>::iterator f=features.begin();f!=features.end();++f){
auto g=f;
if (++g!=features.end()){
durations[i]=g->first-f->first;
@@ -200,7 +205,7 @@ namespace Rotor {
}
i++;
}
- float f=0;
+ double f=0;
int n=-1;
for (auto d: durations){
if (d.second>f){
@@ -227,7 +232,7 @@ namespace Rotor {
//start with a set of the segments numbers
//(the aim: to access the segment numbers by the time that they start)
- map<float,vampHost::feature> segments=features;
+ map<double,vampHost::feature> segments=features;
segments.erase(--segments.end());
//assign the acts from the beginning and end in towards the middle
@@ -237,7 +242,7 @@ namespace Rotor {
while (segments.size()){
int act=-1;
vampHost::feature f;
- float t;
+ double t;
if (take_start){
f=(*segments.begin()).second;
t=(*segments.begin()).first;
diff --git a/rotord/src/nodes_maths.h b/rotord/src/nodes_maths.h
index 0f92f0a..baa26d6 100644
--- a/rotord/src/nodes_maths.h
+++ b/rotord/src/nodes_maths.h
@@ -70,12 +70,13 @@ namespace Rotor {
#define ARITHMETIC_floor 11
#define ARITHMETIC_2pow 12
#define ARITHMETIC_reciprocal 13
+#define ARITHMETIC_rminus 14
class Arithmetic: public Signal_node {
public:
Arithmetic(){
create_signal_input("signal","Signal");
create_parameter("value","number","Value or signal for operation","Value",1.0);
- create_attribute("operator","operator for image","Operator","+",{"+","-","*","/","%","^","sin","cos","ease","jolt","floor","2pow","reciprocal"});
+ create_attribute("operator","operator for image","Operator","+",{"+","-","*","/","%","^","sin","cos","ease","jolt","floor","2pow","reciprocal","rminus"});
title="Arithmetic";
description="Performs arithmetic on a signal with a signal or value";
NODEID="f35e5f82-2d0a-11e3-83d8.0ed336db813";
@@ -83,6 +84,9 @@ namespace Rotor {
Arithmetic(map<string,string> &settings):Arithmetic() {
base_settings(settings);
};
+ void init(){
+ phase=0.0;
+ }
Arithmetic* clone(map<string,string> &_settings) { return new Arithmetic(_settings);};
const double output(const Time_spec &time) {
//if (attributes["operator"]->intVal==ARITHMETIC_divide||attributes["operator"]->intVal==ARITHMETIC_modulo){
@@ -117,11 +121,18 @@ namespace Rotor {
case ARITHMETIC_pow:
return pow(in,parameters["value"]->value);
break;
+//http://dsp.stackexchange.com/questions/971/how-to-create-a-sine-wave-generator-that-can-smoothly-transition-between-frequen
+//
+//arithmetic needs to keep an accumulator and work from the begiining for some things
+//sin/cos needs a phase accumulator to allow frequency modulation
+
case ARITHMETIC_sin:
- return sin(in)*parameters["value"]->value;
+ phase+=in*parameters["value"]->value;
+ return sin(phase);
break;
case ARITHMETIC_cos:
- return cos(in)*parameters["value"]->value;
+ phase+=in*parameters["value"]->value;
+ return cos(phase);
break;
case ARITHMETIC_ease:
return ((1.0-parameters["value"]->value)*in)+(parameters["value"]->value*(0.5f+((cos((fmod(in,1.0)+1.0)*M_PI))*0.5f)));
@@ -138,13 +149,16 @@ namespace Rotor {
case ARITHMETIC_reciprocal:
return parameters["value"]->value/in;
break;
+ case ARITHMETIC_rminus:
+ return parameters["value"]->value-in;
+ break;
}
}
}
return 0.0;
}
int op;
- double value;
+ double value,phase;
};
class Is_new_integer: public Signal_node {
public:
diff --git a/rotord/src/vampHost.h b/rotord/src/vampHost.h
index e44e981..a8b0bbb 100644
--- a/rotord/src/vampHost.h
+++ b/rotord/src/vampHost.h
@@ -66,7 +66,7 @@ namespace vampHost {
void cleanup();
double get_value(const double &time);
//map<double,int> features;
- map<float,feature> features;
+ map<double,feature> features;
//map<time,featureNo>
//this is the best way to store features: because map allows to search for the key below and above the present time