Skip to content

Loading Sounds#

After covering images, we'll go over this a little bit more quickly. Loading sounds follows mostly the same pattern!

Sound is not build into Processing, however, so there are extra steps involved.

Sound Library Setup#

Processing comes with a "Library Manager" that you will find in your SketchImport LibraryManage Libraries menu.

Screenshot of the Manage Libraries Menu Entry

In there, please search for Sound and find the one from the Processing Foundation and hit "install" in the lower right corner.

Screenshot Manager, with the correct one selected: Sound by Author "The Processing Foundation"

This should be all that's required. Well... That and a sound file to play!

Mini Soundboard#

import processing.sound.*;
SoundFile snare;
SoundFile kick;

void setup() {
    snare = new SoundFile(this, "685867__sound_bar_kk__ad-snare.wav");
    kick = new SoundFile(this, "175962__fawkes027__analogish_kick_002.wav");
}

void draw() {
    // just needed for keyPressed to work correctly.
}

void keyPressed() {
    if (keyCode == LEFT) {
        kick.play();
    } else if (keyCode == RIGHT) {
        snare.play();
    }
}

Ignore (and copy) the import on line 1 for now. That's a topic for much later. Other than that, this looks somewhat similar.

  1. We declare two variables of type SoundFile (lines 2 and 3).
  2. We use new Soundfile() in lines 6 and 7 to load the file (yes, this looks different than what we did before, but it serves the same purpose).
  3. We use .play() to trigger playing that sound file. (lines 16 or 18)

Example on Gitlab

You will find this code example in the Examples Gitlab Repository, including the two clips.

Many Many Possibilities#

Sound is a thing we're not getting into too much, sadly. There are TONS of options here that we can't cover. I would encourage you to skim Processing's Sound Reference! You can even work with live audio!

Sound Sources#

Here are a few places where you can get audio clips

(okay, admittedly that list is not very long. Sorry. Suggestions welcome!)

Always Credit the Author

In a university context, all work you hand in is assumed to be yours, that includes any assets that you use. Credit authors of sound bites even if their license does not require it.