Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago

Question

4. Explain the characteristics of successful mentoring programs.

Answered: 1 week ago