Examples
Methods
Returns true if the sound file finished loading successfully.
p5.SoundFile has two play modes: restart
and sustain
. Play Mode determines what happens to a p5.SoundFile if it is triggered while in the middle of playback. In sustain mode, playback will continue simultaneous to the new playback. In restart mode, play() will stop playback and start over. With untilDone, a sound will play only if it's not already playing. Sustain is the default mode.
Returns true if a p5.SoundFile is paused, false if not (i.e. playing or stopped).
Set the stereo panning of a p5.sound object to a floating point number between -1.0 (left) and 1.0 (right). Default is 0.0 (center).
Returns the current stereo pan position (-1.0 to 1.0)
Multiply the output volume (amplitude) of a sound file between 0.0 (silence) and 1.0 (full volume). 1.0 is the maximum amplitude of a digital sound, so multiplying by greater than 1.0 may cause digital distortion. To fade, provide a rampTime
parameter. For more complex fades, see the Envelope class.
Alternately, you can pass in a signal source such as an oscillator to modulate the amplitude with an audio signal.
Return the current position of the p5.SoundFile playhead, in seconds. Time is relative to the normal buffer direction, so if reverseBuffer
has been called, currentTime will count backwards.
Returns an array of amplitude peaks in a p5.SoundFile that can be used to draw a static waveform. Scans through the p5.SoundFile's audio buffer to find the greatest amplitudes. Accepts one parameter, 'length', which determines size of the array. Larger arrays result in more precise waveform visualizations.
Inspired by Wavesurfer.js.
Reverses the p5.SoundFile's buffer source. Playback must be handled separately (see example).
Connects the output of a p5sound object to input of another p5.sound object. For example, you may connect a p5.SoundFile to an FFT or an Effect. If no parameter is given, it will connect to the main output. Most p5sound objects connect to the master output when they are created.
Disconnects the output of this p5sound object.
Replace the current Audio Buffer with a new Buffer.
Schedule events to trigger every time a MediaElement (audio/video) reaches a playback cue point.
Accepts a callback function, a time (in seconds) at which to trigger the callback, and an optional parameter for the callback.
Time will be passed as the first parameter to the callback function, and param will be the second parameter.
Remove a callback based on its ID. The ID is returned by the addCue method.
Remove all of the callbacks that had originally been scheduled via the addCue method.
Save a p5.SoundFile as a .wav file. The browser will prompt the user to download the file to their device. To upload a file to a server, see getBlob
This method is useful for sending a SoundFile to a server. It returns the .wav-encoded audio data as a "Blob". A Blob is a file-like data object that can be uploaded to a server with an http request. We'll use the httpDo
options object to send a POST request with some specific options: we encode the request as multipart/form-data
, and attach the blob as one of the form values using FormData
.