- Processing
- p5.js
- Processing.py
- Processing for Android
- Processing for Pi

- Processing Foundation

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.

Name | ### SoundFile
Examples |
    import processing.sound.*;
    SoundFile file;

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

      // Load a soundfile from the /data folder of the sketch and play it back
      file = new SoundFile(this, "sample.mp3");
      file.play();
    }

    void draw() {
    }
Description | This is a Soundfile Player which allows to play back and manipulate soundfiles. Supported formats are: WAV, AIF/AIFF, MP3. MP3 decoding can be very slow on ARM processors (Android/Raspberry Pi), we generally recommend you use lossless WAV or AIF files.
Methods |
channels() | Returns the number of channels of the soundfile.
cue() | Cues the playhead to a fixed position in the soundfile.
duration() | Returns the duration of the soundfile in seconds.
frames() | Returns the number of frames of this soundfile.
play() | Starts the playback of the soundfile. Only plays to the end of the audiosample once.
jump() | Jump to a specific position in the soundfile while continuing to play.
pause() | Stop the playback of the file, but cue it to the current position so that the next call to play() will continue playing where it left off.
isPlaying() | Check whether this soundfile is currently playing.
loop() | Starts playback which will loop at the end of the soundfile.
amp() | Change the amplitude/volume of this audiosample.
pan() | Move the sound in a stereo panorama. Only works for mono soundfiles!
rate() | Set the playback rate of the soundfile.
stop() | Stops the playback.
Constructor |
    SoundFile(parent, path)
    SoundFile(parent, path, cache)
Parameters |
parent | PApplet: typically use "this"
path | String: filename of the sound file to be loaded
cache | boolean: 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.

Updated on January 1, 2021 03:38:11am EST
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.