Guitar Hero Checklist
Introduction
- What are the goals of this assignment?
To learn how to write ring buffer code, how to write Kotlin classes, and to learn about digital audio.
GuitarString
- When generating random values between −0.5 and +0.5, should I include the two endpoints?
The assignment specification does not specify, so you are free to choose whichever convention you find most convenient. You may include the starting point but exclude the ending point of an interval. For example,
s.substring(i,j)
returns the substring of the strings
beginning at indexi
and ending at indexj-1
inclusive. Or you may include both endpoints of an interval. For example,s.substring(i..j)
returns the substring of the strings
beginning at indexi
and ending at indexj
inclusive.
- How do I round a
Float
up to the nearestInt
?
Use
Float.roundToInt()
fromkotlin.math
.
- I believe I have implemented my
GuitarString
class correctly but no sound came out when I tested it.
Make sure the
init
block of yourGuitarString
code contains the lineout.addSignal(this)
This line connects the signals of the
GuitarString
object toMinim
’s lineout.
GuitarHero
- Where do I enter keystrokes in GuitarHeroLite and GuitarHero?
Be sure that the graphic drawing window has focus by clicking in it. Then, type the keystrokes.
- How do I use
keyboard.indexOf(key)
?
If
keyboard
is aString
andkey
is a character, thenkeyboard.indexOf(key)
returns the integer index of the first occurrence of the characterkey
in the stringkeyboard
, or –1 if it does not occur. You can read about it in the Java String documentation page
- Can I hardwire the constants 44,100, 440.0, and 37 in my program?
As usual, we may deduct style points for using an unnamed constant, especially if you use it more than once. We recommend using the name
out.sampleRate()
for 44,100 andCONCERT_A
for 440.0 and the expressionkeyboard.length
for 37. However, you do not need to name all of the constants in the formula 2 (i − 24) / 12.
Optional: Enrichment
Here are some concrete ideas for synthesizing other instruments. Some come from the paper of Karplus and Strong.
- Harp strings: Flipping the sign of the new value before enqueueing it in
tic()
will change the sound from guitar-like to harp-like. You may want to play with the decay factors to improve the realism, and adjust the buffer sizes by a factor of two since the natural resonance frequency is cut in half by thetic()
change. - Drums: Flipping the sign of a new value with probability 0.5 before enqueueing it in
tic()
will produce a drum sound. A decay factor of 1.0 (no decay) will yield a better sound, and you will need to adjust the set of frequencies used. - Guitars play each note on one of six physical strings. To simulate this you can divide your
GuitarString
instances into 6 groups, and when a string is plucked, zero out all other strings in that group. - Pianos come with a damper pedal which can be used to make the strings stationary. You can implement this by, on iterations where a certain key (such as Shift) is held down, changing the decay factor.
- While we have used equal temperament, the ear finds it more pleasing when musical intervals follow the small fractions in the just intonation system. For example, when a musician uses a brass instrument to play a perfect fifth harmonically, the ratio of frequencies is 3/2=1.5 rather than 2 7/12 ∼ 1.498. Write a program where each successive pair of notes has just intonation.
Here is some cool stuff that is closely related.
- ChucK. ChucK as specialized programming language for real-time synthesis, composition, and performance originated by Ge Wang and Perry Cook at Princeton University. Here's the Karplus–Strong algorithm in ChucK.
- Slide flute. Here's a description of a physically modeled slide flute by Perry Cook.