computerscare-vcv-modules

ComputerScare modules for VCV Rack
Log | Files | Refs

golyFunctions.cpp (1736B)


      1 #include "golyFunctions.hpp"
      2 
      3 Goly::Goly() {
      4 	for (int i = 0; i < 16; i++) {
      5 		currentValues[i] = 0.f;
      6 	}
      7 
      8 }
      9 //[A,B,C,D]
     10 /*
     11 			std::vector<float> golyParams =
     12 			{
     13 		gp[0]=	params[IN_OFFSET].getValue(),  //-1,1
     14 		gp[1]=	params[IN_SCALE].getValue(), //-2,2
     15 		gp[2]=	arams[OUT_SCALE].getValue(),  //-20, 20
     16 		gp[3]=	params[OUT_OFFSET].getValue()}; // -10,10
     17 
     18 
     19 */
     20 void Goly::invoke(int algorithm, std::vector<float> gp, int num = 16) {
     21 	float trigFactor = 2 * M_PI / num;
     22 	switch (algorithm)
     23 	{
     24 	case 0: // code to be executed if n = 1;
     25 		//linear
     26 		//ip / proportion
     27 		//defaults:[A,B,C,D]=[0,1,1,0]
     28 		//
     29 		// C*((ip-A)*B)+D
     30 
     31 		for (int i = 0; i < num; i++) {
     32 			float ip = (float)i / num;
     33 			currentValues[i] = gp[2] * ((ip - gp[0]) * gp[1]) + gp[3];
     34 		}
     35 		break;
     36 	case 1:
     37 		//sigmoid
     38 		for (int i = 0; i < num; i++) {
     39 			float ip = (float)i / num;
     40 			float d = ip - gp[0] - 0.5;
     41 			currentValues[i] = gp[2] / (1 + exp(-d * exp(-4 * gp[1] + 6))) + gp[3];
     42 		}
     43 		break;
     44 	case 2:
     45 		//hump
     46 		for (int i = 0; i < num; i++) {
     47 			float ip = (float)i / num;
     48 			float d = ip - gp[0] - 0.5;
     49 			currentValues[i] = gp[2] * exp(-d * d * exp(-5 * gp[1] + 7)) + gp[3];
     50 		}
     51 		break;
     52 	case 3:
     53 		//sine wave
     54 		for (int i = 0; i < num; i++) {
     55 			float ip = (float)i / num;
     56 			float d = trigFactor * (ip - gp[0]);
     57 			currentValues[i] = gp[2] * (1 + sinf(d * exp(-1.5 * (gp[1] - 3)))) / 2 + gp[3];
     58 		}
     59 		break;
     60 	case 4:
     61 		//pseudo random
     62 		for (int i = 0; i < num; i++) {
     63 			float ip = (float) i / num;
     64 			float d = trigFactor * (ip - gp[0]);
     65 			currentValues[i] = gp[2] * (4 + sinf(d * 29 - 3 + 16 * gp[1]) + sinf(-d * 24 - 2 + 39 * gp[1]) + sinf(d * 17 - 1 - 27 * gp[1]) + sinf(d * 109 + 12.2 - 17 * gp[1])) / 8 + gp[3];
     66 		}
     67 
     68 	default:
     69 		int k = 0;
     70 
     71 	}
     72 }
     73