A Simple Method to Produce Algorithmic MIDI Music based on Randomness, Simple Probabilities and Multi-Threading
aa r X i v : . [ c s . S D ] D ec A Simple Method to Produce Algorithmic MIDI Music based onRandomness, Simple Probabilities and Multi-Threading
Yannis TzitzikasComputer Science Department, University of Crete, Greece, andInstitute of Computer Science, FORTH-ICS, Greece [email protected]
October 2, 2018
Abstract
This paper introduces a simple method for producing multichannel MIDI music that is basedon randomness and simple probabilities. One distinctive feature of the method is that it producesand sends in parallel to the sound card more than one unsynchronized channels by exploiting themulti-threading capabilities of general purpose programming languages. As consequence the derivedsound offers a quite “full” and “unpredictable” acoustic experience to the listener. Subsequently thepaper reports the results of an evaluation with users. The results were very surprising: the majorityof users responded that they could tolerate this music in various occasions.
The work presented in this paper started while we were investigating a possible programmatic assignmentfor the needs of a university course on object-oriented programming, that involved the usage of a libraryfor MIDI music. We ended up posing to ourselves questions like: • Can we produce algorithmically music which can be acceptable (or even pleasing) by humans?Does this requires having knowledge background in music? • Can we produce potentially infinite (in length) music that is not periodic (and thus not boring)? • Can we make humans perceive that such algorithmically-produced music is human-made?A positive answer to the above questions would be interesting from various perspectives. A very concreteand practical benefit is that we would be able to produce infinite series of music without having to careabout the space required for storing that music, since only the algorithm that produces the music wouldhave to be stored. Another concrete benefit is that if the composition method does not require backgroundin music, then any user could easily compose, or adapt, such mucic to his/her preferences or situation.In this paper we present an algorithmic method for producing MIDI music semi-randomly. Thecomposer provides as input a very short specification of the desired notes and their frequency , thedesired instruments , and the desired octaves and durations . An algorithm reads this specification andby randomly picking elements from that specification, produces sequences of MIDI music of the desiredlength. One distinctive feature is that more than one channels are produced and are sent in parallel tothe sound card, and this feature makes the derived mixed music more interesting and less expected.Another characteristic of the proposed algorithm is that it is “context-free”, i.e. for producing thenext score the algorithm does not consider what it has produced before. This means that the only“memory”, or “pattern”, that is used, is actually the memory of the employed random generator.The evaluation with users was quite surprising: almost all of them stated that they could hear suchmusic and a significant percentage of them stated they do like some aspects of that music.The rest of this paper is organized as follows: Section 2 describes the composition process, i.e.the specification of the composition, the semantics of these specifications, and the algorithm used forproducing the sound. Section 3 describes the system
ProbMusic that realizes the proposed method.Section 4 reports the results of an evaluation with users. Finally Section 5 concludes the paper.1
The Composition Process
The process consists of two steps. In the first one, the composer provides a small specification consistingof the desired notes/octaves/instruments (this is analyzed in § mscore . Specifically the algorithm produces three mscores, say mscore , mscore and mscore . These three scores are not identical, because each onewas produced by the process described before, therefore it can be different due to the random selection,which is based on a generator of random numbers.After having produced these three mscores, three threads are produced, by exploiting the multi-threading capabilities of the adopted programming language (in our case we use the Java [2] program-ming language). Each thread is responsible for playing one mscore , however the three threads do notstart at the same time: the second threads starts 3 seconds after the beginning of the first thread, whilethe third thread starts 3 seconds after the beginning of the second. It follows that after around 6 seconds,the produced sound is the result of mixing the sounds of three parallel MIDI channels. It is also worthnoting that the threads are not enforced to be synchronized. This means that the hosting computersystem (virtual machine, operating system, load of the machine at that time) affects the priorities of thethreads and consequently the sound that will be reproduced at each point in time.It follows that the produced sound has three aspects of randomness or non-determinism :a) the random selection of elements from what the composer has specified,b) each of the three mscores is different because they are based on different sequences of random numbers,andc) the priority (and schedule of execution) of the threads on the machine of user is not deterministic.As a consequence, the same composition specification sounds differently each time it is requested. An example of a specification is given in Figure 1. { {"Relaxing, Oct 24, 2013"},{"A","C","E","G"},{"3q","2h","5w","h","4h"},{"Oboe","ELECTRIC_JAZZ_GUITAR","Atmosphere","Choir","Choir_AAHS"},}
Figure 1: Example of the specification of a musical pieceThe first row is the name of the composition and the date of its composition. The second row is a bag of notes , here [A, C, E, G]. The algorithm will pick randomly notes from this bag. We call it bag,instead of set, because duplicates are allowed meaning that if the composer provides a row of the form[A C C], the algorithm with 1/3 probability will be picking the note A and with probability 2/3 the noteC. The third row is a bag of words consisting of one or two letters. The first letter indicates octave ,while the second indicates duration . As regards duration, the possible values (and their meaning) follow: • w: whole duration • h: half duration • q: quarter duration • i: eighth durationThe digits denote octaves and range from 1 to 10.The fourth row is a bag of instrument names , the instruments that the composer prefers for thiscomposition. http://en.wikipedia.org/wiki/Thread (computing) http://en.wikipedia.org/wiki/Java (programming language)
2e should mention that all rows are bags (not sets) meaning that the composer can specify the desiredprobabilities (of notes, duration-octave pairs, instruments) through duplicating accordingly the desiredvalues.
The algorithm picks elements from the bags and forms what we call words . A word contains a randomlypicked note, and a randomly picked duration-octave element. As regards instruments, the algorithmafter the production of a word changes the instrument (by picking randomly an instrument from theprovided bag) with probability 40% (i.e. with 60% probability the instrument does not change).Figure 2 shows the console output of the algorithm. In this example, we have requested music length equal to 33. This means that each of the three threads, will derive an mstring consisting of 33 words.Since we create three threads, the listener will hear 99 (=3 * 33) words. The console output also showsthe times when each of the three threads starts.
Thread No0 has started on 2013/10/28 00:43:12T[Allegro] I[Choir] A3q A2h I[Oboe] Eh A5w I[Atmosphere] C4h I[Choir_AAHS]E2h Ah Eh I[Choir_AAHS] E4h Ah I[ELECTRIC_JAZZ_GUITAR] A4h I[Atmosphere]E4h Ch A3q G2h Ch I[Choir] G3q C4h C4h G5w I[ELECTRIC_JAZZ_GUITAR] E4h E5wI[Choir_AAHS] E5w E5w E5w G3q C3q E5w G5w I[Atmosphere] Eh G3q A3q AhThread No1 has started on 2013/10/28 00:43:15T[Allegro] I[Oboe] C3q Ah I[Oboe] G5w I[Oboe] A5w I[Atmosphere] G2h G5wEh A4h I[Choir] G4h I[ELECTRIC_JAZZ_GUITAR] C5w E4h I[ELECTRIC_JAZZ_GUITAR]A4h I[Oboe] C5w A5w C5w G4h I[Choir_AAHS] A4h I[Oboe] G5w C5w C3q Gh C4hEh I[Atmosphere] G3q I[Choir_AAHS] A2h Ch Ch G5w I[ELECTRIC_JAZZ_GUITAR]Ah I[Oboe] C5w E5w E5w C3qThread No2 has started on 2013/10/28 00:43:18T[Allegro] I[Oboe] Gh E4h I[Atmosphere] E5w I[ELECTRIC_JAZZ_GUITAR] A5wI[Choir] G5w A3q E4h I[Choir] C5w I[Atmosphere] A5w I[Choir] ChI[Choir] E4h I[Choir] G5w E3q A4h I[Atmosphere] C4h A3q G2h A2h I[Choir_AAHS]A2h Eh G2h C3q E5w I[ELECTRIC_JAZZ_GUITAR] A4h Ah E5w C4h E5wI[ELECTRIC_JAZZ_GUITAR] Gh A2h A4h G3q I[Atmosphere] C5w
Figure 2: Example of the console outputNote that the configuration and the algorithm that uses it, is generic in the sense that it can accom-modate various options. Specifically, instead of single notes one can have sequences of notes, e.g. { ”AB”,”A C”,”E”,”G” } . The composer’s role is to produce a specification like that of Figure 1. For deriving the specification ofthe pieces in [7], the author has followed a straightforward trial-and-error methodology. This requiresselecting a few notes, some octave-duration pairs, some instruments, and then test by hearing the result.In average each composition (at least those in [7]) required a trial-and-error process that lasted about20 minutes.
The number of different sounds that can be produced by such a small specifications, like that of Figure1, is very big. Let N denote the set of distinct notes of a specification (2nd row of a specification), OD denote the set of distinct octave-duration pairs (3rd row), and I the set of distinct instruments (4throw). It follows that the set of different words W that can be generated are | N | ∗ | OD | ∗ | I | in size. Forthe specification of Figure 1, we have | N | = 4, | OD | = 5, | I | = 5, so we have | W | = 100 (= 4 * 5 * 5)different words (i.e. | W | = | N | ∗ | OD | ∗ | I | ). 3he size (as number of words) of each mscore is provided by the user. A default value (that yieldsmusic lasting for about 2 minutes and some seconds) is 120. Let use M S to denote the number of wordsin a mscore. Since each word is picked randomly, the number of different mscores of size
M S is | W | MS .In our example it is 100 . Since the music is produced by three mscores which are played concurrently,the number of all different triples of mscores is 100 × × = 100 . Obviously, this numberis extremely big (note that the number of atoms in the entire observable universe is estimated to bearound 10 ). Overall, every time a user requests to hear the piece of Figure 1, he gets back one of the100 possible serializations. Let describe the “coordinates” of the described method of music production in the landscape of algo-rithmic music. • As regards the outcome, this method produces polyphonic music, due to multi-threading. • It is not music composed by the computer, since the composition specification is given by theuser (in future we would like to investigate deriving the composition specification without humanintervention). • As regards the compositional process, the algorithm provides two levels of notational information:the composition specification and the three series as shown in Figure 2 (however the latter is onlyone possible “interpretation” of the composition specification). • As regards the structure of the compositional algorithm per se, it is based on a simple mathematicalmodel (it does not use any knowledge, grammar, evolutionary method, or learning).
ProbMusic ) The described method and algorithm for producing multi-threaded music has been implemented in asystem that is called
ProbMusic . It is written using the Java programming language, while for controllingthe MIDI player it uses the jfugue library [4].
ProbMusic also offers a kind of “playlist player” functionality allowing the user the select the desiredpiece (also offering a “play all” feature). Figure 3 shows a screenshot from its current version offering 11musical pieces. The player provides options for specifying the desired duration of each piece (expressedas number of words), and the number of threads (the default is 3).Each composition can be annotated (currently only by the composer) by one or more keywords.The user can then request the exclusion from the “play all” functionality of the pieces that containnon-preferred (for that moment) keywords by unchecking the corresponding checkbox(es). Finally, andfor obtaining smooth transition in the “play all” functionality, the volume of the sound is graduallydecreased at the end of each musical piece.The entire software is packaged as a single .jar file that can run in any machine that has the JavaRuntime Environment. The size of the package is very small, around 1.1 MB, comparable to the size ofa single mp3 file!A YouTube video the contains around 20 seconds of 9 musical pieces is accessible from [7].
There are numerous works that propose methods for producing music algorithmically dating back toPythagoras (for various links or categorizations see [5, 6, 8, 1]), including attempts for producing musicusing very simple methods, e.g. [3]. However, to the best of our knowledge, most works do not reportany kind of evaluation from users, so it is hard to understand whether the users liked or not the musicproduced by such methods. In our case, we decided to conduct an evaluation with users in order to checkwhether the produced music is acceptable, and if yes to what degree.In this evaluation, 41 persons participated with ages ranging from 19 to 29. They were personseither working at FORTH (computer science researchers, engineers, graduate students) or undergraduate http://en.wikipedia.org/wiki/Observable universe (Dec 11, 2013) ProbMusic students of the Computer Science Department of the University of Crete (specifically students attendingthe 2nd year’s course “CS252 Object-Oriented Programming”, Fall 2013-2014).Each participant was asked to download the software, to hear each of the provided pieces (more thanonce), and then to answer a questionnaire. The software included 6 musical pieces.The questionnaire contained the following questions:
1. Select the two pieces that you liked most.2. Select one of the following choices:(a) I cannot tolerate this music.(b) Yes, I could hear to this music in some occasions (e.g. in public transport means,when I wash dishes, ...).(c) Yes, in general I could hear this music(d) I could say that I like some aspects of this music.(e) I like this music.3. Would you be interested in composing music without having any background in mu-sic?
Figure 4 shows the results regarding the first question where each participant had to select the twomost preferred pieces. We do not observe big differences, since the percentages range from 8% to 23%,i.e. there was not any particular piece that most participants preferred a lot, or disliked a lot.
Select the two pieces that you liked most
Figure 4: Preferences.5igure 5: The results of the questionnaire.Figure 5 shows the results of the second the third questions. As regards the second question, we cansee that: •
41% of the participants said that they could hear such music in specific cases, •
39% that they liked some aspects of that mucic, •
12% that could hear it in general, and •
5% stated that they like it.In total, 98% of the participants declared that they can tolerate this music (only 2% stated that theycannot tolerate it). The percentage of persons that expressed something positive (liked some aspects,could hear it in general, or even like it) is 56% (=5+12+39). It was rather surprising to see such a highpercentage of positive reactions.As regards the last question, 90% of the participants responded that they would like the ability toproduce their own music.
This paper presented a simple method for producing multichannel MIDI music. The method is based onrandom selection, very simple probabilities, and exploits the multi-threading capabilities of programminglanguages. It does not exploit any result of the music theory. It is surprising that the produced musicwas so well accepted by the users. Almost all of them (98%) stated that they could hear such music anda significant percentage of them stated they do like some aspects of that music.Since the composition is based on a very simple input, simple users (i.e. users with no backgroundin music), could in future use this method for composing their own music. In future we would like tostudy which configuration “patterns” lead to aesthetically pleasing music, for attempting to provide anautomatic method for producing even composition specifications. It would also be interesting to comparewith users the produced music with the music produced by other algorithmic methods.The system
ProbMusic is free and is available upon request.
Acknowledgements
Many thanks to Panagiotis Papadakos for informing me about the existence of the jfugue library, andto the students of the course “CS252 Object-Oriented Programming” (Fall 2013-2014) of the ComputerScience Department of the University of Crete, for participating to the evaluation.
References [1] C. Bell. Algorithmic music composition using dynamic markov chains and genetic algorithms.
Journalof Computing Sciences in Colleges , 27(2):99–107, 2011.62] J. Gosling.
The Java language specification . Addison-Wesley, 2000.[3] V.-M. Heikkil¨a. Discovering novel computer music techniques by exploring the space of short computerprograms. arXiv preprint arXiv:1112.1368 , pages 2–5. Citeseer, 1989.[6] A. Moroni, J. Manzolli, F. Von Zuben, and R. Gudwin. Vox populi: An interactive evolutionarysystem for algorithmic music composition.