Package processing.sound
Class SoundFile
java.lang.Object
processing.sound.SoundObject
processing.sound.AudioSample
processing.sound.SoundFile
This is a Soundfile player which allows to play back and manipulate sound
files. Supported formats are: WAV, AIF/AIFF, and MP3.
MP3 decoding can be very slow on ARM processors (Android/Raspberry Pi), we generally recommend you use lossless WAV or AIF files.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidamp(float amp) Change the amplitude/volume of this audiosample.intchannels()Returns the number of channels of the soundfile as an int (1 for mono, 2 for stereo).voidcue(float time) Cues the playhead to a fixed position in the soundfile.floatduration()Returns the duration of the soundfile in seconds.intframes()Returns the number of frames of this soundfile.booleanCheck whether this soundfile is currently playing.voidjump(float time) Jump to a specific position in the soundfile while continuing to play (or starting to play if it wasn't playing already).voidloop()voidloop(float rate) voidloop(float rate, float amp) voidloop(float rate, float pos, float amp) Starts the playback of the audiosample.voidloop(float rate, float pos, float amp, float add) Starts playback which will loop at the end of the soundfile.voidpan(float pos) Move the sound in a stereo panorama.-1.0 pans to the left channel and 1.0 to the right channel.voidpause()Stop the playback of the file, but cue it to the current position.voidplay()Starts the generatorvoidplay(float rate) voidplay(float rate, float amp) voidplay(float rate, float pos, float amp) voidplay(float rate, float pos, float amp, float add) Starts the playback of the audiosample.voidplay(float rate, float pos, float amp, float add, float cue) Starts the playback of the soundfile.voidrate(float rate) Set the playback rate of the soundfile.booleanRemove this SoundFile's decoded audio sample from the cache, allowing it to be garbage collected once there are no more references to this SoundFile.Methods inherited from class processing.sound.AudioSample
cueFrame, jumpFrame, percent, playFor, playFor, position, positionFrame, read, read, read, read, resize, resize, sampleRate, set, set, stop, write, write, writeMethods inherited from class processing.sound.SoundObject
add, getUnitGenerator
-
Constructor Details
-
SoundFile
-
SoundFile
- Parameters:
parent- typically use "this"path- filename of the sound file to be loadedcache- keep the sound data in RAM once it has been decoded (default: true). Note that caching essentially disables garbage collection for the SoundFile data, so if you are planning to load a large number of audio files, you should set this to false.
-
-
Method Details
-
removeFromCache
public boolean removeFromCache()Remove this SoundFile's decoded audio sample from the cache, allowing it to be garbage collected once there are no more references to this SoundFile.- Returns:
- true if the sample was removed from the cache, false if it wasn't . actually cached in the first place.
-
channels
public int channels()Returns the number of channels of the soundfile as an int (1 for mono, 2 for stereo).- Overrides:
channelsin classAudioSample- Returns:
- Returns the number of channels of the soundfile (1 for mono, 2 for stereo)
- See Also:
-
cue
public void cue(float time) Cues the playhead to a fixed position in the soundfile. Note that cue() only affects the playhead for future calls to play(), but not to loop().- Overrides:
cuein classAudioSample- Parameters:
time- position in the soundfile that the next playback should start from, in seconds.
-
duration
public float duration()Returns the duration of the soundfile in seconds.- Overrides:
durationin classAudioSample- Returns:
- The duration of the soundfile in seconds.
-
frames
public int frames()Returns the number of frames of this soundfile.- Overrides:
framesin classAudioSample- Returns:
- The number of frames of this soundfile.
-
play
public void play()Description copied from class:SoundObjectStarts the generator- Overrides:
playin classAudioSample
-
play
public void play(float rate) - Overrides:
playin classAudioSample
-
play
public void play(float rate, float amp) - Overrides:
playin classAudioSample
-
play
public void play(float rate, float pos, float amp) - Overrides:
playin classAudioSample
-
play
public void play(float rate, float pos, float amp, float add) Description copied from class:AudioSampleStarts the playback of the audiosample. Only plays to the end of the audiosample once. If cue() or pause() were called previously, playback will resume from the cued position.- Overrides:
playin classAudioSample- Parameters:
rate- relative playback rate to use. 1 is the original speed. 0.5 is half speed and one octave down. 2 is double the speed and one octave up.pos- the panoramic position of this sound unit from -1.0 (left) to 1.0 (right). Only works for mono audiosamples!amp- the desired playback amplitude of the audiosample as a value from 0.0 (complete silence) to 1.0 (full volume)add- position in the audiosample that playback should start from, in seconds.
-
play
public void play(float rate, float pos, float amp, float add, float cue) Starts the playback of the soundfile. Only plays to the end of the audiosample once. If cue() or pause() were called previously, playback will resume from the cued position.- Overrides:
playin classAudioSample- Parameters:
rate- relative playback rate to use. 1 is the original speed. 0.5 is half speed and one octave down. 2 is double the speed and one octave up.amp- the desired playback amplitude of the audiosample as a value from 0.0 (complete silence) to 1.0 (full volume)pos- the panoramic position of this sound unit from -1.0 (left) to 1.0 (right). Only works for mono soundfiles!cue- position in the audiosample that playback should start from, in seconds.add- offset the output of the generator by the given value
-
jump
public void jump(float time) Jump to a specific position in the soundfile while continuing to play (or starting to play if it wasn't playing already).- Overrides:
jumpin classAudioSample- Parameters:
time- position to jump to, in seconds.- See Also:
-
pause
public void pause()Stop the playback of the file, but cue it to the current position. The next call to play() will continue playing where it left off.- Overrides:
pausein classAudioSample- See Also:
-
isPlaying
public boolean isPlaying()Check whether this soundfile is currently playing.- Overrides:
isPlayingin classAudioSample- Returns:
- `true` if the soundfile is currently playing, `false` if it is not.
-
loop
public void loop()- Overrides:
loopin classAudioSample
-
loop
public void loop(float rate) - Overrides:
loopin classAudioSample
-
loop
public void loop(float rate, float amp) - Overrides:
loopin classAudioSample
-
loop
public void loop(float rate, float pos, float amp) Description copied from class:AudioSampleStarts the playback of the audiosample. Only plays to the end of the audiosample once. If cue() or pause() were called previously, playback will resume from the cued position.- Overrides:
loopin classAudioSample- Parameters:
rate- relative playback rate to use. 1 is the original speed. 0.5 is half speed and one octave down. 2 is double the speed and one octave up.pos- the panoramic position of this sound unit from -1.0 (left) to 1.0 (right). Only works for mono audiosamples!amp- the desired playback amplitude of the audiosample as a value from 0.0 (complete silence) to 1.0 (full volume)
-
loop
public void loop(float rate, float pos, float amp, float add) Starts playback which will loop at the end of the soundfile.- Overrides:
loopin classAudioSample- Parameters:
rate- relative playback rate to use. 1 is the original speed. 0.5 is half speed and one octave down. 2 is double the speed and one octave up.pos- the panoramic position of this sound unit from -1.0 (left) to 1.0 (right). Only works for mono soundfiles!amp- the desired playback amplitude of the audiosample as a value from 0.0 (complete silence) to 1.0 (full volume)add- offset the output of the generator by the given value
-
amp
public void amp(float amp) Change the amplitude/volume of this audiosample.- Overrides:
ampin classAudioSample- Parameters:
amp- A float value between 0.0 (complete silence) and 1.0 (full volume) controlling the amplitude/volume of this sound.
-
pan
public void pan(float pos) Move the sound in a stereo panorama.-1.0 pans to the left channel and 1.0 to the right channel. Note that panning is only supported for mono (1 channel) soundfiles.- Overrides:
panin classAudioSample- Parameters:
pos- the panoramic position of this sound unit from -1.0 (left) to 1.0 (right).
-
rate
public void rate(float rate) Set the playback rate of the soundfile. 1 is the original speed. 0.5 is half speed and one octave down. 2 is double the speed and one octave up.- Overrides:
ratein classAudioSample- Parameters:
rate- Relative playback rate to use. 1 is the original speed. 0.5 is half speed and one octave down. 2 is double the speed and one octave up.
-