From 08e7c5e59b5a7bfecb60ec98bfa191629d522ec8 Mon Sep 17 00:00:00 2001 From: Comment Date: Mon, 9 Dec 2013 01:53:14 +0000 Subject: audio analysis segments output fix --- rotord/src/nodes_maths.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'rotord/src/nodes_maths.h') 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 &settings):Arithmetic() { base_settings(settings); }; + void init(){ + phase=0.0; + } Arithmetic* clone(map &_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: -- cgit v1.2.3