//Osci osci, osci_shifted; final static int SIN = 0; //add 0.25 to phase to get cos final static int TAN = 1; final static int LINE = 2; final static int SQUARE = 3; //switches between -1 and 1, that's all final static int RAMP = 4; //line for half the sequence up to 1, then stay at 1 for the other half final static int RAMPUPDOWN = 5; //line up, stay, line down, stay. use this when drawing a square once for x and once for y with a phaseshift of .. what was it.. 0.5 or 0.25. try it final static int COS = 6; final static int RANDOM = 7; final static int INTVAL = 100; final static int FLOATVAL = 101; class Osci { //it's a wave generator float delta; float beats; float inc; boolean playing; int mode; int[] modes; float phaseshift; float value; float startFrame; //resets after every playthrough //color c; Osci(float beats_, float phaseshift_, int mode_) { //how many beats one cycle takes, the more, the longer. beats = beats_; phaseshift = phaseshift_; inc = phaseshift * TWO_PI; mode = mode_; modes = new int[1]; modes[0] = mode; start(); } /* Osci(int[] modes_) { //for random int[] possibleBeats = {1, 2, 4, 8, 16, 32, 64}; beats = possibleBeats[(int)random(possibleBeats.length)]; modes = modes_; phaseshift = (random(1) > .8) ? .25 : 0; inc = phaseshift * TWO_PI; mode = modes[0]; start(); }*/ void start() { /// start - reset delta = (8 * TWO_PI / beats) / ((60 * frameRate) / bpm); playing = true; startFrame = frameCount; } void stop() { playing = false; } void update() { if (playing) { inc += delta; if (inc > beats*16*TWO_PI) inc -= beats*16*TWO_PI; switch(mode) { case(SIN): value = sin(inc); break; case(COS): value = cos(inc); break; case(TAN): value = tan(inc); break; case(LINE): value = ((inc % TWO_PI)-PI)/PI; //value = ((inc % (TWO_PI-(TWO_PI*phaseshift)))-PI)/PI*1+2*phaseshift; //println(inc % TWO_PI); break; case(SQUARE): value = sin(inc+(phaseshift*TWO_PI)) > 0 ? 1 : -1; break; case(RAMP): value = sin(inc) > 0 ? ((inc % TWO_PI)-PI)/PI : 0; break; case(RAMPUPDOWN): if (sin(inc) < -0.666666666) { value = -0.666666666; } else if (sin(inc) < 0.666666666 && sin(inc) > -0.666666666) { value = sin(inc); } else if (sin(inc) < 1 && sin(inc) > 0.666666666) { value = 0.666666666; } value *= 1.5; break; default: break; } value = constrain(value, -1, 1); if (frameCount > startFrame + (((60 * frameRate) / bpm) * beats) /2) { value = (mode == RANDOM) ? random(-1, 1) : value; //println("beat hit. that's " + str(frameCount - startFrame) + " frames since the last beat"); startFrame += (((60 * frameRate) / bpm) * beats) /2; onRepeat(); } value = map(value, -1, 1, 0, 1); } } void onRepeat() { //println("beat played.."); //background(c); } /* void display() { fill(0); stroke(2); strokeWeight(3); point(width/2, ((value + 1) / 2)* height); }*/ }