COS 126

Mozart Waltz Generator
Programming Assignment

Due: Monday

In 1787, Wolfgang Amadeus Mozart created a dice game (Mozart's Musikalisches Würfelspiel). In the game, you compose a two part waltz by pasting together 32 of 272 pre-composed musical elements at random.

The waltz. The waltz consists of two parts - the minuet and the trio. Each is comprised of 16 measures, which are generated at random according to a fixed set of rules, as described below.

Part 1: generating the waltz. For this part, your goal is to generate a random sequence of measures according to the rules described above. Initialize a 13-by-17 array minuet so that minuet[i][j] is the musical element to play in measure j if you roll i. Initialize a 7-by-17 array trio so that trio[i][j] is the musical element to play in measure j+16 if you roll i.

Part 2: playing the waltz. Play each measure in turn using StdAudio.play().

Data files. The 272 measures are stored together in the 37MB file mozart.zip. You can extract them and keep in your current working directory via the command

% jar xf mozart.jar

Playing audio. Program StdAudio.java is a simple library for read, writing, and manipulative .wav files. All of the arrays are assumed to contain amplitude values between -1 and 1.

void     play(String file)     // read in the .wav file from the file and play it
void     play(double[] input)  // play the array of amplitudes
double[] read(String file)     // read in the .wav file and return the array of amplitudes

Composition. Here is a sample waltz generated from this process and the accompanying musical score. There are 11^16 * 6^16 different possible results, some of which are more likely than others. Since this is over 10^23 different possibilities, each time you play the game you are likely to compose a piece of music that has never been heard before! Mozart carefully constructed the measures to obey a rigid harmonic structure, so each waltz reflects Mozart's distinct style. Unfortunately, due to the rigidly, the process never results in anything truly extraordinary.

This assignment was developed by David Costanzo and Kevin Wayne, inspired by the Mozart's Musikalisches Würfelspiel website.
Copyright © 2004.