This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.



import processing.sound.*;
AudioSample sample;

void setup() {
  size(640, 360);

  // Create an array and manually write a single sine wave oscillation into it.
  int resolution = 1000;
  float[] sinewave = new float[resolution];
  for (int i = 0; i < resolution; i++) {
    sinewave[i] = sin(TWO_PI*i/resolution);

  // Create the audiosample based on the data, set framerate to play 200 oscillations/second
  sample = new AudioSample(this, sinewave, 200 * resolution);

  // Play the sample in a loop (but don't make it too loud)

void draw() {
Description This class allows you low-level access to an audio buffer to create, access, manipulate and play back sound samples. If you want to pre-load your audio sample with an audio file from disk you can do so using the SoundFile subclass.
amp() Change the amplitude/volume of this audiosample.
channels() Returns the number of channels in the audiosample.
cue() Cues the playhead to a fixed position in the audiosample.
duration() Returns the duration of the audiosample in seconds.
frames() Returns the number of frames of the audiosample.
jump() Jump to a specific position in the audiosample without interrupting playback.
loop() Starts playback which loops from the beginning to the end of the sample.
play() Starts the playback of the audiosample. Only plays to the end of the audiosample once.
rate() Set the playback rate of the audiosample.
resize() Resizes the underlying buffer of the audiosample to the given number of frames.
sampleRate() Returns the underlying sample rate of the audiosample.
pan() Move the sound in a stereo panorama. Only works for mono audiosamples!
pause() Stop the playback of the sample, but cue it to the current position.
read() Read some frames of this audio sample into an array. Stereo samples contain two data points per frame.
write() Write some frames of this audio sample. Stereo samples require two data .points per frame.
AudioSample(parent, frames)
AudioSample(parent, frames, stereo)
AudioSample(parent, frames, stereo, frameRate)
AudioSample(parent, frames, frameRate)
AudioSample(parent, data)
AudioSample(parent, data, stereo)
AudioSample(parent, data, frameRate)
AudioSample(parent, data, stereo, frameRate)
parent PApplet: typically use "this"
frames int: the desired number of frames for this audiosample
stereo boolean: whether to treat the audiosample as 2-channel (stereo) or not (default: false)
frameRate int: the underlying frame rate of the sample (default: 44100)
data float[]: an array of float values to be used as this audiosample's sound data. The audiosample will consequently have as many frames as the length of the given array.
Updated on June 6, 2020 10:05:52pm EDT