Electronics have been used to create music for nearly a century. One of the first electronic instruments is the theremin, an instrument that is played without ever actually touching it.
Because the theremin works by using hand positions to directly determine the frequency and amplitude of a sound wave, it is relatively easy to simulate one in software. The code below uses the mouse pointer in lieu of the thereminist’s hands.
Installing Processing LibrariesNOTE: Before running the
Theremin.pdesketchbook, you will need to install the Processing Sound software library, which provides the additional code needed for generating audio effects.
- Open the
Theremin.pdesketchbook in Processing.
- Under the Sketch menu, select Import Library... and choose Add Library...
- Scroll down the list to find Sound and select it.
- Click on the Install button.
Click to Download:
As you experiment with the virtual theremin, note the following:
Xmaps to frequency.
Ymaps to amplitude.
- You can click at a particular point to fix the harmonic.
After you have
thoroughly annoyed everyone in the vicinity made beautiful music, be prepared to discuss the following before moving on to your assignment.
- What are the parameters required to generate a sound? Note that these are the qualities/quantities that change producing a corresponding change in output.
- Are these parameters sufficient to generate any type of sound? What other parameters might be needed to generate notes that sound like a guitar or a flute?
- How do these parameters approximate physical reality? How is this similar to the parameters used to generate visual artifacts, like color, position, or brightness?
Your assignment is to program a virtual piano in Processing—il Processiano! Download the starter code for il Processiano.
Click to Download:
Extend the code to generate audio with key presses. The starter code generates and displays notes when the corresponding keys are pressed (
e), but your program must meet the following specifications:
Extend the code to work with the entire range
b. The following table will help you map notes to exact frequencies.
Extend the code to work across two octaves. When you press the
Ckeys (AKA capital “C”), the procession should play a C note the next octave higher. HINT: Physics makes this easy. Each note is twice the frequency of itself in the previous octave. In other words, the C one octave above middle C (261.626 Hz) is 2 × 261.626, or roughly 523.252 Hz).
Try playing a song:
Processiano.pde file of your Processiano sketchbook.
Processiano uses only natural (♮) notes—i.e., no sharps (♯) or flats (♭). Extend the program to allow the user to designate a sharp or flat by using the
ALT keys along with the designated note key. Note that not all notes have corresponding sharps and flats! This is why some pairs of white keys on a piano are separated by black keys and some are not (e.g., there is no such note as E♯ or F♭).