Created
January 31, 2017 05:18
-
-
Save bigs/6afe1b4959113adb2c62553ce1b87b06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pulse threshold (v) | |
Param threshold(1.5); | |
// clock mul (pos) or div (neg) factor | |
Param factor(1); | |
History last(0.); | |
History ticks(0.); | |
History childTicks(0.); | |
History clockLength(0.); | |
History childClockLength(0.); | |
ticks += 1; | |
childTicks += 1; | |
// pulse detection | |
if (in1 >= threshold && | |
last < threshold) { | |
clockLength = ticks; | |
if (factor > 0) { | |
childClockLength = clockLength / factor; | |
} else if (factor < 0) { | |
childClockLength = clockLength * abs(factor); | |
} else { | |
childClockLength = clockLength; | |
} | |
ticks = 0; | |
} | |
// pulse generation | |
output = 0.; | |
if (childTicks >= childClockLength) { | |
output = 5.; | |
childTicks = 0.; | |
} | |
// shift last value | |
last = in1; | |
out1 = output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment