-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGuitarHeroLite.java
executable file
·35 lines (28 loc) · 1.22 KB
/
GuitarHeroLite.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/** A client that uses the synthesizer package to replicate a plucked guitar string sound */
public class GuitarHeroLite {
private static final double CONCERT_A = 440.0;
private static final double CONCERT_C = CONCERT_A * Math.pow(2, 3.0 / 12.0);
public static void main(String[] args) {
/* create two guitar strings, for concert A and C */
synthesizer.GuitarString stringA = new synthesizer.GuitarString(CONCERT_A);
synthesizer.GuitarString stringC = new synthesizer.GuitarString(CONCERT_C);
while (true) {
/* check if the user has typed a key; if so, process it */
if (StdDraw.hasNextKeyTyped()) {
char key = StdDraw.nextKeyTyped();
if (key == 'a') {
stringA.pluck();
} else if (key == 'c') {
stringC.pluck();
}
}
/* compute the superposition of samples */
double sample = stringA.sample() + stringC.sample();
/* play the sample on standard audio */
StdAudio.play(sample);
/* advance the simulation of each guitar string by one step */
stringA.tic();
stringC.tic();
}
}
}