Showing posts with label maxmsp. Show all posts
Showing posts with label maxmsp. Show all posts

Tuesday, 12 January 2016

Sonification - Algorithmic Composition


Today's algorithmic composition tutorial uses sonification as a composition tool. Sonification uses data that is typically not musical and involves remapping this to musical parameters to create a composition. 

Sonification can be used to hear information in a set of data that might be otherwise difficult to perceive, common examples include Geiger counters, sonar and medical monitoring [ECG]. When creating sonification algorithmic compositions we are interested in creating interesting or aesthetically pleasing sounds and music by mapping non-musical data directly to musical parameters.

Here is some example output:


The Sonification Process:
There are four simple steps involved in creating a sonification composition.
1.            Find some interesting data
2.            Decide which musical parameters you want to map the data to
3.            Fit the input data to the correct range for your chosen musical parameters (normalise)
4.            Output remapped data to MIDI synths, audio devices etc

Step 1 – Find an interesting set of data
First of all we need to source a data set. You can use any data you like stock markets, global temperatures, population changes, census data, economic information, record sales, server activity records, sports data - any set of numbers you can lay your hands on, here are some possible sources: Research portal, JASA data, UK govt data
 
It's important to select your source data carefully. Data that has discernable patterns or interesting contours works particular well for sonifications. Data that is largely static and unchanging will not be interesting, similarly data that is noise-like is usually of limited use.

Here we've loaded some example data into a coll object in PureData

And similarly in Max:

algorithmic composition maxmsp sonification

Step 2 - Map Data to Musical Parameters
The second step is the most creative of the sonification process. It involves making creative decisions about which musical parameters to map the data to e.g. pitch, rhythm, timbre and so on. 

This is more of an involved question than it initially appears, if we choose to map our data to pitch, we also have to choose how these pitches will be represented:
 
Frequency (20Hz - 20kHz): this is useful for direct control of synths, filter cutoffs etc, but is not intuitively musical and typically needs conversion if working with common musical scales
MIDI notes (0 - 127): assumes 12 note division of the octave, no representation of C# versus Db
MIDI cents
•    OpenMusic uses a MIDIcents representation. This is equivalent to MIDI notes * 100 so middle c is 6000
•    This enables microtonal music and alternative divisions of the octave, for example dividing the octave into 17.
Pitchclass
•  octaves are equivalent
Scale degree
•    Assumes use of a scale and returns the degree of that scale.
•    This is useful as we can easily deal with uneven steps in the scale simply

Step 3 – normalise data to fit musical parameters
In Max we can use the scale object. Scale maps an input range of float or integer values to an output range. The number is converted according to the following expression
 y = b e-a c x  c

where x is the input, y is the output, a, b, and c are the three typed-in arguments, and e is the base of the natural logarithm (approximately 2.718282).


expr $f4 + ($f1 - $f2) * ($f5 - $f4) / ($f3 - $f2 )
1 = number
2 = input min
3 = input max
4 = output min
5 = output max

Step 4 – Output
Adding in some MIDI objects allows us to hear our data sonified in a simple way:
algorithmic composition sonification maxmspAnd in PureData adding in a makenote and noteout objects and normalising our output data to one octave of a chromatic scale looks like this.sonification puredata algorithmic composition
You should now have some basic musical output to your MIDI synth. Now the patch is setup it’s easy to experiment with mapping the data to different pitch ranges. For example:
  • Try adjusting the normalisation (the scale object in Max or expr object in PureData) to map the data across two octaves instead of one by changing the output range from 12 to 24 – or any other pitch range.
  • The + 60 object sets our lowest pitch as MIDI note 60, this can be modified easily to set a different pitch range.
  • Invert the data range by having a high output minimum and a lower maximum, so ascending data creates descending melodic lines.
Mapping to Scales
As an alternative to mapping our data to chromatic pitches we can use a different pitch representation and map our scale to the notes of a diatonic scale.
First we need to define a few scales in a table in Max:
sonfication algorithmic composition maxmsp
As the contents of tables are defined slightly differently in PureData this looks like this:
sonification algorithmic composition puredata
The above screenshots show the scale intervals for a Major, Harmonic Minor, Melodic Minor and Natural Minor scale being stored in a separate table for each scale. These are stored as pitchclasses, if we need to transpose or modulate our composition to another key we can add or subtrack to these scale notes before the makenote object e.g. to transpose up a tone to D add a + 2 object. Now rather than mapping to chromatic pitches we’ll map to scale pitches so we’ll need to modify our normalisation to reflect this.
sonification puredata algorithmic composition
Here we’ve changed the output range to be 0 to 6 to reflect the seven different scale degrees of the major scale. Similarly in Max:
sonification maxmsp algorithmic composition
We are now mapping our octave to a major scale, as we have already stored a number of scales you could try changing the name of the table that is being looked up to map to an alternative scale e.g. table harmonic-minor-scale.
We can also map the data to a scale over more than one octave.
sonification algorithmic composition puredata
Here we’ve changed the output range in this example to be 0 to 20. Using % (modulo) to give us the individual scale degrees and / (divide) to give us the octave. The process is the same in Max, although in the previous example we mapped across 3 octaves of the scale there’s no requirement to map to full octaves, you could map your data to 2 1/2 octaves or any other pitch range by changing the output values of the scale object (expr in PureData):
sonification algorithmic composition maxmsp
So far we have mapped our data to MIDI pitches. The next example maps the data to frequencies and uses this to control the cutoff frequency of a band pass filter that is fed with noise. This gives a sweeping windsound effect.
As an alternative to MIDI output we’ll map our wind data to the filter cutoff of a bandpass filter that is fed with noise. As we’re know working with frequencies rather than MIDI notes we’ve changed the output of the scale object to remap any incoming data between 200Hz and 1200Hz:
algorithmic composition maxmsp sonification
The patch is setup in a very similar way in PureData with a bp~ object as our band pass filter, rather than the reson~ object found in MaxMSP.
puredata algorithmic composition sonification
Although all of the notes are created by mapping the data directly to pitches we have made another of creative decisions along the way, so there are many ways of realising different sonifications of the same source data. So far we have only mapped to pitch however we still have a number of variables we can alter:
scale – chromatic, major, melodic minor, natural minor, harmonic minor (any other scales can be defined easily)
base pitch (the lowest pitch )
pitch range (range above our lowest pitch e.g. 2 octaves)
the data set used to map to pitches
As with any composition we also have to make musical decisions concerning which instrument plays when, timbres and instrumentation, dynamics, tempo etc. In another post we’ll look at sonifying these elements from data but for now we’ll make these choices based on aesthetic decisions.
Summary
In the youtube example we have added several copies of the sonification patch so we have one for each of our data sets (temperature, sunshine, rainfall and windspeed). The interesting thing about using weather data is that we should hear some relationship between the four sets of data.
We’ve also added a score subpatch with sends and receives to turn on and off each section and control the variables mentioned above (min pitch, pitch range etc).
After the getting the patch to work play around with your own settings and modifications and check out part two of this sonification algorithmic composition tutorial. Future posts will continue the idea of mapping and explore sonifying rhythm, timbre and other musical parameters. Have fun and feel free to post links to your sonification compositions below.
Post a comment if you’ve any questions on this patch.

Automatic Breakbeat Generator – Max

In this post we’ll create an automatic Breakbeat cutter in Max that will play randomised selections from a sampled drum loop. We’ll also use this together with a Markov melody generator. You can hear some sample algorithmic composition output in this example and download the patch at the end of the post:
A Quick Recap
We have used objects, messages, numbers, buttons and toggles. All of these (and more) can be inserted by double clicking in a blank space or using the keyboard shortcut.
maxmsp basics
Breakbeat Generator
We’ll now start building the breakbeat generator.
We’re going to create an automatic breakbeat generator patch. This will patch will chop up drum loops. This patch will create a breakbeat effect by chopping a sample into 8 and rather than playing straight through in order, playing:
  • 3 consecutive parts chosen from a random start point.
  • 3 consecutive parts chosen from a random start point.
  • 2 consecutive parts chosen from a random start point.
e.g. from the 8 sections of our loop, some 3+3+2 examples could include:
  • 2 3 4 / 6 7 8 / 3 4
  • 5 6 7 / 1 2 3 / 5 6
  • 4 5 6 / 2 3 4 / 6 7
  • 6 7 8 / 5 6 7 / 2 3 etc
Create this patch. This will load, play and cutup our drum loop sample.
algorithmic composition breakbeat generator maxmsp max
Note: ‘p’ stands for patcher in Max Double click on this object and we can edit what’s inside it. Add this to the inside of the patcher:
maxmsp breakbeat generator
We created the Markov Melody Generator in this previous algorithmic composition post
markov chains max maxmsp
The breakbeat generator and Markov chain generator are both connected to a toggle so they can be started at the same time.
maxmsp breakbeat generator4
You can download the Max patch here. Patches for older posts will also be uploaded soon. Check out the algorithmic composition forum to introduce yourself and ask any questions.

Saturday, 3 September 2011

Tone Rows - PureData and Max

Today's algorithmic composition tutorial looks at manipulating a tone row in Max and PureData to generate musical material. We'll also have a look at one technique that's useful in generating more fully formed compositions in Pd and Max than some of the musical sketches we've generated so far.

Jump to the end of the post to hear some sample algorithmic music output from this patch.

As with yesterday's OpenMusic tutorial we're using the tone row from Berg's Violin Concerto:

  G, Bb, D, F#, A, C, E, G#, B, C#, Eb, F

You can use any tone row of your choosing. To start with we'll define our tone row in a table in PureData

algorithmic composition puredata tone rows1
and in Max
algorithmic composition maxmsp tone rows1
We'll start simply by playing through the tone row. As Max and PureData read and write to tables in slightly different ways the patches are setup a little differently in each. In Max the table object is used to read the table data:
algorithmic composition maxmsp tone rows2

Thursday, 18 August 2011

Chaos in Max and PureData

We've looked at a few algorithmic composition ideas using Chaos in OpenMusic here, today's post applies some of these ideas algorithmic composition ideas in Max and PureData.

Chaos theory is a field of mathematics where dynamic systems are very sensitive to initial conditions. The famous 'butterfly effect' states that small differences in initial conditions 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.

As with our OpenMusic chaos patch, for this example of Chaos in PureData and Max we'll use a logistic map. The Logistic Map is a simple example of a discrete dynamical system that actually names a whole family of iterative functions described by the very common Logistic Equation:

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:



Tuesday, 16 August 2011

Tom Johnson's Algorithmic Compositions Part 2

A previous post looked at some of the algorithmic composition ideas used by American Composer Tom Johnson. Today's algorithmic composition tutorial looks at a few more of Johnson's concepts specifically his use of finite automata.

A finite automaton is a sequence using a finite number of symbols generated according to specific rules. In the case of Johnson's Automatic Music, six percussionists each have only two notes, high and low, and the alphabet is limited to 1 (the low note), 2 (the high note), and 3 (a silence) using the following rules:

1 --> 1 1 2
2 --> 3 2
3 --> 3 3

Beginning with 1 generates the following sequence:

   112112321121123233321121123211211232333233333332

Using this automaton it's easy to generate long sequences of numbers that can be then mapped to musical parameters. As ever with algorithmic composition, once you've created your patch or program it's easy to manipulate the formula or remap the musical output to generate new pieces.

Let's have a look at a simple example using PureData and Max. This screenshot shows the generation part of our algorithm in PureData.

The until object will output 500 bangs when the above message is clicked on, the counter outputs a running count of these bangs and this is used as a number to lookup the stored value in the coll object. The output of the coll is connected to a select object and this triggers the new messages that are stored within our coll object.

In Max the patch looks very similar though note the use of Uzi rather than the PureData until object.

Monday, 27 June 2011

Tom Johnson's Self Similar Melodies

The American Composer Tom Johnson often uses simple mathematical principles in his compositions. Today's algorithmic composition tutorial looks at a few of Johnson's algorithmic concepts and applies them using Max and PureData. As Max and PureData use slightly different objects to read and write data from tables we'll include screenshots of the algorithmic composition patches from both applications.

Self Similar Melodies
This first example taken from Johnson’s now out of print book ‘Self Similar Melodies’ makes use of the following expression:

                        n             n+1            n-1             n

Inputting a zero into our algorithm gives us the following four numbers:

                        0            1            -1            0

It’s easy to apply this in PureData:

and in Max:


Sunday, 23 May 2010

Algorithmic Composition with timbres: Klangfarbenmelodie

Algorithmic composition often tends to focus on pitch and rhythm. Today's algorithmic composition tutorial concentrates on timbre, creating algorithmic music by outputting MIDI from MaxMSP [Max] and PureData [PD].

Klangfarbenmelodie (German for tone color melody) and the synonymous French term mélodie de timbres distributes a melody over several instruments rather than assigning it to just one, the listener's focus becomes timbre rather than pitch.

In a similar way, the algorithmic composition patch we'll build today outputs series of overlapping randomly chosen timbres to create an interesting musical texture.

Jump to the end of the post to hear some sample algorithmic music output from this patch.

Algorithmic Composition with MIDI Timbres
Firstly we'll get a simple MIDI note to play in Max and PureData: add a toggle, a metronome object, a message and makenote and noteout objects. If you're not sure how to do this, work through some of the earlier algorithmic composition tutorials here:
Your Max or PureData patch should now look like this, you should also hear a MIDI note when you turn the toggle on. If not, check you have a MIDI output device selected.
algorithmic composition with timbre Max 1algorithmic composition with timbre PureData 1