PlayThatTune.java
public class PlayThatTune
{
public static void main(String[] args)
{
while (!StdIn.isEmpty())
{
int pitch = StdIn.readInt();
double duration = StdIn.readDouble();
double hz = 440 * Math.pow(2, pitch / 12.0);
int N = (int) (StdAudio.SAMPLE_RATE * duration);
double[] a = new double[N+1];
for (int i = 0; i <= N; i++)
{
a[i] = Math.sin(2 * Math.PI * i * hz / StdAudio.SAMPLE_RATE);
}
StdAudio.play(a);
}
}
}
No comments:
Post a Comment