Digital Music Programming II: squelch
This lab demonstrates how to filter out the feedback notes from a PianoDisc MIDI player piano. The piano will return notes played by the computer, so it is difficult to figure out whether the note was played by a performer or is just a feedback note which should be ignored by the computer.
The return time of a note depends on two variables: how hard the note is played, and the pitch of the note.
The following figure displays the callibration data used in this object. The grayscale value of each pixel indicates how long it took for a note with a given attack velocity to return to the computer. White means that the note to a very long time to return (about 250 milliseconds), while dark gray means that the note took a short time to return (about 47 milliseconds). Black indicates that either the note never returned (in low velocities, for example), or that the MIDI note was outside the bounds of the 88-key keyboard. Note the alternating horizontal bands which are caused by the differences in weight/length of black and white keys on the piano. Note also the decreased sensitivity of the mid-range of the piano where the manufacturer of piano made the action more stiff since this is the region of the piano played most often (the measured piano was less than one year old when measured).
The above plot shows the average return time for any given note/velocity. Usually louder notes return faster and have less variation in their return times. Therefore a smaller window of time is necessary to squelch loud notes. Softer notes have a more variable return time, and the squelching window must be made larger. Notice in the plot below that the lower dynamic notes cause a more jagged appearance to the plot. This is because the softer notes are played with less force. The previous momentum of the key before it was played starts to become significant, as well as the motion of other nearby keys and other vibrations in the piano.
Below is a plot of the squelching tolerance window based on the velocity of the outgoing MIDI note. Loud notes have a +/- 5 millsecond windows around their expected return time, while low notes have a +/- 30 millisecond window around their expected return time. If returned notes fall within the squelch window, then it will be identified as a note the computer had previously sent out. This tolerance window is only approximate. See the extra-extra credit question in the exercises for more information.
ImplementationHow does the squelch object work? Outgoing note on messages are timestamped before they leave the computer. A circular buffer is used to store the note number that went out, as well as the minimum and maximum time that the note is expected to return.
When a note-on message comes into the computer from the piano, the squelch object checks through its circular buffer for a note of the same pitch that was sent out. If a note of the same pitch is found, then the object checks to see if a squelch note is expected in the given time window specified by the minimum and maximum arrival times stored if and when the note was first sent out of the computer.
Note-off messages are not squelched and are not a major concern since they will not cause feedback (unless perhaps you send note to the piano based on note-offs received from the piano).