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 (in seconds)
returns: the number of seconds the sound lasts
Takes a sound as input and returns the number of seconds that sound lasts.
getLength
getLength(sound):
sound: the sound you want to find the length of (how many samples it has)
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 (how many samples it has)
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: the sound you want to get the sample from
index: 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: the sound you want to get the samples from
returns: a list 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 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: the sound you want to get the sample from
index: 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: the sound you want to get the sampling rate from
returns: the integer value 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 belonging to a sound
return: the sound the sample belongs to
Takes a Sample object and returns the Sound that it belongs to.
makeEmptySound makeEmptySound(numSamples[, samplingRate]):
numSamples: the number of samples in sound
samplingRate: the integer value 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: the time in seconds for the duration of the sound
samplingRate: the integer value 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 and (optionally) 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 path of a wav file
returns: the 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: the string path to the file chosen in the dialog box
Opens a file chooser to let the user pick a file and returns the complete path name as a string. Takes no input.
play play(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 MIDI note number, from 0 to 127 (60 = Middle C) 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 (optional)
Plays the given note. No return value. Default intensity is 64.
setSampleValue setSampleValue(sample, value):
sample: the sound sample you want to change the value of
value: the value you want to set the sample to
Takes a Sample object and a value (should be between -32768 and 32767), and sets the sample to that value.
setSampleValueAt setSampleValueAt(sound, index, value):
sound: the sound you want to change a sample in
index: the index of the sample you want to set
value: the value you want to set the sample to
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 that you want to stop playing
Stops a sound that is currently playing.
writeSoundTo writeSoundTo(sound, path):
sound: the sound you want to write out to a file
path: the path to the file you want the picture written to
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