Table of Contents > Understanding Sound in JES > Sound Functions in JES
Sound Functions in JES

This is a list of functions that you may find useful when you are creating programs to manipulate or create audio files in JES. Remember, these functions are part of a special library, and are not available in other Jython programming environments.
blockingPlay
blockingPlay(sound):
sound: the sound that you want to play.
Plays the sound provided as input, and makes sure that no other sound plays at the exact same time. (Try two play's right after each other.)
duplicateSound
duplicateSound(sound):
sound: the sound you want to duplicate.
returns: a new Sound object with the same Sample values as the original.
Takes a sound as input and returns a new Sound object with the same Sample values as the original.
getDuration
getDuration(sound):
sound: the sound you want to find the length of.
returns: the number of samples in sound.
Takes a sound as input and returns the length of the sound in seconds.
getLength
getLength(sound):
sound: the sound you want to find the length of.
returns: the number of samples in sound.
Takes a sound as input and returns the number of samples in that sound.
getNumSamples
getNumSamples(sound):
sound: the sound you want to find the length of.
returns: the number of samples in sound.
Takes a sound as input and returns the number of samples in that sound. (Same as getLength)

getSampleObjectAt

getSampleObjectAt(sound, index):
sound: A Sound, the sound you want to get the sample from.
index: An Integer, the index value of the sample you want to get.
returns: The sample object at that index.
Takes a sound and an index (an integer value), and returns the Sample object at that index
getSamples
getSamples(sound):
sound: A Sound, the sound you want to extract the samples from
returns: A collection of all the samples in the sound
Takes a sound as input and returns the Samples in that sound.
getSampleValue
getSampleValue(sample):
sample: A Sample, a sample of a sound.
returns: The integer value of that sample.
Takes a Sample object and returns its value (between -32768 and 32767). Formerly getSample().
getSampleValueAt
getSampleValueAt(sound, index):
sound: A Sound, the sound you want to use the sample from.
index: An Integer, the index of the sample you want to get the value of.
Takes a sound and an index (an integer value), and returns the value of the sample (between -32768 and 32767) for that object.
getSamplingRate
getSamplingRate(sound):
sound: A Sound, the sound you want to get the sampling rate from.
returns: An Integer representing the number of samples per second.
Takes a sound as input and returns the number representing the number of samples in each second for the sound
getSound
getSound(sample):
sample: A Sample, a sample belonging to a sound.
return: A Sound, the sound the sample belongs to.
Takes a Sample object and returns the Sound that it remembers as its own.
makeEmptySound makeEmptySound(numSamples[, samplingRate]):
numSamples: An integer, number of samples in sound
[samplingRate]: An integer, representing the number of samples per second of sound (optional)
returns: An Empty Sound.
Takes one or two integers as input. Returns an empty Sound object with the given number of samples and (optionally) the given sampling rate. Default rate is 22050 bits/second. The resulting sound must not be longer than 600 seconds. Prints an error statement if numSamples or samplingRate are less than 0, or if (numSamples/samplingRate) > 600.
makeEmptySoundBySeconds makeEmptySoundBySeconds(duration[, samplingRate]):
duration: An integer, time in seconds for duration of sound
[samplingRate]: An integer, representing the number of samples per second of sound (optional)
returns: An Empty Sound.
Takes a floating point number and optionally an integer as input. Returns an empty Sound object of the given duration with the given sampling rate. Default rate is 22050 bits/second. If the given arguments do not multiply to an integer, the number of samples is rounded up. Prints an error statement if duration or samplingRate are less than 0 or if duration > 600.
makeSound makeSound(path):
path: A String, a path to a wav file.
returns: A Sound, created from the file at the given path.
Takes a filename as input, reads the file, and creates a sound from it. Returns the sound.
pickAFile pickAFile():
returns: A String, the path to the file chosen in the dialog box.
Lets the user pick a file and returns the complete path name as a string. No input.
play play(A Sound):
sound: the sound you want to be played.
Plays a sound provided as input. No return value.
playNote playNote(note, duration, intensity):
note: the note (a number > 0) you want to be played.
duration: the duration you want the note to be played in milliseconds.
intensity: the intensity (a number between 0 and 127) you want the note to be played.
Plays a note. No return value
setSampleValue setSampleValue(sample, value):
sample: A Sample, the sound sample tou want to change the value of.
value: An Integer, the value you want to set the sample to.
Takes a Sample object and a value, and sets the sample to that value. Formerly setSample().
setSampleValueAt setSampleValueAt(sound, index, value):
sound: A Sound, the sound you want to change a sample in.
index: An Integer, the index of the sample you want to set.
value: An Integer, the new value of the sample you want to set.
Takes a sound, an index, and a value (should be between -32768 and 32767), and sets the value of the sample at the given index in the given sound to the given value.
stopPlaying stopPlaying(sound):
sound: the sound you want to stop being played.
Stops playing a sound provided as input. No return value.
writeSoundTo writeSoundTo(sound, filename):
sound: A Sound, the sound you want to write out to a file.
filename: A String, the path of the location you want to write the sound.
Takes a sound and a filename (a string) and writes the sound 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.)


jump to top