User Tools

Site Tools


Processing Tutorial

Part 11: Sound

-11.1: ESS (.wav and .mp3 reading, modification and writing)

ESS is the main sound library that we'll be using in Processing. ESS supports MP3 files and certain types of WAV files.

-11.1.1: Including ESS and Loading Sounds

To include the ESS libraries, go to the Sketch menu, then Import Libarry → Ess.

ESS has to run in Continuous or Java mode, because you have to include the stop() function:

public void stop() {

To start ESS, you have to include the following command in setup() before doing anything else with ESS:


If you want to load a sound clip, it has to be in the “data” folder of yor sketch.

To load a sound file, create a new AudioChannel object:

AudioChannel myChannel = new AudioChannel("FileName.wav");

-11.1.2: Playback

To play a sound back, just use the command;

-11.1.3: Manipulating Sounds

Each AudioChannel object has an array called “samples[]” that contains short audio samples from the sound file. You can directly access this array and change those values.


-Length of audio clip in milliseconds


-“Loops” can be any int, or Ess.FOREVER to loop infinitely.


-The current volume, between 0 and 1.


-Set the volume.


-Volume in decibels.


-Set the gain.


-The pan in the stereo field. Between -1 or Ess.LEFT (far left) and 1 or Ess.RIGHT (far right).


-Set the pan.


-Boolean- true if muted, false otherwise.


-Sets mute state.

AudioChannel.fadeTo(volume, millseconds)

-Fades to the given volume over the given number of milliseconds.


-Stop fading at the current volume.

AudioChannel.panTo(pan, milliseconds)

-Pan to the given position over the given number of milliseconds.


-Stop panning at the current location.

[I never had to use AudioStreams, AudioInputs or AudioFiles for any example, so I'm leaving them off.]

-11.1.4: Saving Sounds

To save a sound clip, just use


-11.1.5: Limitations

Every sound sample has extremes, or limits, outside of which the data will be truncated to the limits. In ESS, the extremes are -1 and 1. So, if you assign a value greater than 1 or less than -1 to a sound sample, it will be given the value 1 or -1. If you play back the sound clip, you'll hear a lot of distortion- this is called “clipping”. You lose a lot of sound data when clipping occurs, which leads to a static sound, so be careful.

-11.2: jm-Etude (MIDI reading,manipulation)

For MIDI clips, we use the jm-Etude libraries. To understand Etude, you have to understand the object hierarchy.

-A song is called a “score”.

-A score is made up of “parts”.

-A part is made up of “phrases” and can be played by different “instruments”.

-A phrase is made up of “notes”.

-A note has pitch and volume.

-11.2.1: Including jm-Etude and Loading Sounds

To include the ESS libraries, go to the Sketch menu, then Import Library → jmetude.

Unlike ESS, jm-Etude can run in Basic mode.

To start jm-Etude, run the following command before doing anything else with Etude:

Etude myEtude = new Etude(this);

To load a sound clip, use the following command:

myEtude.createScore(String scoreTitle, String fileName);

You will use the scoreTitle string to refer to this object in other functions.

-11.2.2: Playback

To play back a sound clip, use the command

myEtude.playMIDI(String title);

where title is the title of an existing score, phrase or part.

-11.2.3: Manipulating Sounds

After we've loaded a file, we have a score. We know that scores are made up of parts. How do we access those parts?

String[] myParts = myEtude.getScoreParts(String ScoreTitle);

This gives you an array of the Part names. To get the phrases from a part, we use

String[] myPhrases = myEtude.getPartPhrases(String PartTitle);

And to get notes from a Phrase, we use

String[] myNotes = myEtude.getPhraseNotes(String PhraseTitle);

You can directly access and modify notes, but not whole phrases, parts or scores. You can remove parts from phrases or phrases from scores with:

removePartPhrase(String partTitle, String phraseTitle);
removeScorePart( String scoreTitle, String partTitle );

You can add parts to phrases and phrases to scores with:

addPartPhrase( String partTitle, String phraseTitle );
addScorePart( String scoreTitle, String partTitle ); 

-11.2.4: Limitations

A few things you can't do with jm-Etude:

  • Change the order of parts or phrases
  • Make blanket changes to entire parts, phrases or scoress
  • Save sound files.

-11.3: The Book's Classes (MIDI creation)

We use the MidiPlayer class to play MIDI sounds.


MidiPlayer myMIDI = new MidiPlayer();

You have to have the proper classes from the book in your sketch's “code” folder.
Next: Part 12- Video

Last: Part 10- Images

part_11-_sound.txt · Last modified: 2007/08/30 13:53 (external edit)