Objects and Methods Summary


[Page 287 (continued)]

In this chapter, we talk about several kinds of encodings of data (or objects).

Sound

Sound objects are encodings of sounds, typically coming from a WAV file.

SoundSample

An object that represents a sample in a sound. The value of a sample is between -32,768 and 32,767 representing the voltage that a microphone would generate at a given instant when recording a sound. The length of the instant is typically either 1/44,100 of a second (for CD-quality sound) or 1/22,050 of a second (for good enough sound on most computers). A SoundSample object remembers what sound it came from, so if you change its value, it knows to go back and change the right sample value in the sound.



[Page 288]

Here are the methods used or introduced in this chapter:

Math Methods

Math.abs(number)

Takes a number and returns it as a positive number.


FileChooser Methods

FileChooser.getMediaPath(String fileName)

Takes a filename as input, and returns the full path name of the file with the media directory before the filename.

FileChooser.pickAFile()

Lets the user pick a file and returns the complete path name as a string.

FileChooser.setMediaPath(String directory)

Takes a directory as input and sets the directory name to be what is added to the passed filename using getMediaPath.


Sound Methods

blockingPlay()

Plays the Sound object it is invoked on, and makes sure that no other sound plays at the exact same time. (Compare two blockingPlay's with two play's right after each other.)

getLength()

Returns the number of samples in the Sound object it is invoked on.

getSamples()

Returns an array of SoundSample objects for the Sound object it is invoked on.

getSampleValueAt(int index)

Takes an index (an integer value), and returns the value of the sample at that index for the Sound object it is invoked on.

getSamplingRate()

Returns the number representing the number of samples in each second for the Sound object it is invoked on.

play()

Plays the Sound object it is invoked on.

setSampleValueAt(int index, int value)

Takes an index, and a value, and sets the value of the sample at the given index in the Sound object it was invoked on to the given value.

write(String fileName)

Takes a filename (a string) and writes the sound in the Sound object it is invoked on to that file as a WAV file. (Make sure that the filename ends in ".wav" if you want the operating system to treat it right.)



[Page 289]

SoundSample Methods

getValue()

Returns the value for the SoundSample object it is invoked on.

setValue(int value)

Sets the value for the SoundSample object it is invoked on to be the passed value.




Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net