ESS is the main sound library that we'll be using in Processing. ESS supports MP3 files and certain types of WAV files.
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() { Ess.stop(); super.stop(); }
To start ESS, you have to include the following command in setup() before doing anything else with ESS:
Ess.start(this);
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");
To play a sound back, just use the command
AudioChannel.play();
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.
-Fades to the given volume over the given number of milliseconds.
-Stop fading at the current volume.
-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.]
To save a sound clip, just use
AudioChannel.saveSound("filename");
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.
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.
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.
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.
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 );
A few things you can't do with jm-Etude:
We use the MidiPlayer class to play MIDI sounds.
Example:
MidiPlayer myMIDI = new MidiPlayer(); myMIDI.playNote(52,250);
You have to have the proper classes from the book in your sketch's “code” folder.
Next: Part 12- Video
Last: Part 10- Images