Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 144
Introduction to Computer Science: Multimedia

Michael Goldwasser

Spring 2015

Dept. of Math & Computer Science

Lecture Notes: Sound Processing


To work with audio, we will use a package named minim which included in the standard Processing distribution. In these notes, we explore the tip of the iceberg of its capabilities. For more detailed information we point toward:


Overview of Digital Audio

In the physical world, sound is composed of waves, the vibrations of which are detected by the ear. As a point of reference, humans have a typical hearing range that can detect wave frequencies anywhere from 20 to 20000 vibrations per second, and the tone known as "Middle C" on a piano has frequency approximately 261.6 Hz (i.e., vibrations per second).

On computers, the analog signals are converted to digital by rapidly taking samples of the vibration levels. (Read more on wikipedia.) By convention, CD-quality sound uses 44100 samples per second (although other sampling rates can be used), and the amplitude of each sample is often measured as a 16-bit number, interpreted as a magnitude from -32768 to +32767. If the audio is recorded in stereo, then there would be a separate left track and right track, with each sample consisting of a left and right magnitude.

When stored as a file, some audio file formats (e.g. WAV, AIFF, AU) store the raw data in uncompressed format (perhaps including some meta information within the file as well). Many other audio formats use compression, in some cases at the possible degradation of quality (e.g. MP3, AAC). In either case, sound files must typically be returned to the traditional sample representation for playback.


Getting Started with minim

While minim ships as part of the Processing distribution, to use it you must explicitly import one or more libraries. You may then create a "Minim" instance. The first class we will explore is named AudioPlayer and it effectively manages the storage and playback of an audio sample. As our first example, we consider the following example from the Minim Quickstart Guide:

   import ddf.minim.*;
   
   Minim minim;
   AudioPlayer song;
   
   void setup()
   {
     size(100, 100);
   
     minim = new Minim(this);
   
     // this loads mysong.wav from the data folder
     song = minim.loadFile("mysong.wav");
     song.play();
   }

   void draw() { }  // necessary for interactive playback of audio

In this example, variable song represents an AudioPlayer. That player effectively manages the playback of the audio clip and manages a virtual "playhead" that represents a position within the clip. In addition to play(), an AudioPlayer supports functions pause(), rewind(), skip(ms) to skip forward or backwards a certain number of milliseconds (with negative being backward), and cue(ms) which sets the playhead to the absolute number of milliseconds from the start of the clip. In addition, the length() function returns the length of the clip in milliseconds, and position() returns the current position of the playhead in milliseconds.

To examine individual samples, there are two approaches:


Michael Goldwasser
CSCI 144, Spring 2015
Last modified: Thursday, 23 April 2015
Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit