01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package music;
class Music {
private static double pitch = 440;
/** play note at the current pitch for the given duration
in milliseconds (the initial pitch is A = 440 Hz) */
public static void play(int duration) {
System.out.println("play for " + duration/1000.0 + ": " + pitch );
}
/** rest for given duration */
public static void rest(int duration) {
System.out.println("rest for " + duration/1000.0);
}
/** multiply the pitch frequency by the given factor
(a factor less than one will lower the pitch) */
public static void scalePitch(double factor) {
pitch *= factor;
}
/** reset the pitch to note A = 440 Hz */
public static void reset() {
pitch = 440;
}
}
|