Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The programming language required for this code is: Java. Can anyone help me write this code asap! Part 2: Writing a program to play sounds
The programming language required for this code is: Java. Can anyone help me write this code asap!
Part 2: Writing a program to play sounds For this part, you will write a program which runs from the main method and plays a sound based on user input. This is different from how A2 and your Loops class worked, but one that will be increasingly common! In those cases, the main method was used solely for testing our other methods. But the main method is commonly used for kicking off a program -- and that is what we will do in this part. To start: 1. Add another class to package a3 named SmoothSounds, also with a main method. 2. Download and add the example sound file asyouwish wave to the a3 package. 3. Download and add the sound helper class, StdAudiojava e, to the a3 package. 4. If you have already done Lab 4, these steps should be familiar to you. Make sure the package statement at the top of the StdAudio file says package a3; Write methods: The final test of your Smooth Sounds functionality should be just running the program itself from main. However, we will build up to that final program incrementally with a few methods -- We strongly recommend that you test these methods in main as you write them, but then comment out the tests or delete them when you are running your final program. We will take a successfully running program as a sufficient test that the methods work. 1. Method name: loadSound Parameter(s): none. Return value: Returns a new doublecl containing the contents of asyouwi sh.wav using the code snippet provided below. Details: We discussed audio in Friday's recitation. A sound file can be represented as a double[] where each element in the array represents the amplitude of the sound wave at a certain point in time. After copying the files into your package that were specified above, you can load a sound file as a double[] using the following code: double() samples = StdAudio.read("asyouwish.wav"); You should test this method from main before proceeding, to make sure that you can properly use StdAudio and the audio file and get a doubled) 2. Method name: playSound Parameter(s): A non-null double[] containing values between -1 and 1 (larger values are squished to be within the range). Return value: void). But sound should be produced as detailed below. Post-Condition: The array parameter is not changed. Details: This method should play the sound corresponding to the input parameter. You can play sound from a double [] named sound by calling StdAudio.play(sound); . So playSoundCloadSound()) with your volume up should produce a sound! 3. Method name: getIntFromUser Parameter(s): none. Return value: An int value that the user of the program (e.g. you, or the grader) typed in. You can assume that the user will input an int. Details: In lecture, we learned about the concept of Java packages, and how we can use code from other packages to expand our code's functionality. For this method, we will use the Scanner class from the java.util package. To start, add the following to the top of your Class, underneath the package declaration, to make Scanner available via its short name: import java.util.Scanner; 4. Method name: repeatedlySmooth Parameter(s): a non-null double[] named array , followed by non-negative int named n Return value: A new double [] which is the result of repeatedly applying Loops. smootharray to array n times. Post-Condition: The array parameter is not changed. Example: repeatedlySmooth(array, 0) should return array. repeatedlySmooth(array, 1) should return Loops. smoothArray(array)). repeatedlySmooth(array, 2) should return Loops. smoothArray(Loops. smoothArray(array)). Part 2: Writing a program to play sounds For this part, you will write a program which runs from the main method and plays a sound based on user input. This is different from how A2 and your Loops class worked, but one that will be increasingly common! In those cases, the main method was used solely for testing our other methods. But the main method is commonly used for kicking off a program -- and that is what we will do in this part. To start: 1. Add another class to package a3 named SmoothSounds, also with a main method. 2. Download and add the example sound file asyouwish wave to the a3 package. 3. Download and add the sound helper class, StdAudiojava e, to the a3 package. 4. If you have already done Lab 4, these steps should be familiar to you. Make sure the package statement at the top of the StdAudio file says package a3; Write methods: The final test of your Smooth Sounds functionality should be just running the program itself from main. However, we will build up to that final program incrementally with a few methods -- We strongly recommend that you test these methods in main as you write them, but then comment out the tests or delete them when you are running your final program. We will take a successfully running program as a sufficient test that the methods work. 1. Method name: loadSound Parameter(s): none. Return value: Returns a new doublecl containing the contents of asyouwi sh.wav using the code snippet provided below. Details: We discussed audio in Friday's recitation. A sound file can be represented as a double[] where each element in the array represents the amplitude of the sound wave at a certain point in time. After copying the files into your package that were specified above, you can load a sound file as a double[] using the following code: double() samples = StdAudio.read("asyouwish.wav"); You should test this method from main before proceeding, to make sure that you can properly use StdAudio and the audio file and get a doubled) 2. Method name: playSound Parameter(s): A non-null double[] containing values between -1 and 1 (larger values are squished to be within the range). Return value: void). But sound should be produced as detailed below. Post-Condition: The array parameter is not changed. Details: This method should play the sound corresponding to the input parameter. You can play sound from a double [] named sound by calling StdAudio.play(sound); . So playSoundCloadSound()) with your volume up should produce a sound! 3. Method name: getIntFromUser Parameter(s): none. Return value: An int value that the user of the program (e.g. you, or the grader) typed in. You can assume that the user will input an int. Details: In lecture, we learned about the concept of Java packages, and how we can use code from other packages to expand our code's functionality. For this method, we will use the Scanner class from the java.util package. To start, add the following to the top of your Class, underneath the package declaration, to make Scanner available via its short name: import java.util.Scanner; 4. Method name: repeatedlySmooth Parameter(s): a non-null double[] named array , followed by non-negative int named n Return value: A new double [] which is the result of repeatedly applying Loops. smootharray to array n times. Post-Condition: The array parameter is not changed. Example: repeatedlySmooth(array, 0) should return array. repeatedlySmooth(array, 1) should return Loops. smoothArray(array)). repeatedlySmooth(array, 2) should return Loops. smoothArray(Loops. smoothArray(array))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