ITIS1213 Assignment 1: Audio Poetry & MIDI Song

Verified

Added on  2019/09/25

|9
|3588
|296
Practical Assignment
AI Summary
This practical assignment for ITIS1213 focuses on Java programming, specifically using sound objects and arrays, and the MIDIPlayer class. Students create audio poetry methods, including overloaded methods to save sounds to files. They also design a new audio poetry method and compose a MIDI song using sheet music, translating notes into MIDI commands. The assignment emphasizes proper coding style and includes a rubric for grading. Students submit their NetBeans project file and the sheet music used for the MIDI song.
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
The main idea behind this assignment is to work with Sound objects and arrays of Sound objects,
as well as to use the MIDIPlayer class to program a song.
Prep Work
1. Download and unzip the file linked at Assignment 1 Starting Code in Canvas. This file,
A1Files.zip, when unzipped, will produce three files you’ll need:
Assignment1_ITIS1213.java
AudioPoetry.java
CupSong.java
Make sure you remember where you stored the unzipped files.
2. For the first three parts of this assignment, you will be working in the
Assignment1_ITIS1213.java file (which contains the main method) and the
AudioPoetry.java file. (In Part 4, you will need CupSong.java.)
3. Create a new Java project in Netbeans, with your name in the project. The project name
must follow this format: LastnameFirstname_Assignment1_ITIS1213. So, if Professor
Long was doing the assignment, the project would be named:
LongBruce_Assignment1_ITIS1213. Make sure to uncheck the “Create Main Class”
checkbox before creating the project.
4. You’ll get a new project, and when you open the Source Packages folder in the Netbeans
Navigator window, it will show an empty <default package>. Right-click on Source
Packages and select New Java Packages. In the dialog that comes up, create a package
that has the same name as your project.
5. Copy the assignment files (Assignment1_ITIS1213.java, AudioPoem.java, and CupSong.java)
into the package/source file directory on your computer. (If you’re not sure where your
NetBeans projects files are, click the File tab in the upper left window of NetBeans (it
should be next to the Projects tab), right-click on src, then click Properties. The All Files
line shows you the folder on your hard drive where your source files are stored.) Once
you’ve copied those files to your src folder they should automatically appear in your new
package under the Projects tab. Open each of these files and change the package name at
the top of each file to match the package name in your project.
6. Finally, add the MediaCompClasses.jar file to the library for your project. You’re ready to
go!
Part 1 – Create audio poetry methods (25%)
1. Read through the two java files provided to try to understand what they do and how they
work together. Assignment1_ITIS1213.java is the test harness that runs the program
because it has the main method. The beginning of the main method reads in a number of
tmp5bcq8imp.docx Page 1 of 9
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
splice points. These are just the sample numbers within the .wav file that indicate where
individual words start and stop. The two important lines are at the end of the main
method. One creates a new AudioPoem object called myPoem then calls the play()
method on the myPoem object. The real processing happens in the AudioPoem class.
2. To see how this works, copy the thisisatest_splice.rtf file into your mediasources
directory and make sure that you have the thisisatest.wav file in that directory as well.
3. In the main method, look for the line near the beginning that sets the value of the String
path variable. Change it to the path to your mediasources directory.
4. Run the project to see what it does.
a. First you should see a popup window asking you to specify where your main method is.
Select Assignment1_ITIS1213.java and click OK. (That should be the last time you see
that window.)
b. Next, you should see a popup window that asks you to “Please select a sound file …”.
(Look in the upper left of the popup window for the message.) Select and open
thisisatest.wav.
c. Next, you should see a popup window that asks “Now select the file that contains the
splice points...”. Select and open thisisatest_splice.rtf.
d. Once you have selected the proper input files you should hear four words slightly
separated: this … is … a … test. (That’s one of the authors of the MC textbook speaking
by the way.)
5. You will notice that running the test harness just plays the sound, using the AudioPoem’s
play() method, which is completed for you. The AudioPoem class takes the sound object
and the splice points and creates an array of sound objects each element of which is one of
the separate words from the sound. The rest of the methods in AudioPoem (look at lines
36 thru 118) are stub methods, which means they exist, but they are empty – there is no
code inside of them; they’re just placeholders. These methods are meant to play the
individual words in different ways. Your job in Part 1 of the Assignment is to complete
these stub methods and test each of them by adding appropriate code to your main
method. Look at the Javadoc comments above each stub to understand what each method
should do. Look at the code in the play() method to see how to play the four individual
sounds one after the other. In your main method pause one second between invoking each
of the AudioPoem methods. While you’re testing your methods, you can comment out all
the methods that work so you’re only listening to one at a time. When you submit this
Assignment remove those comments so you make sure you hear all the methods tested
when you run the test harness program.
Part 2 – Overload audio poetry methods (25%)
Do this part of the assignment once Part 1 is complete.
tmp5bcq8imp.docx Page 2 of 9
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
1. Your job is to create overloaded methods in the AudioPoem class. These new methods save
the set of sounds created by the method to a file in a directory you specify. Each of the
overloaded methods takes two additional String parameters. These parameters represent
the filename and the path to where you are storing files. So, for example, the overloaded
method playReverseOrder(int pause, String filename, String path)
should play the words in the audio poem in reverse order, but it should also save the new
sound that plays the same thing. If you do this correctly, anyone should be able to play the
sound file you create and hear the same sounds you did when your method ran. To do this,
you will need to create a new sound object to hold the sounds as well as the gaps between
the words, copy the sounds (and the gfaps) into it as they are played, and then write that
new Sound object out to a file before the method returns.
2. When this part of the assignment is done, you should have the following methods working
properly (the ones in bold are the new ones that save the sound):
play()
play(int pause)
play(int pause, String filename, String path)
playDoublets(int numDoublets)
playDoublets(int numDoublets, String filename, String path)
playRandomOrder(int totalWords, int pause)
playRandomOrder(int totalWords, int pause, String filename, String path)
playRandomUnique(int pause)
playRandomUnique(int pause, String filename, String path)
playReverseOrder(int pause)
playReverseOrder(int pause, String filename, String path)
playTriplets(int numTriplets)
playTriplets(int numTriplets, String filename, String path)
3. Note that some of these new methods will be a bit tricky, because you won’t know how big
your new sound should be. How many samples do you need for example, for the
playRandomOrder sound? It’s going to play a bunch of words, but you don’t know ahead of
time, which words, and each word sound contains a different number of samples. Hint:
play it safe, and find out which word in the array is longest, and how many samples are in
that word. Also, how many samples do you need for a 100 millisecond pause? You’ll need
to query the sampling rate to handle this.
Hint: You may want to create some private helper methods so that you don’t have to retype
a lot of code. For example you may want a calculateNumberOfSilentSamples
method and a writeSoundToFile method. Create all the helper methods you like.
4. Add appropriate JavaDoc documentation for these methods.
5. Test these new overloaded methods by calling them from your test harness file and
specifying filenames. You should also listen to the.wav files your code created to make sure
they sound exactly the same as when the method is called from your test harness program.
(Just play them with whatever your default audio player is on your computer.)
tmp5bcq8imp.docx Page 3 of 9
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
Part 3 – Create your own audio poetry method (10%)
In this part of the assignment your job is to create a brand new method that does something
interesting with the word array in the AudioPoem class. You have complete freedom in
creating this method – it can do anything you want, including calling methods in Sound.java to
change each sound word. You must document your method well, and add a comment at the
top of your AudioPoem.java file that identifies the method created for this part of the
assignment.
Part 4 – Create a MIDI song (25%)
In this part of the assignment, you need to a new Java class, that will play a song of your
choosing using the MIDIPlayer. The examples towards the end of Chapter 10 in your textbook
will be very helpful. You’ll use the CupSong.java file you downloaded at the beginning of this
Assignment. This part of the assignment should take some time, but should be pretty
straightforward. First, uncomment the code at the bottom of your main method in your test
harness program. That code creates a CupSong and plays it. Try it out! Then examine the
CupSong.java file to see what it does. You’ll be making one just like this for this part of the
assignment. Here are your instructions (I’d read all the way through them first):
1. Find piano sheet music for a simplified version of a song you like (lots of sites on the
Interwebs have this stuff freely available), I found a single-page, simplified version of “the
cup song” at https://www.pinterest.com/jaredpiano/simplified-sheet-music-new-piano-
brag-songs/. Of course, you can also search for your own music at other sites.
2. Use the guide below to identify the notes that are in your song:
Figure 1. Names of Notes and Their Symbols
3. If you don’t already have a basic knowledge of how to read sheet music, you’ll need this
guide to know how long each note should last:
tmp5bcq8imp.docx Page 4 of 9
First note of
the Cup Song
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
You can figure out how long each note should be played by assigning a number of
milliseconds to a whole note then assigning appropriately proportional values to all the
other types of notes. For example, if a whole note is 1000 milliseconds, then a half note
should be 500 milliseconds, and so on. A rest lasts as long as the corresponding note but
it’s silence instead of a sound.
4. The easiest way to do this is to create a table in a spreadsheet that contains, in order, all the
notes, their duration and how that translates into MIDIPlayer commands. (Below this list
of instructions, you’ll see the Cup Song sheet music, and a part of the corresponding Excel
table that you can use to figure out the commands to give to the MIDIPlayer object.)
5. Create a new Java class in the same project and package as the CupSong.java class (right-
click on the Assignment 1 package and then select New Java Class…). Call the class
MySong. Then using the CupSong class as an example, inside your MySong class create a
MySong constructor, a changeInstrument() method, and a play() method to play
your song.
6. Your play() method may call other methods (for example if there is a repeating chorus, it
makes sense to create a method for that and call that method, instead of retyping the
chorus commands).
7. Change the lines in your YourName_Assignment1_ITIS1212.java main method that play the
Cup Song so they play your song instead. Call your play() method at least 3 times from
inside this main method, changing to various different MIDI instruments. You can find
MIDI instrument numbers here.
8. Bonus: make use of the overloaded playNote method that allows you to specify intensity as
well as note and duration and change the intensity of each note so that some notes are
emphasized by being played louder.
Important Notes about Part 4:
1. Make sure you pick sheet music for a simple song, or a simplified version of a song, aimed
at novice piano players. One page of sheet music is sufficient.
2. I would strongly advise you to pick a song that has no sharps or flats unless you
can already read music. If you don’t know what I’m talking about pick music
where you see this:
3. You don’t need to play notes and chords. In the sheet music for the cups song, there are
notes in treble clef (the staff of music at the top) and chords (multiple notes played
together) in the bass clef (the staff of music at the bottom). I am ignoring everything on the
bass clef and only translating the notes on the treble clef.
4. If you don’t have a basic knowledge of reading music, you are going to learn a little bit
about it by doing this part of the assignment, and that’s a good thing. However, if you find
you are having trouble converting your sheet music into MIDI notes, PLEASE ask for help!
tmp5bcq8imp.docx Page 5 of 9
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
We don’t want anyone losing grade points just because they don’t have a music
background.
5. Don’t choose a song that has chords, that is, more than one note played at the same time.
This screenshot above shows the first part of Beyonce’s song “Pretty Hurts”. Note that
there are multiple notes being played at the same time. These are chords and our
MIDIPlayer class does not handle chords.
6. Here’s the Cup Song sheet music:
tmp5bcq8imp.docx Page 6 of 9
Chord!
The first 4
measures are
this line.
Measure 1 2 3 4
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
The first four measures above are converted into notes, durations and the appropriate
MIDIPlayer calls in the table below:
Figure 2. Excel Spreadsheet for MIDI Player
I used a lookup table in my Excel spreadsheet to automatically fill in the MIDI code and
Duration columns, and the concatenation function to create the Java Command column. If
you want to know how to do this I’ll be happy to show you in class. Once you have the Java
commands you can just copy that column and paste it into NetBeans.
The table below shows the conversion from notes into MIDI codes. Here’s how to convert
sheet music to MIDI codes:
a) Go to the sheet music for the Cup Song on page 6. Look at the first note and find the
corresponding note in Figure 1 above on page 4. It’s a C.
b) But which C is it? There are 7 notes A, B, C, D, E, F, and G and they repeat over and
over. The reference point is what’s called middle C. You can see it in Figure 1.
c) In Figure 3 below, find middle C. The C you want to play as the first note of the Cup
Song is the 7th note to the right of middle C in Figure 1. That means that the pitch of
the C we want to play is higher than middle C so in Figure 2 we go up (that is,
towards the top of Figure 3) seven notes from middle C. That takes us to the note
labeled C5.
d) C5 is a white key on the piano so we look in the far right column of Figure 3 and find
MIDI code 72. The top line of Figure 2 shows the MIDI code is 72 so that top line
will play the C we want to play as the first note of the Cup Song.
e) How long the note lasts (its duration) is determined by what type of note it is:
whole note, half note, etc. The “time signature” tells us what we need to know to
figure out how long each note should last. In the Cup Song the time signature is:
tmp5bcq8imp.docx Page 7 of 9
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
f) The lower 4 says a quarter note gets one beat. The upper 4 says there are 4 such
beats in a measure. There are four quarters in a whole so one whole note would
take up the entire measure. You’d count to four and hear the note that whole time.
If you played four different quarter notes in one measure you’d hear a different note
each beat. If you played eight eighth notes in one measure each eighth note would
take up half a beat. And so on. The first measure of the Cup Song has 8 notes in it so
you know each note is an eighth note.
g) We picked 2000 milliseconds (i.e., 2 seconds) as the duration of a whole note. So a
half note takes 1000 milliseconds, a quarter note takes 500 milliseconds, and an
eighth note takes 250 milliseconds. Half, quarter, and eighth rests take the same
amounts as time as the corresponding notes.
h) We now know everything we need to make the MIDI player play a note: it’s MIDI
code and the length of time to hold that note. Your job is to translate the sheet
music for the song you picked into note names, and assign the proper MIDI values
and durations to each.
Figure 3. MIDI Values for Piano Keys
tmp5bcq8imp.docx Page 8 of 9
White keys
Black keys
First note of
the Cup Song
Document Page
Assignment 1 – Fridge Magnet Poetry & Song!
Coding Style – (15%)
This grade is awarded for proper coding style. This includes:
Appropriate method, variable, field, object and class names
Proper indentation
Good JavaDoc and within method commenting (explains what code is doing)
Well-organized, elegant solutions for each part
Files to submit:
You have two files to submit:
Your project file submitted as a NetBeans zip file. This is not the same as a regular zip file.
You create this file from NetBeans. First select the project you want to export, then go to
File Export Project To ZIP…. In the window that pops up don’t change the Root
Project line. On the Build ZIP: line you can browse to the directory where you want your
zip file to be stored but you’ll have to enter the filename yourself. Be sure to use the
complete name of your project as the file name. If you do not submit a NetBeans zip file
you will receive a zero on this Assignment.
A digital version of the page of sheet music you used for Part 4 (ensuring the title of the
song is at the top). By digital version I mean do not submit an actual piece of paper!
Grading Rubric (see the rubric on Canvas)
tmp5bcq8imp.docx Page 9 of 9
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]