diff options
Diffstat (limited to 'rotord')
| -rwxr-xr-x | rotord/rotor.h | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/rotord/rotor.h b/rotord/rotor.h index ed566c7..b681e72 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -603,12 +603,33 @@ namespace Rotor { //http://create.stephan-brumme.com/fnv-hash/ const uint32_t Prime = 0x01000193; // 16777619 const uint32_t Seed = 0x811C9DC5; // 2166136261 + /// hash a byte + inline uint32_t fnv1a(unsigned char oneByte, uint32_t hash = Seed) + { + return (oneByte ^ hash) * Prime; + } + /// hash a short (two bytes) + inline uint32_t fnv1a(unsigned short twoBytes, uint32_t hash = Seed) + { + const unsigned char* ptr = (const unsigned char*) &twoBytes; + hash = fnv1a(*ptr++, hash); + return fnv1a(*ptr , hash); + } + /// hash a 32 bit integer (four bytes) + inline uint32_t fnv1a(uint32_t fourBytes, uint32_t hash = Seed) + { + const unsigned char* ptr = (const unsigned char*) &fourBytes; + hash = fnv1a(*ptr++, hash); + hash = fnv1a(*ptr++, hash); + hash = fnv1a(*ptr++, hash); + return fnv1a(*ptr , hash); + } class Random: public Signal_node { public: Random(){}; Random(map<string,string> &settings) { base_settings(settings); - seed=ofToFloat(find_setting(settings,"amount")); + seed=(float)find_setting(settings,"seed",Seed); for (auto p:parameter_inputs){ if (p->parameter=="seed") p->receiver=&seed; } @@ -616,16 +637,19 @@ namespace Rotor { }; Random* clone(map<string,string> &_settings) { return new Random(_settings);}; const float output(const Time_spec &time) { - if (inputs.size()) { //there should there be a way to specify number of inputs in the code rather than in xml + if (inputs.size()) { if (inputs[0]->connection) { - return 0.0f; - //return (((Signal_node*)inputs[0]->connection)->get_output(time))/divide_amount; + //hash the integer part and add the fractional part back on + float o=(((Signal_node*)inputs[0]->connection)->get_output(time)); + uint32_t m=(int)o; + return ((float)fnv1a(m,(uint32_t)(seed+0.5f)))+(o-m); } } return 0.0f; } float seed; - uint32_t key; + private: + }; class Signal_output: public Signal_node { public: |
