0:47

So let's talk about stochastic composition versus chance.

It kinda comes down to a couple of key questions here.

One is how many random decisions are we making?

Because if we're making a lot of random decisions of not just five or

ten but hundreds or even thousands of random decisions, then,

we have the ability to really shape the probability distribution of

those random numbers in a meaningful way.

So that they're not just coming out with an even chance of any number coming out.

But if we stack the odds basically, if we make some odds more likely than others,

if we do that enough, then we're going to actually be able to hear that, and

hear the effect of that in the music.

So if we make enough random decisions, we have this ability to use

stochastic techniques to control the distribution of those random decisions and

the results of them and shape the music that way.

The other thing that we can think about is how are those decisions structured?

In other words, are we just kind of blindly taking the random numbers that

come out and then using those to kind of, you feed into function arguments,

or some effects value, or something like that?

Or are we thinking really carefully about the mapping that's behind these?

Kind of how are we taking this and bringing it in a musically

sensible way that supports what we're trying to do in music.

So I'm gonna walk through both of these as we refine the example that we built in

the last video to make it more an example Stochastic composition and

less an example of Chance composition.

So the first thing I want to talk about are probably distributions.

So far, we've been using things like the random function from Python, and

we've had uniform distributions where every outcome is just as likely

to arise as any other outcome.

So with random, you're just as likely to get any number between zero and

one as any other number.

They're all equally likely.

Same way as if you flip a coin, you're just as likely to you get heads or tails.

So you might get three heads in a row or even ten tails if you feel really lucky.

But if you do thousands and thousands of coin flips, eventually,

you're gonna converge on a uniform distribution where you've gotten

just about the same number of heads and tails.

Same thing is true with random.

What we're gonna look at now is a different

kind of probability distribution, a Gaussian Distribution.

You've all probably seen something like this bell curve-like thing before,

where you have a central value which is kinda the one that's maximally likely to

come back, and then some kind of slope out from there.

And so, as you get towards the edges, things become decreasingly likely,

so you're very unlikely to get these values.

You're very unlikely to get those values, you're very likely to get that,

then you're pretty likely to get those, and those, and so on and forth.

So we can use the gauss function in Python to create one of these

Gaussian Distributions, so

that we can control the likelihood of different outcomes coming through.

And we specify in terms of two different arguments, one is the mean,

which is the central number here, And the second one is the standard deviation,

which controls the slope of this, essentially.

So the higher the number, kind of the flatter that becomes, and

the more is under the bell of that curve.

So now let's look at the script that we wrote in the last video to try to make

Maximally random choices about what sounds to use and

where to place them in [INAUDIBLE].

And where going to use a Gaussian distribution on our start times.

So, that we try to clump a lot of our sounds and

make them really dense in the middle and have the music be a little bit thinner or

sparser in the beginning and in the end.

So, I need to go to the start timeline here and

random is giving me a uniform distribution.

So I don't wanna use that anymore.

going to delete that.

I still want the one plus because I want to make sure all my sounds start at

measure one or later.

But i'm going to use Gals command now,

Gals function to create galaxy distribution,

sent it around eight and spreading by a factor of three.

So that's all I really need to do to create a galaxy distribution here.

But I am going to make a couple of other small changes.

I'm gonna create more sounds.

And this way we get, that distribution will come through even better, and

we'll be able to see it better.

And I'm gonna spread that across more tracks.

Again, to keep the...

Since I have more sounds here I wanna keep the chance of,

of overlap on the same track of two sounds, as low as possible.

So, I'll go ahead and run that.

5:54

So it still sounds very random, but

we are hearing these changes in density according to the Gaussian Distribution.

And so I want to look at this second question,

we've covered the distribution part of this, and this is

kind of a macro level attempt to create a sense of a large scale form to it.

Cuz, you know, this kind of diagram also corresponds to something we see in music

a lot, an arch form, where you kind of build up tension or density.

Towards the middle are some climactic point piece,

and then you decrease it again towards the end.

So we've done something along those lines by creating this calcium

distribution in terms of the density of our sounds,

how many sounds are happening at any given time?

But we've left something out, and

that's that We've kind of ignored the meter of the music here.

A DAW is very good in giving us a timing grid.

And all these sound files were created with a tempo and a meter in mind.

And we've kind of ignored that because we're randomizing the starting point to

a floating point number so

it can start from any point in the middle of the measure.

So, what I want to do is try to bring back some of that sense Of beats, and meter,

and tempo of this music.

Now I wanted to bring in some math functions to do that.

So here is some common functions in the math library in Python.

So this is a whole other API, where if we wanted to use we would use it we would

start off our Python script with this line "from math import *".

Then we get all these things like sines, and cosines, and tangents and

things like that.

I want, in particular, just use One simple function right now, floor of x.

That basically returns an integer that's the highest integer that's still

less than whatever x is.

So if x is 1.25,

the floor of it is gonna be a one.

If x is 3.14159, floor.

is going to be three and so on and so forth.

Okay, so now let's apply some of those ideas about quantization.

to our script to have the starting and

end times of each of our sounds align with beats and measures of music.

So the first thing I'm going to do is I have to import the math library so

I can use the math functions from Python that I want.

So I'm going to add a line up here for math import *.

And the next thing I need to do is look at my start time,

so I've got the gauss in distribution, I want to keep that.

But I wanted to always start at the beginning of the measure.

So I'm gonna use the floor function from the Python math library to do that.

So, the gauss function is gonna generate a floating point number and

the floor function is basically gonna take of the decimal points.

So it's the lowest integer,

that's the integer just below whatever number I have there, so if we start off.

With an integer that's 3.547,

when I apply the floor function it's just gonna be 3.

And now let's look at the end time, my duration here.

So I'm using random still here.

So it's gonna be a random floating point number between 0 and 1.

But I wanna quanize this so it lasts a certain number of beats now instead.

So I'm gonna use rand int instead to give me an integer between two and four.

So rand int will either return two or three or four and

multiply that by zero point two five.

And what that's doing is I basically

have either zero point two give times two, zero point two five Times three.

Or 0.25 times 4.

So 0.25 times 2 would be two beats.

0.25 times 3 it means it will last three beats.

And 0.25 times 4 will be four beats which is a full measure.

So each time we're going to start at the beginning of the measure,

that is the four function is doing for us.

And we're gonna end after either 2, 3, or 4 beats.

So let's go ahead and run this, and see what happens.

9:58

And again I'm gonna hide the code view so we can see all the tracks at once.

And you can see how the starts are always aligning with the starts of measures.

And the ends are always a lining with either B3, 4 or

the start of the next measure.

So, let's listen to this.

[MUSIC]

So we're still

hearing these

changes according

to the Gaussian

distribution and the density.

But we're also hearing a sense of meter, a sense of some kind of regular pulse going

through this because the sounds are always starting at the beginnings of measures and

lasting a particular number of beats.

I wanna just talk about an important historical example of stochastic

composition.

This is a Greek composer named Iannis Xenakis.

He actually helped develop a software program called ST.

Which stood for stochastic music.

And he wrote a number of pieces with this.

This piece is called ST/10.

Which meant it was written for ten musicians.

And he wrote this in 1962.

And the way this worked was his program actually didn't generate sound it just

generated note data.

Things like start time,

what instrument in that ensemble of ten musicians is playing the note.

What its pitch is, what its duration is, what its dynamic is.

And he loved glissandis, so there were actually a few different

parameters that controlled where there was a glissandi, and

if so, whether it was up or down, and how Farms going and things like that.

And once you got that new data out of the computer, you transcribed it, not so

different from what Hiller and Isaacson did with ELIAC suite, that we look at in

the first video in this module, to transcribe this new data onto a musical

score, that musicians could then rehearse and perform on traditional instruments.

and there's sarcastic decisions being made throughout as you can control things like

the parameter of this note data that we just discussed above.

The density of notes in a particular section,

how long a section is of the music and so on and so forth.

You can use a variety of different distributions including normal and

galaxy distributions that we looked at here Now and to make one final point here.

Which is that stochastic music is not limited to a kind of avant-garde or

experimental musical practices.

Just yesterday I was playing on my iPad Garage Band with my son.

and he opened up this smart drum instrument on it where you actually

drag pictures of drums onto a grid and

the y axis of where you place them controls the dynamic.

The x axis is complex on one side and simple on the other and so

you're controlling this sarcastic aspect of how Each drum within the selection

of different drum samples is playing how dense it's being triggered.

And then as if that's not enough,

there's a little picture of a dice at the bottom of th screen.

If you hit the dice, it will randomly place different instruments in different

places on this grid, to create a new drum pattern for you.

So the The kind of consumer purpose of it in a program like that seems to be that

everyone wants their own kind of unique drum pattern.

But they don't necessarily want to program it from scratch,

the way we might in a pattern sequencer.

So this kind of stochastic approach gives people the ability to generate over and

over and over again, until they find something that they like, or

to tweak the parameters of each of things until they find something that they like.

So to review what we've done in this video, we've talked about the differences

between chance and stochastic music in terms of distributions and mappings.

We've looked at probability distributions, such as Gaussian distributions

As a way to structure chance decisions into a more stochastic approach.

And we also looked at math functions, like the floor function,

to help us quantize and kind of use the metrical grid to perform

different kinds of mappings with our random numbers.

And then finally we looked at the music Iannis Xenakis As an example of stochastic

techniques in composition.

In the next video, we're gonna look at a very different approach to algorithmic

composition in the form of process music.