summaryrefslogtreecommitdiff
path: root/rotord/src/nodes_maths.h
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-12-08 09:57:25 +0000
committerComment <tim@gray.(none)>2013-12-08 09:57:25 +0000
commite04516069c71a5a1e32e6a5fbf0eb5b86dcfc5a2 (patch)
treebec01f63fb5306d6ec49eae870ed747594be5927 /rotord/src/nodes_maths.h
parenta647bc51ea9fd29623aba56246e85c51b923bbd9 (diff)
many signal fixes
Diffstat (limited to 'rotord/src/nodes_maths.h')
-rw-r--r--rotord/src/nodes_maths.h42
1 files changed, 35 insertions, 7 deletions
diff --git a/rotord/src/nodes_maths.h b/rotord/src/nodes_maths.h
index 4c81f7b..2bf8b48 100644
--- a/rotord/src/nodes_maths.h
+++ b/rotord/src/nodes_maths.h
@@ -5,6 +5,7 @@
#include <libnoise/noise.h>
#include <libnoise/mathconsts.h>
#include "Poco/Logger.h"
+#include "mtrand.h"
using namespace noise;
@@ -94,6 +95,7 @@ namespace Rotor {
if (inputs.size()) { //there should there be a way to specify number of inputs in the code rather than in xml
if (inputs[0]->connection) {
float in= inputs[0]->get(time);
+ int inint; //this old chestnut
switch (attributes["operator"]->intVal) {
case ARITHMETIC_plus:
return in+parameters["value"]->value;
@@ -108,8 +110,10 @@ namespace Rotor {
return in/parameters["value"]->value;
break;
case ARITHMETIC_modulo:
+ //cerr <<in<<" % "<<parameters["value"]->value<<" = "<<fmod(in,parameters["value"]->value)<<endl;
return fmod(in,parameters["value"]->value);
- break;
+ //return (((int)in)%12); //+(in-((int)in));
+ break;
case ARITHMETIC_pow:
return pow(in,parameters["value"]->value);
break;
@@ -206,6 +210,20 @@ namespace Rotor {
hash = fnv1a(*ptr++, hash);
return fnv1a(*ptr , hash);
}
+ uint32_t hash( uint32_t a)
+ {
+ a = (a+0x7ed55d16) + (a<<12);
+ a = (a^0xc761c23c) ^ (a>>19);
+ a = (a+0x165667b1) + (a<<5);
+ a = (a+0xd3a2646c) ^ (a<<9);
+ a = (a+0xfd7046c5) + (a<<3);
+ a = (a^0xb55a4f09) ^ (a>>16);
+
+ a -= (a>>1);
+
+ return a;
+ }
+
class Random: public Signal_node {
public:
Random(){
@@ -214,18 +232,29 @@ namespace Rotor {
create_signal_input("signal","Signal");
create_parameter("seed","number","Seed value","Seed",1.0f);
NODEID="1de86932-2d0b-11e3-96d3-77aa4558e6cd";
+ std::uniform_int_distribution<> d(-9999, 9999);
};
Random(map<string,string> &settings):Random() {
base_settings(settings);
};
Random* clone(map<string,string> &_settings) { return new Random(_settings);};
const float output(const Time_spec &time) {
- uint32_t seed=Seed+parameters["seed"]->value;
- //hash the integer part and add the fractional part back on
- float o=inputs[0]->get(time);
+
+ float o;
+ if (inputs[0]->connection){
+ o=inputs[0]->get(time);
+ }
+ else o=time.time;
uint32_t m=(int)o;
- return ((float)(fnv1a(m,seed)%((uint32_t)time.duration)))+(o-m);
+ PRNG.seed(m^(int)parameters["seed"]->value);
+ return ((float)(PRNG()&0xf))+(o-m);
+
+ //uint32_t seed=Seed+parameters["seed"]->value;
+ //hash the integer part and add the fractional part back on
+ //
+ //return ((float)(fnv1a(m,seed)))+(o-m); //%((uint32_t)time.duration))
}
+ MTRand_int32 PRNG;
};
class Noise: public Signal_node {
//fractal noise
@@ -253,9 +282,8 @@ namespace Rotor {
}
return perlin.GetValue(time.time,0,0)*parameters["scale"]->value;
}
- uint32_t seed;
private:
- module::RidgedMulti perlin;
+ module::Perlin perlin;
};
}