Created
March 16, 2012 22:57
-
-
Save jordanorelli/2053446 to your computer and use it in GitHub Desktop.
primitive markov chain (in chuck)
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
200::ms => dur beat; | |
"A" => string currentState; | |
ADSR env; | |
env.set(20::ms, 20::ms, 0.6, 20::ms); | |
env.keyOff(); | |
SinOsc s => env => dac; | |
fun void enterState(string stateName) { | |
if (stateName == "A") { | |
enterState("A", 200); | |
} else if (stateName == "B") { | |
enterState("B", 300); | |
} else if (stateName == "C") { | |
enterState("C", 400); | |
} | |
} | |
fun void enterState(string stateName, float freq) { | |
stateName => currentState; | |
freq => s.freq; | |
env.keyOn(); | |
beat / 2 => now; | |
env.keyOff(); | |
beat / 2 => now; | |
} | |
while(true) { | |
Math.rand2f(1, 100) => float i; | |
if(currentState == "A") { | |
if(i <= 20.0) { | |
enterState("B"); | |
} else if(i >= 80.0) { | |
enterState("C"); | |
} | |
} else if (currentState == "B") { | |
if(i <= 40.0) { | |
enterState("A"); | |
} else if(i >= 50.0) { | |
enterState("C"); | |
} | |
} else { | |
if(i <= 25.0) { | |
enterState("A"); | |
} else if (i >= 35.0) { | |
enterState("B"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment