BBC Micro Music Masterclass

8: Automatic Composition

One of the most interesting areas being developed in the field of computer music is called autocomposition. As its name suggests, this technique involves allowing the computer to compose music without the direct influence of a human being.

The crudest method of achieving autocomposition is simply to feed random numbers into the SOUND statement as Pitch values. The following program is unlikely to enthral anyone who is not completely tone deaf for longer than about fifteen seconds but ably illustrates the results of the above-mentioned method:

10 REPEAT:Pitch=RND(64): SOUND 1,-15,Pitch*4,5:UNTIL0

One of the reasons why this type of ‘music’ is extremely unsatisfying to listen to is because it is virtually structureless. Over the decades, human beings have come to expect certain musical guidelines to be adhered to and while these guidelines vary from culture to culture their absence jars on the ears and the brain. A Japanese audience, by contrast with their Western equivalent, can remain riveted to their futons for hours on end listening to the musical structures which their ears have been trained to appreciate. Outsiders, however, would find it difficult to stifle yawns before a few minutes were up! Of course, this does not make the Japanese better or worse musicians than Westerners, but simply emphasises the fact that their musical vocabulary is different to ours.

The BBC Microcomputer has no inherent musical vocabulary whatsoever. To persuade it to compose sensible music we must first identify the basic principles involved in making music, then find a way of inputting this information into the Beeb. It is not feasible to attempt to give the computer a general musical education, for the simple reason that we would come up against memory constraints. Luckily this is not necessary (or even desirable). Most human musicians are actually severely limited in the range of music they can play and these limitations are much more severe than just a matter of Norwegian musicians being unable to play Indian tunes and vice versa. Most Jazz musicians have little experience of classical music and few classical musicians spend their leisure hours playing jazz. Consequently, when we try to musically educate the BBC, we must try to follow the human example and stick to a narrow stylistic vocabulary.

As I indicated in the Music Theory chapter over the centuries music has developed from being a matter of simple modes and scales to the plethora of styles and techniques which we enjoy and appreciate today. If you look around, you will notice that, of late, both jazz and classical music seem to have removed all harmonic restrictions from the shoulders of the composer. For this reason, amongst others the computer does not find it at all daunting to emulate modern avant garde styles!



...

In this program the random number generator is only restricted to values for Pitch within the BBC’s range and Durations which are reasonably short. Lovers of Shoenberg and the like should find this program extremely satisfying! In order to titillate the rest of us, I have also included a second avant garde program. Avant Garde 2 restricts the pitch interval from one note to the next. This is accomplished simply by introducing a variable P% which remembers the previous Pitch value. The REPEAT... UNTIL loop at Line 35 then holds back Pitches which would precipitate too big a leap:

...

OK, I admit it. This is not a fantastic improvement on our first attempt. Nevertheless, the technique of restricting intervals does make for more natural-sounding musical lines. You will doubtlessly be pleased to hear that further progress towards harmony are still possible. By far the biggest step towards aesthetically pleasing music is taken when we restrict the computer to scales. The next program sets up an array P%(22) which contains notes of the C Major scale. Line 150 then randomly picks values from the array.


10 REM"***MUSIC 1***
...

Note that in all the remaining programs in this chapter I have chosen a particular convention for recording Pitch values. Since at no point will we be dealing with intervals which are smaller than a semitone, I have made a semitone interval equal to 1 unit. Bearing in mind that this is the generally accepted convention for synthesisers, I have used the following formula to convert to BBC nomenclature from the absolute pitch values used by instruments such as the Roland MC -202 and the MC-4:

(Pitch*4)+5=BBC Pitch value

The table which follows accordingly gives the conversion from music symbols. You should quickly find that you can remember all the value of the notes which we use frequently.

For example, the C Major scale becomes:


The “Music 1” program contains all the main components required for auto composition:

1. A note source, usually a DATA statement containing, in this case, three octaves of the C Major scale.

2. An array to hold this note information while the program is operating (in this example P%(22)). Since each entry in the note source is numbered it is a simple matter to set up a random select routine which picks notes from the array.

3. A random choice statement. In “Music 1” this takes the form:

Pitch% = P%(RND(21)+ 1)*4+ 5

Random values of P%(22) between 1 and 22 are chosen and converted to BBC Pitch values using the formula as shown.

4. The pitch interval restriction is accomplished first by remembering the previous Pitch% in Line 190, with P% =Pitch%. The value of P% is then compared with the new Pitch% in Line 160. If the difference between the values (i.e. the size of interval) is greater than a set value (32 in this case, equalling 8 semitones) the loop is forced to REPEAT... UNTIL an acceptable value is generated.

Different intervals can be tried in order to hear their effect. Basically, the larger the interval the more erratic the music. The smaller the interval the more predictable the sound. As is so frequently the case in music, we are obliged to play off the twin evils of monotony and chaos...

The combination of restricted interval jumps and a scalar note source has given us harmonically acceptable music (for the moment we will neglect timing). Nevertheless merely listening to all the possible note combinations within a single Major scale eventually does get a little dull. The following program accordingly improves on “Music 1” in two areas. It first introduces a further note priority within the scale, and secondly a chord change is also introduced.




The note source in this program has been modified to include the Major chord in addition to the Major scale. This means that the notes C, E and G (0,4,7...) for C Major and G, B and D (2,7,11...) occur twice in their respective arrays. This makes it twice as likely that a chord note will be randomly chosen. This simple assumption is in fact, very effective in making the computer’s musical doodling more reminiscent of a human-style effort at composition.

Note that one further interval restriction has also been added. If Pitch%=P% then a REPEAT is forced. This stops the computer repeating the same note.

A chord change is introduced simply by setting up a two dimensional pitch array, P%(42,2) and alternating between the two dimensions every eight notes. It should be noted that since the key of this piece is C, I have used a mode of C Major as G scale information. As a general rule, the scale information should remain fixed no matter what chords are being played. The exception to this rule occurs when a key change occurs during a piece.

A key change was common to the ‘standard’ songs of the 40s and 50s but is less frequently encountered when you look at contemporary pop and folk music. For this reason the computers improvisations are more closely related to these simpler genres than the musically sophisticated standards of yesterday.

You might like to try substituting a G Major scale for the C mode as an experiment. As well as this, you should try different scales and arpeg-gios as note sources. The listing below gives the DATA for Pentatonic scales and Natural Minor scales, with arpeggios. Other possibilities include blues, diminished and whole tone scales, and these scales are given here:

Scale	Interval sequence

Major		 8  8  4  8  8  8  4
Diminished	 4  8  4  8  4  8  4  8
Blues		12  8  4  4 12  8
Hindu		 8  8  4  8  4  8  8 
Wholetone	 8  8  8  8  8  8
Dorian Minor	 8  4  8  8  8  4  8 
Aeolian Minor	 8  4  8  8  4  8  8
Harmonic Minor	 8  4  8  8  4 12  4
Pentatonic	 8  8 12  8 12

The music the computer is now composing closely follows many of the basic musical rules laid down by J. S. Bach and his predecessors. It is solidly grounded in the notes of the relevant chord and also employs scale notes to a lesser degree. No accidentals (sharp or flat) are used at all. It is, however, rather difficult to assess how well the computer is sticking to the chord changes. To make this easier why don’t you try the program “Bach 1”. This uses the same melody generation routine as “Music 2” but adds a two note chord accompaniment.






640
650 DATA 2,4,7,9, 11, 14, 16, 19,21,23,26,28,31,33,35,38,40,43,45,47,50,52,55,57,59,62

If we think of the melody line as a series of quavers (1/8th notes) then the chords only sound on the beat (every 1/4 note). In point of fact, a chord SOUND statement is put in the queue each time a melody note is played. This makes for easy SOUND synchronisation using the extended SOUND statement. The S value is set at 2 (two statements on other channels must be collected before all three can SOUND together), and the off beat rests are attained by using a silent volume ENVELOPE (ENVELOPE 3).

The loop Notes% is split in half and another loop C% is inserted. When C%=1 (an on beat) ENVELOPE 2 is selected and a chord is heard. When C%=2 (an off beat) ENVELOPE 3 is selected and no chord is heard.

“Bach 1” also lets you select either a Pentatonic or a Major chord/scale note source. Note that as it stands the program must be restarted to select the opposing set of DATA.

One possible extension of letting the computer compose melodies would be giving it control over chords. In practice, this move generates very unsatisfactory music. This is because even though there are a large number of possible sequences in theory, only a few are actually employed. A more constructive improvement to the program would be to let the user INPUT his or her own sequence and have the computer improvise variations over the changes. The next program allows you to do just that.

 10
 20
 30 REM"***BACH 2 ***
 40
 50
 60 REM"Set up and READ's DATA
 70 REM" into the Arrays....
 80
 90 CLS
100 ENVELOPE 1,1,0,0,0,0,0,0,126,-1,0,-1,110,80
110 ENVELOPE 2,1,0,0,0,0,0,0, 100,-3,-20, -40, 90, 0
120 ENVELOPE 3,1,0,0,0,0,0,0,0,0,0,0,0,0
130 S%=42:DIM P%(S%,7),Chord%(2,7),SEQ%(8)