Zum Hauptinhalt

Lesson 4 - Variables and random processes

Abschlussbedingungen
How to instantiate variables to automatise the process. Random object and scaling of results to control different parameters of the patch.

Lesson 4:

edu sharing object



Transcript

00:09 - Lesson 04. Variables and random processes. In this tutorial we are going to refine the “line” technique and learn how to use variables inside messages. As we’ve seen up to now, the messages we used to control the “line” contained fixed values. For example, now I go to 30% of the volume, 0.3 in 1 second and go back to 0 in half a second. 00:44 - But I might want to deal with one or even more dynamic values, perhaps controlled by sliders, for example. This would allow us to gain more control over the patch we are developing. To do this I need to replace the amplitude value with “$1” [string one] and the time with “$2”. The symbol for ‘string’ is the same as the dollar sign. For the moment we’ll justtake care of the amplitude and leave the time fixed as it is. “$1” or, more generally, the “$” symbol follow by a number corresponding to the variable count inside the same message, means that each number coming in through the message inlet will replace the “$” symbol, and as a result we will always have a list of two values. 01:39 - If I take a slider and set its “Properties” to go from 0 to 1, we can now have smooth volume changes. 02:03 - We can also connect a “print” object to check the list we get as result. 02:23 - More generally this “line”, used to control the volume, allows us to have smooth changes in the amplitude and prevents clicks that might happen if I were to set the volume abruptly using individual numbers instead of ramps of numbers. 02:42 - I could do the same to control the frequency of the oscillator. I take a horizontal slider, set its “Properties” to go from 50 to 1000 Hz (, connect it to the message going to the “line”, and replace the value that corresponds to the frequency with the variable “$1”. 03:21 - So now if I increase a little bit the volume and I start to move the horizontal “slider” I can dynamically set the rate at which the oscillator will oscillate. You can hear that a new frequency is reached, each time it is set, in 250 ms thus producing a little “glissando”. This makes each change, both in frequency and in amplitude, very smooth. Now we are ready to introduce a very useful object: “random”. 04:01 - As the name suggests “random” is able to generate random numbers. Let’s look for a moment at its help file. 04:14 - As you can see “random” requires an argument which represents the range of our random path. In this case we have 5, that means “random” will generate numbers between 0 and 4. “Random” requires a “bang” to generate the numbers, so let’s check it. 04:37 - Going back to our patch we type 1000 as argument for our “random” object. This means that “random” will generate random numbers between 0 and 999, which will correspond to the frequency in Hertz. 04:58 - The introduction of randomness in our patch allows us to to make a step towards the realm of algorithmic composition. This means that our compositions, in the form of Pure Data patches, will behave according to the sets of instructions we are going to develop and which may contain elements of unpredictability. 05:20 - We already saw in the help file that “random” requires a “bang” to work, so create one and connect it. 05:34 - Let’s listen to the result. 05:59 - Since we don’t want to bang it manually each time, we need another object, one which we already met in the previous tutorial, something able to generate “bangs”. Can you guess? Exactly, it is “metro”! So let’s create one, and assign it a time rate. Turn on the metro by creating a “toggle" and listen to the result. 06:50 - We have created a random arpeggiator of sinusoidal waves. We could implement the same random process for the volume as well. 07:04 - Let’s select copy and paste the part of the algorithm we want to use again. 07:17 - We mustn’t forget that volumes work in the range of 0 to 1. Since “random” is not able to generate floating numbers, all we need to do is to scale down by dividing the numbers coming out of the “random” object by 1000. 07:37 - Connect this to the slider controlling the volume or amplitude. And we shall try it. 07:52 - I can now have a more rhythmic behaviour by shortening the time of the ramp assigned to the volume and also, by listening to this carefully, by turning off the “metro” that controls the generation of the frequencies. Now the generated rhythm is clearly perceivable. 08:18 - As the last thing I can also add a “number box” connected to the cold inlets of both metros in order to control the rate at which the bangs are generated. 08:36- Let’s listen to the result now. 08:48 - With this basic patch I can already achieve an interesting variety of results. In the next tutorial we are going to introduce the principles of additive synthesis and we are also going to develop together the first patch ready-to-use with the data coming from external sensors, which will be introduced in the second part of this series.



Example Patch:

 

edu sharing object
 

Zuletzt geändert: Dienstag, 12. September 2023, 18:12