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.*;
Sound s;

void setup() {
  size(200, 200);

  // Play two sine oscillators with slightly different frequencies for a nice "beat".
  SinOsc sin = new SinOsc(this);, 0.2);
  sin = new SinOsc(this);, 0.2);

  // Create a Sound object for globally controlling the output volume.
  s = new Sound(this);

void draw() {
  // Map vertical mouse position to volume.
  float amplitude = map(mouseY, 0, height, 0.4, 0.0);

  // Instead of setting the volume for every oscillator individually, we can just
  // control the overall output volume of the whole Sound library.

Description The Sound class allows for configuring global properties of the sound library's audio synthesis and playback, such as the output device, sample rate or global output volume. Information on available input and output devices can be obtained by calling Sound.list()
list() Print and return information on available audio devices and their number of input/output channels.
sampleRate() Get or set the internal sample rate of the synthesis engine.
inputDevice() Choose the device (sound card) which should be used for grabbing audio input using AudioIn.
outputDevice() Choose the device (sound card) which the Sound library's audio output should be sent to.
volume() Set the overall output volume of the Processing sound library.
Sound(parent, sampleRate, outputDevice, inputDevice, volume)
parent PApplet: typically use "this"
sampleRate int: the sample rate to be used by the synthesis engine (default 44100)
outputDevice int: the device id of the sound card that sound should be played on
inputDevice int: the device id of the sound card from which sound should be captured
volume float: the overall output volume of the library (default 1.0)
Updated on December 22, 2018 01:32:08am EST

Creative Commons License