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. 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(String fileName)
          Constructor that takes a file name
 
Method Summary
 void add(Sound source)
          Method to add the passed sound to this sound
 void blendSounds()
          Method to overlap or blend two sounds.
static Sound blendSoundsS()
          Method to overlap or blend two sounds.
 void changeFreq(double factor)
          Method to change the frequency of a sound by the passed factor
 void changeFreq2(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
 void copySineWave(int freq, int maxAmplitude)
          Method to copy a sine wave with the given frequency and maximum amplitude to the current sound
 Picture createPicture()
          Method to turn a sound into a picture
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 createSoundFromTextFile(String fileName)
          Method to create a sound from a text file
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 that just shows how to get each sample value and set it again
 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
 Sound echo(int delay, int numEchoes)
          Method to create multiple echoes of the current sound
 void forceToExtremes()
          Method to set all the sample values to the maximum positive value if 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
static void main(String[] args)
           
 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(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 reverseS(String file)
          Method to reverse the sound with the passed file name
 void splice()
          Method to splice two sounds together with some silence between them into the current sound
 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
 void splicePreamble()
          Method to splice "We the " then "United" then "people of the United States" into the current sound
 void splicePreamble2()
          Method to splice the preamble into the current sound so that it says We the United people of the United States
static Sound splicePreambleS()
          Method to splice "United" into "We the people of the United States" by adding it after the "the"
static Sound spliceS()
          Method to splice two sounds together with some silence between them into the current sound
 String toString()
          Method to return the string representation of this sound
 void writeSamplesAsText(String fileName)
          Method to write out the values in the sound to a file as text
 
Methods inherited from class SimpleSound
asArray, blockingPlay, blockingPlayAtRateDur, blockingPlayAtRateInRange, blockingPlayOld, 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(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 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(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 that just shows how to get each sample value and set it again


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 if 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

spliceS

public static Sound spliceS()
Method to splice two sounds together with some silence between them into the current sound

Returns:
the resulting sound

splice

public void splice()
Method to splice two sounds together with some silence between them into the current sound


splicePreamble

public void splicePreamble()
Method to splice "We the " then "United" then "people of the United States" into the current sound


splicePreambleS

public static Sound splicePreambleS()
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

splicePreamble2

public void splicePreamble2()
Method to splice the preamble into the current sound so that it says We the United people of the United States


reverseS

public static Sound reverseS(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


blendSoundsS

public static Sound blendSoundsS()
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.


blendSounds

public void blendSounds()
Method to overlap or blend two sounds. Start by copying the first 20,000 samples from sound1 into the current 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 Sound echo(int delay,
                  int numEchoes)
Method to create multiple echoes of the current sound

Parameters:
delay - the number of samples before the echo starts
numEchoes - the number of echoes desired
Returns:
a new sound with the echoes in it

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.


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.

changeFreq2

public void changeFreq2(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

copySineWave

public void copySineWave(int freq,
                         int maxAmplitude)
Method to copy a sine wave with the given frequency and maximum amplitude to the current sound

Parameters:
freq - the desired frequency
maxAmplitude - the maximum amplitude

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

writeSamplesAsText

public void writeSamplesAsText(String fileName)
Method to write out the values in the sound to a file as text

Parameters:
fileName - the name of the file to write to

createSoundFromTextFile

public static Sound createSoundFromTextFile(String fileName)
Method to create a sound from a text file

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

createPicture

public Picture createPicture()
Method to turn a sound into a picture

Returns:
a created picture

main

public static void main(String[] args)