09.12.2012 Views

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Markov Chain<br />

In <strong>Kyma</strong>, the MarkovChain is a generic object, not necessarily tied to musical applications. It is a kind of<br />

sparse, fast-food version of the classic Markov chain: instead of weighted transitions, you give it a<br />

“training sequence” in the <strong>for</strong>m of an Array, and it constructs weighted transitions based on what transitions<br />

occur and how many times they occur in the training sequence. Once you have “trained” the object<br />

this way, you can ask it to generate any number of sequences, each of which will be statistically related to<br />

the original training sequence you gave it.<br />

For example, if you evaluate the following, short program,<br />

| chain seq |<br />

chain :=<br />

MarkovChain<br />

trainingSequence: #(<br />

what is your name<br />

is it an animal name<br />

or is your name one that would belong to a human<br />

like my name is a name that would<br />

belong to a very human being<br />

)<br />

chainLength: 2.<br />

seq := chain newSequenceOfLength: 100 seed: 9008.<br />

you might get something like this as the result:<br />

OrderedCollection(your name is a name that would belong to a very human being)<br />

Since the chain length is 2, every pair of words in the generated sequence is one that occurs in the original<br />

training sequence. However, the entire chain is something new, not found anywhere in the sequence.<br />

Each time you ask the MarkovChain <strong>for</strong> a new sequence, giving it a different seed, the result will be a<br />

new sequence. Notice that we asked <strong>for</strong> a sequence that was 100 words long; when the MarkovChain<br />

backs itself into a corner and can’t find any more legal transitions, it returns what it has been able to come<br />

up with so far.<br />

Now let’s look at a musical example. Here’s the script from the example called modified Markov chains:<br />

| t chain dur pitchOffset seq |<br />

MM := 160.<br />

chain :=<br />

MarkovChain<br />

trainingSequence: #(<br />

#(0 4) #(3 2) #(-5 2) #(2 4) #(3 2) #(-5 2) #(2 4)<br />

#(3 2) #(-5 4) #(2 2) #(3 2) #(-5 4) #(2 2) #(-5 2)<br />

#(5 2) #(-7 4) #(1 2) #(-2 2) #(1 4) #(0 0.5) #(12 4)<br />

)<br />

chainLength: 2.<br />

t := 0.<br />

1 to: 10 do: [ :i |<br />

seq := chain newSequenceOfLength: 100 seed: i * 26.<br />

seq do: [ :offDur |<br />

dur := (offDur at: 2) / i.<br />

pitchOffset := offDur at: 1.<br />

self<br />

keyDownAt: t beats<br />

duration: dur beats<br />

frequency: 1 g + pitchOffset nn + i nn<br />

velocity: i/10.<br />

t := t + dur]].<br />

144

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!