Introduction to writing algorithms

15
Introduction to Writing Algorithms. (In MINC) Christopher Bailey Hi!! I'm Sammy the Serialist, and I'm going to show you, through an example, the basic steps in creating a CMIX (MINC) algorithm. Along the way, we're going to use "Chris Bailey's 8-Step Method for Creating Algorithms" What are algorithms: Basically, the word "algorithm" usually refers simply to a way or method of doing a task, with the task usually being of a repetitive nature, or being something that can be described easily in an "overall" way. In computer music, examples of such tasks might be "play a chromatic scale" or "play 200 random notes" or "make a very cloudy tremolating sound." As a tool for composers, in other words, algorithms are most often used to generate textures. Generally speaking, in computer music, algorithms do two things: 1. make your life easier: you can use them to do some of the "thinking" for you (but remember, you have to teach the machine "how to think"), creating textures where the details don't matter as much as the overall effect; this is the most common kind of algorithmic composition: using algorithms to create clouds, lines, or whatever: soundfiles that you will insert into a larger piece. 2. For the exploration of things like style modeling, genetics, games, physical laws (gas particles dancing around, et al), artificial intelligence, etc. This gets into "deeper" aspects of algorithmic composition, which we won't get into here (Brad Garton's advanced class begins to explore this wonderful world. . .)

description

 

Transcript of Introduction to writing algorithms

  • 1. Introduction to Writing Algorithms.(In MINC) Christopher Bailey Hi!! Im Sammy the Serialist, and Im going to show you, through an example, the basic steps in creating a CMIX (MINC) algorithm. Along the way, were going to use "Chris Baileys 8-Step Method for Creating Algorithms"What are algorithms: Basically, the word "algorithm" usually refers simply to a way ormethod of doing a task, with the task usually being of a repetitive nature, or being something thatcan be described easily in an "overall" way. In computer music, examples of such tasks might be"play a chromatic scale" or "play 200 random notes" or "make a very cloudy tremolating sound."As a tool for composers, in other words, algorithms are most often used to generate textures.Generally speaking, in computer music, algorithms do two things:1. make your life easier: you can use them to do some of the "thinking" for you (but remember, you have to teach the machine "how to think"), creating textures where the details dont matter as much as the overall effect; this is the most common kind of algorithmic composition: using algorithms to create clouds, lines, or whatever: soundfiles that you will insert into a larger piece.2. For the exploration of things like style modeling, genetics, games, physical laws (gas particles dancing around, et al), artificial intelligence, etc. This gets into "deeper" aspects of algorithmic composition, which we wont get into here (Brad Gartons advanced class begins to explore this wonderful world. . .)What we want to look at here is how to use algorithms to create simple textures and other soundmaterials for use in your music. The idea/example illustrated here is rather assinine, but it doescover all the concepts you will need to know for basic algorithmic design.To make this process easier, I came up with simple way of thinking things through before andwhile writing code to accomplish a given musical task.Here it is: Chris Baileys Basic 8-Step Process 1) Think of and explore your idea, draw pictures, diagrams, and etc. to figure out whats happening in the different musical parameters. How is pitch changing? How is start-time happening? How is duration working? Remember that you dont necessarily have to write all of the notes in their temporal order: some algorithms may splatter notes in time randomly (not in time-order); others may write notes (or other sounds) in rhythm, from

2. first-to-last, time-wise. All sorts of possibilities can happen, so try to open your mind to different ways of solving whatever musical problem you have. 2) Divide job into loops. (Sometimes the task you have can be accomplished with one loop that writes all of the sound involved, other times you may want to have a number of loops write the sounds for different sections of a segment of music, for example.) 3) Basic set-up stuff: Here is where you write statements at the top of the score for things that wont be changing during the algorithmic process. Thus commands like rtsetparams() , opening input and output files with rtinput() and rtoutput() , certain makegen()s, (if theyre not going to be changing throughout the score), and so on. Repeat 4-7 for each loop 4) Outline each loop. Type your while or for statements, and then add brackets below, into which you will eventually insert your loop(s). 5) Action Statements. Write out the statements that actually make the sound. (typically the instrument name(s), as in WAVETABLE or the like.) Then fill in their parameters with variables. 6) Work outwards from the Action Statements, figuring out how each parameter will be determined each time the loop goes around--- pitch,duration,start, etc. 7) Initialize all variables before each loop starts. 8) Run it, test it, fix it, modify it, love it.OK, now I describe these steps in more detail: Step 1) Think of your idea. Draw a picture. Figure out whats happening in terms of pitch, rhythm (start-times), durations, articulations (amplitude envelopes), loudness, stereo placement, and whatever other factors are involved in the instrument(s) youre using. Sammy the Serialist Example, cont.: Lets see. . . I have an Evil 12 Tone Row, and I want to make a nice leapy melody, with the pitch-classes cycling through my Evil Row. Of course, they must always come in different octaves. The rhythm--well, Im an evil serialist, so of course I want it to be based on my row. The duration of any note will be simply to sound until the next note. I want the articulations to be either an Sfp attack, or else a hairpin () kind of articulation. Loudness-- well, of course, it, too must be based on the row! HaHa! And stereo placement too!! Ha ha ha!! 3. So, now youve thought of how your musical excerpt is going to work. Now, go on to the nextstep-- step 2) Divide your job into as many separate simple-as- possible loops as you can. In general, a single loop should create either a single line, or a uniform or uniformly changing texture.Sammy Example, cont.: I think I will only need one loop, since I am creating one line ofpitches. Later on, for counterpoint, I can use more loops. step 3) Begin by defining basic stuff, like your output file, your input files, any makegens that stay the same for the entire thing, etc.Sammy Example, cont.:rtsetparams(44100, 2)rtoutput("evil.rows.aiff")makegen(1, 10,1000, 1, .2, .2, .2, .1)These are the basic setup items for our script. "Timbre" stays the same--(which, forWAVETABLE is makegen slot 1). But articulation, (i.e.--amplitude envelope, which forWAVETABLE is makegen slot 2, (and usually type 24)) changes, so that will be "in" theloop--well get to it later on. step 4)Write the outlines of your loop(s). This means, basically, control (while or for) statements, plus (if necessary) a statement at the end of the loop that increments your counter.while: As long as the expression in () is True, then the stuff below, the statements in {} willexecute. After the stuff in {} is done executing, the () expression is tested again, if stillTrue, then the statements in {} are executed again, and so on, until the () expression isFalse, then the {} stuff is skipped and the program goes on.Example:while (x