CS 111 - Program Design I, Fall 2015

Lab 10

This lab will have you prompt the user for an amount to change the volume of a sound file. You are to prompt the user for a percent value using the getIntNumber() method of the SimpleInput class. You are to then multiply every sample in the sound file by this percent value. The basic calculation is to first multiply the amplitude amount at each Sound Sample by the value entered by the user, then divide the result by 100. Note that if the user enters in a value between 0 and 99, the volume of the sound file will be decreased. If the user enters a value greater than 100, the volume will be increased. If the user enters 100, the volume will be unchanged. Thus:

  • To double the value of the sound, the user should enter 200 (which we interpret as a 200% modification).
  • To triple the value of the sound, the user should enter 300 (which we interpret as a 300% modification).
  • To half the value of the sound, the user should enter 50 (which we interpret as a 50% modification).
  • To make the volume a quarter of its original volume, the user should enter 25 (which we interpret as a 25% modification).
Note you will want to check out the sample Lect1105c.java. This code doubles the volume in a sound file by multipling the value at every sample by 2.

For this assignment:

  • If we want to double the volume of a sound, we multiply every sample value by 2
  • If we wanted to triple the volume of a sound, we multiply every sample value by 3
  • If we want to cut the volume of a sound in half, we multiple every sample value by 0.5
  • To make the volume a quarter of what it originally was, we multiply every sample value y 0.25
Also, remember range of valid sample values is from -32,768 to +32,767. For this lab, you must also check to see if the sample value falls out of this range after the multiplication is done. If the sample value becomes greater than +32,767, set the value to +32,767. If the sample value becomes less -32,768, set the value to -32,768. This is simply done by use of two if statements. One of these if statements is as follows:

 if (amplitude > 32767)  
       {  amplitude = 32767;  } 

Here are some sample sound files that can be used for this lab:

The method in the Sound class of getSamples() will allow you to access an array of SoundSamples which will allow access to the sound. The methods in the SoundSample class of are useful for modifying the sample values.

Lab Assignment 10

Due: Wednesday 11/11/2015 by 11:59 pm

Create a Java program that will:

  • Contain a comment indicating
    • your Name,
    • Net-ID,
    • Course Name,
    • Assignment Name and
    • a short description of the assignment

  1. Contain the main() method that will
    • Prompt the user for a sound file and make a sound object from this file.
    • Prompt the user for an integer percent value that will be used to modify the volume of the sound.
    • Call a method modifySound() that will change the volume of the sound. The Sound object and the integer percent value are to be sent to this method as parameters.
    • play (or explore) the resulting sound and prompt the user to save it in a file

  1. Contain a method called modifySound() that will
    • Take two parameters:
      1. The first parameter will be a Sound object.
      2. The second parameter will be an integer value.
    • Modify the volume of the sound using the amount given by the second parameter. The amount is to be considered as a percent value. Thus a value of 100 keeps the volume unchanged. A value greater than 100 increased the volume, whilea value between 0 and 100 lowers the volume.
    • Check for and correct any "clipping" that may result from the resulting value being greater than 32,767 or less than -32,768.

Program Submission

You are also to submit the Java file electronically via the link in the assignment page in Blackboard.

Sample Sound Files

Here are some example sound files you can use with this assignment.

-- Main.troy - 2015-11-05

Edit | Attach | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2015-11-05 - 20:57:56 - Main.troy
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
Helping Women Faculty Advance
Funded by NSF