Sunday, 25 April 2010

OpenMusic and Chaos - OMChaos library

Our last few Algorithmic Composition posts have featured OpenMusic tutorials. We're continuing our look at OpenMusic today by looking at chaos, using the OMChaos library.

Chaos theory is a field of mathematics where dynamic systems are very sensitive to initial conditions. The famous 'butterfly effect' states that small differences can lead to large variations later: the small flap of a butterfly's wings may cause effects that later alter the path of a tornado.

Many of our previous algorithmic composition tutorials have used random elements (e.g. probabilities and Markov chains). Although Chaos might appear random, it's important to note that it is deterministic: if you run the algorithm again with exactly the same input it will produce the same output.

Today we'll start to look at using some Chaos algorithms to generate algorithmic music.

OpenMusic and Chaos - The OMChaos library
1. Make sure that OMChaos has been enabled in the preferences of OpenMusic.


2. Create a new patch in your workspace. OMChaos has 4 categories of functions: orbitals, IFS, fractus and UTILS.


3. The OMChaos orbitals menu features the core of the library. Each of these orbitals functions is a different chaos algorithm. Each of them shares the important chaos algorithm characteristic: small changes in initial conditions can lead to large changes later.

4. We'll start by using the KAOSN function.

5. This OpenMusic function is a form of a very common chaos algorithm fn+1=cfn(1-fn). That's to say: to get the next value of f, multiply the current values of c, f and (1 - f). This formula involves only 1 subtraction and two multiplies but it leads to chaotic behaviour. In this graph you can see with values of c below 3 the behaviour is very predicatable. However if c > 3.75 then very small changes in f lead to very large changes later on:


6. Here we've used 24 values for .95 for f 3.75 for c and set the length to be 24. Evaluating the KAOSN function will produce a series of 24 values based on these input parameters. Each time its evaluated it will produce the same numbers. If we change the input values to f 3.75 and c .94999, the numbers generated will start the same but slowly deviate as the sequence grows in length: the butterfly effect, small changes in initial conditions lead to large changes later on.


7. We'll use this chaos function to generate pitches between MIDI note 48 and 72. The output of the kaosn function is a series of floating point numbers between 0 and 1. To get the number in the range we want add:
  • an om* function and 24, giving our series a range of 0 to 24
  • an om+ function and 48 giving our series a range of 48 to 72
  • an om* function and 100, to change MIDI notes into the MIDIcents pitch representation OpenMusic uses
  • The om-round function rounds these numbers into integers

8. In this patch we'll have two voices with slightly different initial conditions for our chaos function. They will start playing identical notes and then slowly start to deviate. We'll append a reversed copy of the list, so we'll have a musical palindrome. To do this we can add cons and reverse functions. Reverse will reverse our original pitch list and cons will add this reverse pitch list to the end of our original pitch list. If you evaluate the cons function you'll see it's created list of lists (two sets of parentheses), we use the flat function here to flatten the list into a single set of parentheses:


9. Connect the output of voice, to the chords input of a voice.

10. We now need to duplicate what we have so far so we can create another set of pitches with slightly a different initial for our KAOSN function. Select all [CMD A on Mac, CTRL A on PC] and duplicate [CMD D on Mac, CTRL D on PC]. Change the second input to one your KAOSN functions to .94999, so that the two sections have slightly different initial conditions.

11. We also need to tell OpenMusic what rhythm to use for our melody. The voice function uses Rhythm Trees as its rhythmic representation. Rhythm trees are beyond the scope of this algorithmic composition post, but we will create some algorithmic music with rhythm trees in a future algorithmic composition tutorial. For now add in a repeat-n function and a mktree function. In this example we'll create 48 32nd notes:


10. Your patch should now look something like this (click on the image for a larger version):
11. To evaluate each voice press v, to play the voice press p to send it to a MIDI port. If you haven't done this already you can set up your MIDI outputs in OpenMusic preferences.

12. To hear both voices at the same time we need to create a list of both voices add in a poly function.


13. We can now hear both voices starting with the same pitches, slowly diverging and the converging back to the same pitches.

14. We'll be looking at rhythm trees in more detail in a future post, but for now to make the rhythms more interesting we'll use the nth-random function to choose randomly from a list of possible rhythms: (1/32 1/8 -1/16 -1/4 1/16) negative numbers represent rests. Repeat-n will generate a hundred of the randomly chosen rhythms:
15. Your final patch should look like something like this (I've changed the length of the sequence for both KAOSN functions to 50, giving us a melody 100 notes long when the reversed melody is added to the end). Click on the image for a larger version.



OpenMusic OMChaos Library Tutorial Summary
We've created an OpenMusic patch using the OMChaos library to generate chaotic pitches. Two voices have been used, with slightly different initial conditions the melodies diverge. Appending a reverse version of the melody on the end gives us a musical palindrome.

We then introduced the concept of rhythm trees in OpenMusic and randomly selected some rhythms from a given list.

Subscribe to the RSS feed and tune back regularly for more algorithmic composition tutorials, posts and reviews using Common Music, OpenMusic, PureData, MaxMSP and other algorithmic composition software.

No comments:

Post a comment