Class Name

SoundFile

Description

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.

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() {
    }
    

Constructors

  • SoundFile(parent, path)
  • SoundFile(parent, path, cache)

Parameters

  • parenttypically use "this"
  • pathfilename of the sound file to be loaded
  • cachekeep 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.

Methods

  • 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.
  • channels()Returns the number of channels of the soundfile as an int (1 for mono, 2 for stereo).
  • 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.
  • jump()Jump to a specific position in the soundfile while continuing to play (or starting to play if it wasn't playing already).
  • pause()Stop the playback of the file, but cue it to the current position.
  • isPlaying()Check whether this soundfile is currently playing.
  • loop()Starts playback which will loop at the end of the soundfile.
  • amp()Changes the amplitude/volume of the player.
  • pan()Move the sound in a stereo panorama.
  • rate()Set the playback rate of the soundfile.