In this session we’ll hook up out first keyboard instrument: a simple additive synthesis organ. We’ll use a MIDI keyboard for this session and you’ll need to bring it to other sessions in the future as well.
MIDI is an old standardized protocol for devices to talk to each other through “MIDI” messages. While it has a lot of deficiencies and problems, ranging from bandwidth to extreme standardization, it has been around so long that it generally works and is readily available.
5.1 Making MIDI Work.
Make sure Pd is closed and plug in your keyboard. Your keyboard should be getting power either because it is powered by your USB port or through an external power source if needed. Once your keyboard is plugged and powered open Pd. In the menu Media/MIDI Settings or in the menu Preferences/MIDI you will need to select your device as an input device. In Linux, you’ll need to choose ALSA MIDI in the Media Menu, select at least one input and output port, and then connect your device to Pd with the aconnect command. To do this type the comand “aconnect -i” to list your input devices and note the client numbers of your device and of Pd and then connect them with the command “aconnect device_client_no pd_client_no”, where these last two arguments are the numbers you noted earlier, so something like “aconnect 24 128”.
Once you’ve setup your device in Pd, create a new object [notein] and check out its help file. This help file is the same for all MIDI objects. As you press keys and pads (if you have them) you should see the numbers coming out of [notein] changing, and as you move faders, knobs, modulation wheel, and pressure pads (if you have any of these), you should see the numbers coming out of [ctlin] changing. Finally, if you have a pitch bend wheel, you’ll see the output [bendin] changing as well.
For now, we will focus on the output of [notein] and in particular to its first two outlets, which output pitch and velocity.We have seen pitch so far, but velocity is a new term. Velocity is a measure of the intensity with which you press the key, calculated by the time it takes for a key to go from being at rest to fully pressed. Midi notes are divided in “note on” events and “note off” events. Pitch is the same for both of these kinds of events as it they refer to a single key, but for note on events, velocity will range from 1 (slowest/softest) to 127 (fastest/strongest), and will be zero for note off events, to mark the release of the key.
5.2 Creating an Abstraction.
We have already seen how to make a sub-patch, but now we want to consider making abstractions. abstractions are patches that you can call from other patches and show up as an object. The main benefit of using abstractions is that whatever you change in the abstraction file is updated to all the instances of that abstraction. Below are steps to create an abstraction.
To create and use an abstraction in our organ project you need to follow the steps below:
- STEP 1: Create a folder and call it “organ-v.1”. All files related to our new organ will be saved here.
- STEP 2: Create a new patch like the one shown below. This is a hack one of our patches from last week that does additive synthesis with 8 harmonics. Save this patch as a new file called “additive.pd”. Save it in the folder above.
- STEP 3: Create a new patch and save it as “main.pd” in the same folder. At this point your folder should only have two files: main.pd and additive.pd.
- STEP 4: Create a new object called additive and you should be able to see a new object with one inlet and one outlet. If this step doesn’t work close everything and open the main file in your folder again and that should solve the problem.
To access an abstraction you can click on it in run mode and you’ll be able to see and edit its contents. Any changes you make on one copy of the abstraction will take effect on all other copies of the abstraction.
5.3 A Monophonic keyboard.
Let’s briefly analyze how events are generated by [notein] as you press the keys. To do this we pack pitch and velocity and print the results in the console. As you play a melody you’ll find that due to idiosyncrasies of the keyboard or perhaps to sloppy technique, the logical order of “noteon noteoff noteon noteoff” that a melody suggests is often altered and we get “noteon noteon noteoff noteoff”. This kind of instability makes it harder to perform and leads to keyboards not making sound when a key is currently being pressed. To deal with this, we use a voice managing object called “poly”. Create [poly] and read the helpfile.
Because we are aiming at a monophonic keyboard at this point, we will first use [poly] with one voice and allowing voice stealing. This means that whenever a new key is pressed, that key will take the voice. Thus we use [poly 1 1]. Because we only have one voice we will temporarily ignore the first outlet of poly and only use the second (pitch) and third (velocity).
As you can see from analyzing our “additive” abstraction, its inlet is designed to receive pitch in “MIDI” units, so we can connect the second outlet of [poly] to the inlet of [additive]. However, to control the amplitude of “additive” we need to do a few things. First, to control amplitude we need to multiply the output of [additive] times a [line~] to avoid roughness. To avoid clicks we need to create ramps of approximately 30 ms, although you use a different number you may prefer. Finally, the amplitude range of the output of [additive] is -1 to 1, so we need to multiply it times a scalar that ranges from 0-1 to keep it within range. Because velocity is in a midi scale (0-127) we must divide it by 127 to stay in range.
We should now have a monophonic keyboard!
5.4 Timbres and presets
So why don’t you have sound?
At this point, all our harmonics have an amplitude of 0, that is, the amplitudes of our oscillators is being multiplied by a constant of zero. To change these amplitudes we need to send values to the receive objects, h1 through h8. By sending a value between 0 and 1 to each of these receives, we give relative amplitudes to the harmonics and thus create several “static” timbres. In the figure on the right, we create a message box that can send values to out organ as presets.
Try each of them and describe how your perception of the timbral quality of the organ changes with each preset. In general, when there is more energy in the higher harmonics the sounds are generally brighter. It is interesting to note that in the fourth preset, the fundamental or first harmonic has an amplitude of 0, and the rest of harmonics of 1, however, the perception of the fundamental is still present. This is known as the missing fundamental phenomenon.
5.5 Polyphonic Organ
At this point you might be craving for more voices. To do this we need to modify poly so that we can use more voices, four in this case, so poly goes from the arguments “1 1” to “4 1”. The first outlet of poly will give you the voice number so we pack it along with with pitch and velocity.
At this point we need to introduce [route] which allows us to literally route lists according to their first element. It is important to note that route will eliminate the first element if it matches and send the rest of the list. Thus if we have [route 43] and we send the input messsage “43 54 65”, the output of the first outlet will be “54 65”.
Finally, we need to copy our voice three more times to have a total of four voices and divide the sum of their signals by 4 before sending to the [dac~]. Analyze and test the patch shown in the figure below.