Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ITSC 1213 Lab 3 Remember, this is pair programming so you should agree on everything you do, and switch who in control of the keyboard

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
ITSC 1213 Lab 3 Remember, this is pair programming so you should agree on everything you do, and switch who in control of the keyboard and mouse whenever indicated OVERVIEW 1) Part A: Explore Sound Quality 2) Part B: Condense the sound 3) Part C: Expand the sound 4) Part D: Fade in method 5) Part E: Overloading method 6) Bonus 1: Fade out method 7) Bonus 2: Method that skips a parameter-controlled number of samples Part A: Explore Sound Quality Objective: Figure out what happens if you set every second sample to 01 1) Let's find out what happens if we make the value of every other sample in a sound file 0, which equates to silence, or no sound at all. Below is a picture of sound samples as they appear in something like the sound explorer. The size of each bar represents the amount of air pressure (positive or negative) detected in that sample. Below that, the numeric values of the sound samples as they appear in an array when they are stored in the computer's memory Remember that each sound sample is numerically represented by an integer that ranges from -32,768 to 32,767. Actual sound Sound Sample Indices 0 1 23 4 Create a new method called zeroAlternatingSamples() in your Sound.java file that transforms the sound by setting every second sample to 0, as pictured below 2) 3) The method needs to create a new Sound object with the same length as the original Sound object, and copy values of samples from the original sound into the new sound, and then return the new sound at the end. Note that in Sound.java, to refer to the original Sound object, we use this reference variable. For example, to get the length of the current Sound object, we can use this.getLength0. Here is some pseudocode to help you create your new method: REMEMBER- create a new sound object to hold a sound with the same length as the current sound REPEAT-for each sample in the current sound object: CALCULATE whether this sample index is odd or even CHOOSE-if index is even: REMEMBER -copy the value of this sample to the new sample CHOOSE-if index is odd: REMEMER-put 0 in the new sample REMEMBER-return the new sound object Make a prediction. What do you think the altered sound, with every second sample set to 0, is going to sound like? Will you even be able to hear a difference? 4) 5) Create a new project called Lab3SoundTests in order to be able to call and test your new method. 6) To test your method, type the following commands into the main method of your Lab3Sound Tests.java file: // set up path to where sound files are String path-""i I/ replace with your path // specify filename of sound to test with String filename "preamble.wav" ITSC 1213 Lab 3 open the sound Sound sound1-new Sound (path filename) explore the sound sound. explore 0 ; // call the zeroAiternating samples method with a / new Sound object pointer (sound2) to store the new sound that is returned sound sound2-sound1.zeroAlternatingsanples sound, comparing it to the origina sound2.explore ) Note what is happening here. We create a new Sound object from the preamble. way file and open the explorer so that we can look at it and play with it. Then we create a new Sound object pointer called sound2. We call the zeroAlternatingSamples () method on soundl, and it returns a new Sound object that has been altered. Once this line has executed the object pointer sound2 points at the new Sound object that was created in the zeroAlternatingSamples() method. The sound1 object pointer still points at the inally created Sound object. Finally, we explore sound2, so that we can see it and play with it. The picture below illustrates what is happening: sound1 sound1 object Caling the method on sounds ereaes a new sound, whioh thees sound2 sound2 object Run your Lab3SoundTests code and you should see two sound explorer windows like the following (remember that they may appear right on top of each other, so you may have to move the top one to see the bottom one): 7) ample Value The number of samples beseen pises 65 ITSC 1213 Lab 3 Note that in the second window there appear to be fewer sound samples. Play the two sounds to hear the difference. Explain what happens when every other sound sample is zero (what does it sound like and why?) 8) Add JavaDoc comments to the zer es() method. When you are done, regenerate the Javadoc, and look at it in your browser to make sure that it adequately describes the method. 9) Show your Sound java, your Lab3Sound Tests.java and the zeroAl zeroAlternatePreamble.wav file to the Professors or TA to get credit for this part. SWITCH DRIVERS: whoever has been typing should now be navigating Part B: Condense the sound. Objective: To find out what happens when you skip every other sample and cut out the skipped parts. 1) Add a new method to Sound java called skipsamples (). This method is very similar to the previous one, except that instead of setting every second sample to 0 we will just skip that, and end up with a new sound (which your method should return) that is half the length of the original. This is what we are doing: 2) Here is pseudocode for this methood: REMEMBER-create a new sound object to hold a sound half the length of this sound REPEAT-for each sample in the new sound REMEMBER-copy in the appropriate sample value from the original sound REMEMBER-return the new sound object ITSC 1213 Lab 3 This is a little bit tricky, so we suggest drawing index numbers on the image above to help you figure out how to get the right samples. Write out the index numbers and you will find a pattern. 3) Once you think you have the code working, make a prediction. How do you think this is going to sound, in comparison to the other methods and to the original sound? 4) Add a third sound object to your Lab3SoundTests file, and call this new method to get the new sound. Explore your new sound. 5) Play the new sound, and describe it here. Can you explain why it sounds the way it does? 6) Add Javadoc comments for this new method. 7) When you have this working, show it to the Professors or TA to get credit for this part. Part C: Expand the sound Objective: To find out what happens when every single sample is repeated? 1) Add a new method to Sound java called repeatA11Samples (). In this method, we will create a new sound file that is double the length of the original, and we will simply repeat every single sample. This is what we are doing: 2) Here is pseudocode for this method: ITSC 1213 Lab 3 REMEMBER - create a new sound object to hold a sound double the length of this sound REPEAT-for each sample in this sound object: propriate spots in the new sound array REMEMBER return the new sound object Again, this is a litle bit tricky, so we sugest ranex snumbers on the image above to help you figure out how to get the right sample indices. you think you have the code working, make a prediction. How do you think this is going to sound, in comparison to the other methods and to the original sound? 4) Add a fourth sound object to your Lab3SoundTests file, and call this new method to get the new sound. Write this new sound out to the file system with the name repeatAllSamplesPreamble.wav. Then add a line of code to open the sound in an explorer window. 5) Play the new sound, and describe it here. Can you explain why it sounds the way it does? 6) Add Javadoc comments for this new method. 7) When you have this working, show it to the Professors or TA to get credit for this part. SWITCH DRIVERS: whoever has been typing should now be navigating**** Part D: Fade in method Objective: To alter sound samples using a gradient (gradual change). Note: A gradient is a common pattern in math and programming. It is a gradual change, and is often used for animation, transitions, fading in and out, and generally for smoothing out anything that is too jarring or which happens too abruptly. The idea is to multiply some series of source values by increasing (or decreasing) percentages so that there is a smooth transition from one state to another. This is commonly done by following this general pattern: Loop through the range of items where you want the change to happen: get the source item value multiply it by some percentage, where that percentage changes in a systematic way from] something like 1% to 2% to 3%, etc. up to 100% (to fade in) store the changed value - ITSC 1213 Lab 3 1) Sometimes it's nice to have sounds fade in, so that the volume begins at a low level and ramps up to its full level. Let's create a method that will fade a sound in over a specified number of seconds. The pictures below show the preamble.wav sound without a fade-in on the left and with a three second fade-in on the right. You can see the difference in the waveform at the beginning: 2) To do this, create a new method in Sound.java called fadeIn(int seconds), and have it take one integer parameter that represents the number of seconds that it should take for the sound to reach full volume. This method returns the new sound object 3) In order to modify the sound, you need to multiply each sample by a factor that represents an increasing percentage of full volume. Multiplying a sample by 0.0 would set it to no volume (silent), while multiplying a sample by 1.0 would set it to its full, original volume. Multiplying it by 0.5 would set it to half its volume. So, we need to multiply each sample by a different, slightly increasing value from zero to 1, in order to get the fade in effect. 4) We are going to be given the number of seconds that specifies how long the fade in should take. Let's think about this. Imagine that we have to fade in over 5 seconds. How many samples do we need to modify? We need to know the sampling rate of this sound object (the number of samples per second). We can get the sampling rate by calling this.getsamplingRate(). So, the interval of samples that we need to change is seconds this.getSamplingRate . Create a variable calledinterval and set it to the passed in number of seconds, multiplied by the sampling rate. 5) Now, we need to loop through the sound from the first sample up to interval, changing each sample. Write the for loop that will loop through this interval of sounds. In the next step we'll figure out what to do inside the for loop. 6) To figure out what goes in the for loop, we need to figure out how we should change each sample. Let's think through a smaller example. If we wanted to fade in over just ten samples our interval would be 10. In this case, we would want no sound on the first sample (multiply by 0), volume at 1/10th on the second sample (multiply by 0.1 or /interval), volume at 2/10ths on the third sample (multiply by 0.2 or 2/interval), etc., up until the tenth sample, when we would have 9/10ths volume. So, we basically need to multiply each sample i, by i/interval or i/(seconds sampling_rate). Draw this simple example in your sketchbook, showing the original SoundSample array, and the modified SoundSample array, as well as the indices and what each sample is being multiplied by. Use this sketch to identify the pattern between the indices and the volume. ITSC 1213 Lab 3 7) Here is some pseudocode to help you create your new method REMEMBER-find out the sampling rate for this sound (number of samples/second) CALCULATE-find out the number of samples that have to be changed, based on how REMEMBER -store the result of that calculation as "interval" REPEAT-for each sample i from 0 to interval: many seconds you want the fade in to take and the sampling rate REMEMBER -get the original sample value CALCULATE-multiply original value by iVinterval REMEMBER store calculation back in the sample HINT: You have to be careful when working with doubles and integers in the same expression. What happens if you cast a double to an integer too early in the process? The part inside the loop can be written as one line of code, or split into three sub-steps, storing values in temporary variables, depending on your style. (Sometimes it helps to do each step individually to keep the statements simple, then combine them later once you're sure the algorithm is working properly.) Add a fifth sound object to your Lab3SoundTests file, and call this new method with argument 3 to get the new sound. Explore your new sound. Make sure that you hear the sound fade in. Try some other values to make the fade in slower or faster. What happens if you specify a number of seconds that is longer that the sound? Should you allow this? Add a precondition test to make sure that the number of seconds passed in is appropriate. 8) 9) Add JavaDoc comments to the fadeIn () method. When you are done, regenerate the Javadoc, and look at it in your browser to make sure that it adequately describes the method and the precondition for the seconds parameter 10) When you have this working, show it to the Professors or TA to get credit for this part. ***Switch driver and navigator!*** Part E: Overloading method Objective: To practice method overloading. 1) We now will define an overloaded method of zeroAlternatingsamples() we defined in Part A. The new method will take two String arguments and returns nothing. The method header is as follow: public void zeroAlternatingSamples (String path, String name) The method works the same as what we defined in Part A, except that, instead of returning the new Sound object, it writes the new sound to a file specified by the arguments. 2) Create this new method in Sound.java 3) Test this new method in Lab3SoundTests with the following line of code: zeroAlternatingSamples(path, "zeroAlternatingSamples.wav"); 4) Check the mediasources folder to see if this new file has been written. 5) When you have this working, show it to the Professors or TA to get credit for this part. Bonus 1: Write a fade out method that works similarly to the fade in method. It should take a parameter for the number of seconds to stretch out the fading out and over that time, it should slowly decrease the volume down to nothing. Bonus 2: Write a method that creates a new sound by skipping either every second, third or fourth sample, depending on a parameter that is passed in

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

What do you like most about the organization?

Answered: 1 week ago