CS 111 - Program Design I

Lab 12

This lab will have you combine two sound files to add a "background" soundtrack to a foreground sound. The following files of the Gettysburg Address and the Preamble of the U.S. Constitution are great foreground sound files.

The final sound should be the length of the smaller of the two original sounds.

We will also want to make the background sound quieter than it originally is, so we wish to make its volume a third of its original value. Here are some good files for the background sound:

To combine two sound files, you simply just add the sample values together.

The only problem occurs if the resulting value goes above 32,767 or below -32,768. A simple solution is to use an if statement to check for this. Two simple if statements can check for this and correct the problem if it occurs. To correct this, just set the value to either 32,767 if the value was greater than 32,767 or set the value to -32768. if the value was less than -32,768.

Lab Assignment 12

Due: Tuesday 11/19/2013 by 11:59 pm

Create a Java program that will do the following:

  • Be writen using good programming style which includes:
    • Good variable names
    • In-line commenting
    • Proper indentation of program statements
    • Use of blank lines to separate blocks of code.
    • Header block commenting for the program and each method written

      Your header block comment for the program must include the following:

      • Your Name,
      • Net-ID,
      • Course Name,
      • Assignment Name and
      • Day and time of your CS 101 lab section (i.e. Wednesday at 9:00)
      • A short description of the assignment.
Header block comments for each method must include the following:
  • A description of the purpose of the method
  • A listing of the name, type and purpose of every parameter
  • A description of the return value and its type

  • The main() method that will perform the following steps:
    • Prompt the user for the "Foreground" sound file and make a sound object from this file.
    • Prompt the user for the "Background" sound file and make a sound object from this file.
    • Call a method combineSounds()
    • play (or explore) the resulting sound and
    • Prompt the user to save the resulting sound in a file
  • The method combineSounds() that willperform the following steps:
    • Take two sound objects as parameters: the foreground sound and the background sound.
    • Create a new sound that is the same length as the shorter of the two sounds.
    • Add the background sound to the foreground sound, but the volume of the background sound should be one-third of its original volume. To do this, first divide the background sound sample values by 3 before adding the two values together. This resulting sound is to be stored in the new sound.
    • check for and correct any "clipping" that may result from the resulting value being greater than 32,767 or less than -32,768.
    • return the newly created sound.
You are also to submit the Java file electronically via the assignment link for Lab 12 in BLackboard.

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

-- Main.troy - 2013-11-14

Topic revision: r1 - 2013-11-14 - 20:21:41 - Main.troy
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
Helping Women Faculty Advance
Funded by NSF