Class Sound

java.lang.Object
  extended by SimpleSound
      extended by Sound

public class Sound
extends SimpleSound

Class that represents a sound. This class is used by the students to extend the capabilities of SimpleSound. Sounds are immutable (they don't change). Each method that modifies a sound returns a copy of the original sound. Copyright Georgia Institute of Technology 2004

Author:
Barbara Ericson ericson@cc.gatech.edu

Constructor Summary
Sound(int numSeconds)
          Constructor that takes the number of seconds that this sound will have
Sound(Sound copySound)
          Constructor that takes a sound to copy
Sound(java.lang.String fileName)
          Constructor that takes a file name
 
Method Summary
 void add(Sound source)
          Method to add the passed sound to this sound
static Sound blendSounds()
          Method to overlap or blend two sounds.
 void changeFreq(double factor)
          Method to change the frequency of a sound by the passed factor
 void changeFreq1(double factor)
          Method to change the frequency of a sound by the passed factor
 void changeVolume(double factor)
          Method to change the volume (amplitude) of the sound by multiplying the current values in the sound by the passed factor.
 Sound clip(int start, int end)
          Method to create a new sound by copying just part of the current sound to a new sound
static Sound createSineWave(int freq, int maxAmplitude)
          Method to create a one second sine wave sound with the given frequency and maximum amplitude
static Sound createSquareWave(int freq, int maxAmplitude)
          Method to generate a 1 second sound with square waves with the passed frequency and maximum amplitude.
static Sound createTriangleWave(int freq, int maxAmplitude)
          Method to create a one second triangle wave sound with the given frequency and maximum amplitude
 void decreaseVolume()
          Method to halve the volume (amplitude) of the sound.
 void decreaseVolume2()
          Method to halve the volume (amplitude) of the sound.
 void doNothing()
          Method to go through each sound sample and set the sample value to the original value.
 void doubleFreq()
          Method to double the frequency of a sound by taking every second sample.
 void echo(int delay)
          Method to add an echo to a sound
 void echo(int delay, int numEchos)
          Method to create multiple echos
 void forceToExtremes()
          Method to set all the sample values to the maximum positive value it they were positive (including 0) and the minimum negative value if they were negative.
 void halveFreq()
          Method to halve the frequency of a sound by taking each sample twice.
 void increaseHalfDecreaseHalf()
          Method to increase the first half of the sound (double it) and then decrease the second half (half it).
 void increaseVolume()
          Method to double the volume (amplitude) of the sound
 void mirrorFrontToBack()
          Method to mirror a sound front to back
 void normalize()
          Method to normalize (make as loud as possible) a sound.
static Sound pickAndPlay()
          Method to pick a sound file, create the sound object, play the sound object, and return the sound object
 void play5Freq()
          Method to play a sound 5 times and each time increase the frequency.
static Sound playNamed(java.lang.String fileName)
          Method to create a sound object from the given file name and play the sound.
static Sound playSpecificSound()
          Method to play a specific sound.
 void reverse()
          Method to reverse the current sound.
static Sound reverse(java.lang.String file)
          Method to reverse the sound with the passed file name
static Sound splice()
          Method to splice two sounds together with some silence between them
 void splice(Sound source, int sourceStart, int sourceStop, int targetStart)
          Method to copy part of the passed sound into this sound at the given start index
static Sound splicePreamble()
          Method to splice "United" into "We the people of the United States" by adding it after the "the"
static Sound spliceSimpler()
          Method to splice "United" into "We the people of the United States" by adding it after the "the"
 java.lang.String toString()
          Method to return the string representation of this sound
 
Methods inherited from class SimpleSound
asArray, blockingPlay, blockingPlayAtRateDur, blockingPlayAtRateInRange, convert, explore, getAudioFileFormat, getBuffer, getChannels, getDEBUG, getFileName, getFrame, getLeftSample, getLength, getLengthInBytes, getLengthInFrames, getNumSamples, getPlaybacks, getRightSample, getSample, getSamples, getSampleValue, getSampleValueAt, getSamplingRate, getSoundExplorer, isStereo, loadFromFile, makeAIS, play, playAtRateDur, playAtRateInRange, playAtRateInRange, playNote, printError, printError, removePlayback, setAudioFileFormat, setBuffer, setFrame, setLeftSample, setRightSample, setSampleValue, setSampleValueAt, setSoundExplorer, write, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sound

public Sound(java.lang.String fileName)
Constructor that takes a file name

Parameters:
fileName - the name of the file to read the sound from

Sound

public Sound(int numSeconds)
Constructor that takes the number of seconds that this sound will have

Parameters:
numSeconds - the number of seconds desired

Sound

public Sound(Sound copySound)
Constructor that takes a sound to copy

Method Detail

toString

public java.lang.String toString()
Method to return the string representation of this sound

Overrides:
toString in class SimpleSound
Returns:
a string with information about this sound

pickAndPlay

public static Sound pickAndPlay()
Method to pick a sound file, create the sound object, play the sound object, and return the sound object

Returns:
the created sound object

playSpecificSound

public static Sound playSpecificSound()
Method to play a specific sound. The sound to play is specified in the method. To change the sound that this method plays change the file name in the method and recompile

Returns:
the created sound object

playNamed

public static Sound playNamed(java.lang.String fileName)
Method to create a sound object from the given file name and play the sound. It also returns the created sound object

Returns:
the created sound object

doNothing

public void doNothing()
Method to go through each sound sample and set the sample value to the original value. This is simply a template for processing sounds using an array of SoundSample objects


increaseVolume

public void increaseVolume()
Method to double the volume (amplitude) of the sound


decreaseVolume

public void decreaseVolume()
Method to halve the volume (amplitude) of the sound.


decreaseVolume2

public void decreaseVolume2()
Method to halve the volume (amplitude) of the sound.


changeVolume

public void changeVolume(double factor)
Method to change the volume (amplitude) of the sound by multiplying the current values in the sound by the passed factor.

Parameters:
factor - the factor to multiply by

normalize

public void normalize()
Method to normalize (make as loud as possible) a sound.


forceToExtremes

public void forceToExtremes()
Method to set all the sample values to the maximum positive value it they were positive (including 0) and the minimum negative value if they were negative.


increaseHalfDecreaseHalf

public void increaseHalfDecreaseHalf()
Method to increase the first half of the sound (double it) and then decrease the second half (half it).


clip

public Sound clip(int start,
                  int end)
Method to create a new sound by copying just part of the current sound to a new sound

Parameters:
start - the index to start the copy at (inclusive)
end - the index to stop the copy at (inclusive)
Returns:
a new sound with just the samples from start to end in it

splice

public static Sound splice()
Method to splice two sounds together with some silence between them

Returns:
the resulting sound

splicePreamble

public static Sound splicePreamble()
Method to splice "United" into "We the people of the United States" by adding it after the "the"

Returns:
the changed sound

spliceSimpler

public static Sound spliceSimpler()
Method to splice "United" into "We the people of the United States" by adding it after the "the"

Returns:
the changed sound

splice

public void splice(Sound source,
                   int sourceStart,
                   int sourceStop,
                   int targetStart)
Method to copy part of the passed sound into this sound at the given start index

Parameters:
source - the source sound to copy from
sourceStart - the starting index to copy from in the source
sourceStop - the ending index (the copy won't include this)
targetStart - the index to start copying into

reverse

public static Sound reverse(java.lang.String file)
Method to reverse the sound with the passed file name

Parameters:
file - the name of the file
Returns:
the sound reversed

reverse

public void reverse()
Method to reverse the current sound.


mirrorFrontToBack

public void mirrorFrontToBack()
Method to mirror a sound front to back


blendSounds

public static Sound blendSounds()
Method to overlap or blend two sounds. Start by copying the first 20,000 samples from sound1 into the target sound then copy the sum of half of sound1 and half of sound2 for the next 20,000 samples and end with the next 20,000 samples from sound2.


echo

public void echo(int delay)
Method to add an echo to a sound

Parameters:
delay - the number of samples before the echo starts

echo

public void echo(int delay,
                 int numEchos)
Method to create multiple echos

Parameters:
delay - the number of samples before the echo starts
numEchos - the number of echos desired

doubleFreq

public void doubleFreq()
Method to double the frequency of a sound by taking every second sample. The result will be a higher sound.


halveFreq

public void halveFreq()
Method to halve the frequency of a sound by taking each sample twice. The result will be a lower sound.


changeFreq1

public void changeFreq1(double factor)
Method to change the frequency of a sound by the passed factor

Parameters:
factor - the amount to increment the source index by. A number greater than 1 will increase the frequency and make the sound higher while a number less than one will decrease the frequency and make the sound lower.

changeFreq

public void changeFreq(double factor)
Method to change the frequency of a sound by the passed factor

Parameters:
factor - the amount to increment the source index by. A number greater than 1 will increase the frequency and make the sound higher while a number less than one will decrease the frequency and make the sound lower.

play5Freq

public void play5Freq()
Method to play a sound 5 times and each time increase the frequency. It doesn't change the original sound.


createSineWave

public static Sound createSineWave(int freq,
                                   int maxAmplitude)
Method to create a one second sine wave sound with the given frequency and maximum amplitude

Parameters:
freq - the desired frequency
maxAmplitude - the maximum amplitude
Returns:
the new sound

add

public void add(Sound source)
Method to add the passed sound to this sound

Parameters:
source - the sound to combine with this one

createSquareWave

public static Sound createSquareWave(int freq,
                                     int maxAmplitude)
Method to generate a 1 second sound with square waves with the passed frequency and maximum amplitude.

Parameters:
freq - the desired frequency
maxAmplitude - the maximum amplitude
Returns:
the created sound

createTriangleWave

public static Sound createTriangleWave(int freq,
                                       int maxAmplitude)
Method to create a one second triangle wave sound with the given frequency and maximum amplitude

Parameters:
freq - the desired frequency
maxAmplitude - the maximum amplitude
Returns:
the new sound