________________________________________________________________________ MIDI-based adaptive tuning by common-tone matching rev. 7 Sept. 2002. _ _ _ _ __ __ __ ___ ___ ____ __________________________________________ *Introduction* Meantone temperaments (of which 12-tone equal temperament is a special case), which distribute the syntonic comma (81/80) over a chain of fifths (3:2's), have dominated Western music since 5-limit consonance (triadic harmony) came into common use about 500 years ago. As a result, it is impossible to render much of this music in just intonation without creating melodic (absolute pitch space) distortion in it. There are many ways to deal with melodic distortion. The fact that fine chamber ensembles often render music with less harmonic distortion than 12-tone equal temperament and without the apparent means of using more accurate temperaments suggests that fruitful ways exist. We describe a configurable leisure-time MIDI-processing algorithm with the aim of exposing the choices that define a "way" from the composer's point of view. The algorithm can then serve as an interface for testing music- theoretical questions (such as: When is smoothness in local common-tone relations preferred over steadiness of the global pitch standard?) or as a composition tool -- the composer could automate the types of tuning choices he tends to make, saving the chore of tuning every pitch by hand with exotic notation. The resulting MIDI performance could stand by itself, or be used to train human performers. Composers who want manual tuning as a degree of freedom may still value the ability to quickly test several general approaches to a piece. Around the turn of the 20th century, tetradic harmony became popular in Western music. In 12-tone equal temperament, this implies 7- and 9-limit consonances, and further commas that are not tempered out by the most accurate 5-limit meantones (which are also the most popular historical meantones). The present algorithm exposes harmonic limit as a free parameter, and can render a given piece of music in the 3-limit through the 19-limit with the same logic. *Configurable Parameters* k - (2-6) polyphony n - (odds 3-19) harmonic limit r - (1-3) consonance ranking method c - (1-4) chord substitution cutoff p - (1-4) continuous events awareness l - (1-2) locked events handling h - (1-4) note history threshold d - (1-2) dropped events sandwiching a - (1-4) common-tone root arbitration f - (1-2) chord not found handling s - (1-3) subset method *The Consonance Lookup Table* Create a database relating 12-tone chords to just ones: () List all just chords with between 2 and k notes (inclusive) whose component dyads fall within odd-limit n. () Pair each just chord with its tuning in 12-tet, using the tempered approximation with the lowest RMS error for chords over which 12-tet is not consistent. () For some k and n, 12-tet will not be unique -- tempered chords will approximate more than one just chord. Sorting by the 12-tet side of the table, rank the just versions of each 12-tet chord by the inverse of their odd-limit if r=1; RMS deviation from 12-tet if r=2; the product of these if r=3. Keep only the c highest-ranking just chords for each 12-tet chord. *The Event Database* Create a utility that takes General MIDI files as input and uses note on/off and (as runtime options) channel amplitude, note velocity, and patch decay information to create a database of sound events, which keys each note-on in the input file to a frequency (assuming 12-tet) and loudness value for every tick in the file. Events are flagged "open", "dropped", or "locked" at each tick. Events are open on the tick which carries their note-on, and then locked for all subsequent ticks if p=1. If p=2, they are locked until they receive a note-off; if p=3, until they are not one of the k loudest events. If p=4, events are never locked. If l=1, locked events are simply ignored by the tuning algorithm. If l=2 they are visible to the algorithm, but changes to their frequency values return true without having an effect. [See below for a discussion of dropped events.] *The Note History Database* Keys each 12-tet degree to a frequency, updated once for each tick in the event database. After update, values that have not changed are erased if h=1. If h=2, unchanged values are erased only if all notes at the associated 12-tet degree are off; if h=3, only if they are silent. If h=4, values are never erased. Higher h should reduce melodic distortion in the adaptive tuning. *The Adaptive Tuning Algorithm* Step through the event database. At each tick, consider the currently- sounding events a chord... () If there are dropped events at the current tick... () If the lowest dropped event is adjacent (in octave-specific pitch space) to exactly one tuned event, tune the pair of events as a chord using a lookup table with k=2 n=5 r=1 c=1, rooting to the frequency of the tuned event. Restart at the current tick. () Else, if d=1, tune the dropped event with its lower neighbor as above. If d=2, use both neighboring events and a lookup table with k=3 n=17 r=1 c=3, rooting so only the frequency of the dropped event may change. Restart at the current tick. () If the chord is found in the consonance lookup table... () If the note history is empty, tune the current chord to its highest-ranking just version, root it on the lowest frequency at that tick in the event database, adjust its other frequencies in the event database, update the note history, and step to the next tick. () Else, if any notes in the current chord have values in the note history, tune the chord to the just version that allows the greatest number of these to remain unchanged (common-tone matching), using the highest-ranking version in case of a tie. If this does not uniquely specify the root of the new chord, root to the lowest note that preserves the match if a=1; the highest if a=2; the loudest if a=3. If a=4, minimize the RMS shift of all matched notes. Update the history and step to the next tick. () Else, apply the 12-tet intervals between the notes of current chord and the ones at the previous tick to the frequencies at the previous tick (from the event database). Copy the resulting frequencies into the note history under the names of the notes of the current chord and restart at the current tick. This treats the 12-tet motion as ideal by using it to 'tare' the last chord into a set of artificial common tones. () Else, the chord is not found in the lookup table... () If f=1 and there is a point in octave-specific space which divides the current events into two chords that are both in the lookup table, select from all such points the one cutting the widest dyad and run the algorithm for each of the two resulting chords, in sequence, lower first. Step to the next tick. () Else, drop events until the remaining chord is found in the table. Drop events by least loudness if s=1, by exclusion from the largest found chord if s=2, or by exclusion from the largest found chord containing the lowest note if s=3. Restart at the current tick. ________________________________________________________________________ ~ Carl Lumma Berkeley, California.