Question
Modify PlayThatTune to take additional command-line arguments that control the volume (multiply each sample value by the volume) and the tempo (multiply each note's duration
Modify PlayThatTune to take additional command-line arguments that control the volume (multiply each sample value by the volume) and the tempo (multiply each note's duration by the tempo).
public class PlayThatTune {
public static void main(String[] args) {
// repeat as long as there are more integers to read in while (!StdIn.isEmpty()) {
// read in the pitch, where 0 = Concert A (A4) int pitch = StdIn.readInt();
// read in duration in seconds double duration = StdIn.readDouble();
// build sine wave with desired frequency 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); }
// play it using standard audio StdAudio.play(a); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started