The purpose of this assignment is to introduce you to loops and playing sound files.
The people, google, siri subdirectories of the project file contains a large number of WAV files of Hello World spoken in different voices and languages, both real (from various individuals) and synthetic (from Google Translate and Apple Siri). Below are some sample executions:
~/Desktop/sound-loops> javac-introcs SayHelloWorld.java ~/Desktop/sound-loops> java-introcs SayHelloWorld people/KevinWayne.wav ~/Desktop/sound-loops> java-introcs SayHelloWorld google/English.wav ~/Desktop/sound-loops> java-introcs SayHelloWorld google/Spanish.wav ~/Desktop/sound-loops> java-introcs SayHelloWorld siri/Kyoko.wav
The key method call is the following, which reads and plays the specified WAV file:
StdAudio.play("filename.wav");
DrumLoop.java
that takes the name of a WAV file as a command-line
argument and repeatedly plays the specified WAV file in an infinite loop.
As an example, the Amen break is one of the most widely sampled tracks in history and has been used in a variety of music genres, including hip hop, jungle, and industrial. This 4-bar drum loop was created by the multiracial soul group The Winstons in their 1969 track "Amen, Brother."
Here are some sample executions:
Extra credit: find and submit other WAV files, that when looped, produces an interesting effect (e.g., famous drum loop, ultrasound, bird chirp).~/Desktop/sound-loops> javac-introcs DrumLoop.java ~/Desktop/sound-loops> java-introcs DrumLoop AmenBreak.wav ~/Desktop/sound-loops> java-introcs DrumLoop Fresh.wav ~/Desktop/sound-loops> java-introcs DrumLoop heartbeat.wav ~/Desktop/sound-loops> java-introcs DrumLoop SOS.wav
In this exercise, you will create a version of this stomp–stomp–clap rhythm. To do so, write an infinite loop to repeatedly play the four WAV files in the given order: stomp.wav, stomp.wav, clap.wav, and silence.wav.
~/Desktop/sound-loops> javac-introcs StompStompClap.java ~/Desktop/sound-loops> java-introcs StompStompClap
Extra credit: find and submit another sequence of WAV file, that when played in succession and repeated, produces an interesting effect (e.g., a percussive beat).
Write a program MajorScale.java
that takes three command-line
arguments (a MIDI note number, a number of octaves, and an instrument name)
and plays a major scale starting at the specified root note,
for the specified number of octaves, both ascending and descending.
To play a note, use the corresponding WAV file in the directory specified
by the instrument name. For example,
piano/60.wav is middle C on a piano
and
opera/69.wav is concert A from an
opera singer.
For example, here are the notes in a 1-octave A major scale, starting at concert A (69), ascending and descending:
And here are the notes in a 2-octave C major scale, starting at middle C (60), ascending and descending:
Note that a k-octave major scale has 7k + 1 notes ascending and 7k + 1 notes descending.
~/Desktop/sound-loops> javac-introcs MajorScale.java ~/Desktop/sound-loops> java-introcs MajorScale 60 1 piano ~/Desktop/sound-loops> java-introcs MajorScale 69 1 piano ~/Desktop/sound-loops> java-introcs MajorScale 60 3 opera
Write programs to produce other musical scales, such as minor, chromatic, natural minor, harmonic major, harmonic minor, melodic minor, and major pentatonic.
If the sum is s, then play minueti-s.wav
.
For example, if you roll an 8 for the measure 3,
then play minuet3-8.wav.
Note that each roll has 11 possible outcomes (2 through 12) but some outcomes
(such as 7) are more likely than others (such as 2 or 12).
If the result is s, then play trioi-s.wav
.
For example, if you roll a 6 for the measure 15,
then play trio15-6.wav.
The mozart subdirectory of the project file contains the 272 WAV files (\(11 \times 16 = 176\) for the minuet measures and \(6 \times 16 = 96\) for the trio measures), using the naming conventions described above.
Context: each time you run the program you will compose a piece of music that has never been heard before! The precomposed measures obey a rigid harmonic structure so that each waltz reflects Mozart's distinct style. Unfortunately, due to this rigid structure, the process never results in anything truly extraordinary.~/Desktop/sound-loops> javac-introcs MusicalDiceGame.java ~/Desktop/sound-loops> java-introcs MusicalDiceGame ~/Desktop/sound-loops> java-introcs MusicalDiceGame
Submission.
Submit
DrumLoop.java
,
StompStompClap.java
,
MajorScale.java
, and
MusicalDiceGame.java
.
You may not call library functions except those in the java.lang
(such as Integer.parseInt()
and Math.sqrt()
).
Do not use Java features that have not yet been introduced in the course.