<<

Karolin Stange,∗ Christoph Wick,† Playing in Just and Haye Hinrichsen∗∗ ∗Hochschule fur¨ Musik, Intonation: Dynamically Hofstallstraße 6-8, 97070 Wurzburg,¨ Germany Adaptive Tuning Scheme †Fakultat¨ fur¨ Mathematik und Informatik ∗∗Fakultat¨ fur¨ Physik und Astronomie †∗∗Universitat¨ Wurzburg¨ Am Hubland, Campus Sud,¨ 97074 Wurzburg,¨ Germany Web: www.just-intonation.org [email protected] [email protected] [email protected]

Abstract: We investigate a dynamically adaptive tuning scheme for microtonal tuning of musical instruments, allowing the performer to play music in in any . Unlike other methods, which are based on a procedural analysis of the chordal structure, our tuning scheme continually solves a system of linear equations, rather than relying on sequences of conditional if-then clauses. In complex situations, where not all intervals of a chord can be tuned according to the of just intonation, the method automatically yields a tempered compromise. We outline the implementation of the algorithm in an open-source software project that we have provided to demonstrate the feasibility of the tuning method.

The first attempts to mathematically characterize is particularly pronounced if m and n are small. musical intervals date back to , who Examples include the perfect (m:n = 2:1), noted that the consonance of two tones played on the (3:2), and the (4:3). a can be related to simple Larger values of mand n tend to correspond to more of the corresponding string lengths (for a general dissonant intervals. If a normally consonant interval introduction see, .., Geller 1997; White and White is sufficiently detuned from just intonation (i.e., the 2014). Physically, this phenomenon is caused by simple frequency ), the resulting mismatch of the circumstance that oscillators such as strings almost-coinciding partials leads to a superposition of emit not only their but also waves with slightly different (Helmholtz a whole series of partials at multiples of 1877). The fast beating of these partials, which do the fundamental frequency. Consonance is related not quite coincide, can result in a sensation of to the matching of higher partials, i.e., two tones roughness, or of being out of tune, that ruins the with fundamental frequencies and f  tend to perception of consonance. be perceived as consonant if the m-th partial of With the historical development of fretted in- the first matches the n-th partial of the second. struments and keyboards, it made sense to define a In other words, mf = nf  (see Figure 1). Although system of fixed frequencies in a pattern of repeating the perception of consonance is a highly complex . The frequency ratios of stacked intervals psychoacoustic phenomenon (see, e.g., McDermott, multiply. (For example, the chord A2–E3–B3, con- Lehr, and Oxenham 2010; Stolzenburg 2015) that sisting of two perfect fifths each having the ratio also depends on the specific context (Parncutt and 3:2, yields a frequency ratio of 9:4 from A2 to B3.) Hair 2011; Milne, Laney, and Sharp 2015), one can This immediately confronts us with the fundamen- basically assume that the impression of consonance tal mathematical problem that multiplication and prime numbers are incommensurate in the sense Computer Music Journal, 42:3, pp. 47–62, Fall 2018 that powers of prime numbers never yield other doi:10.1162/COMJ a 00478 simple prime numbers. For example, it is impossible  2018 Massachusetts Institute of Technology. to match k just perfect fifths with just octaves

Stange et al. 47

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Figure 1. Consonance of a Helmholtz (1877), the fifth just perfect fifth. The figure is perceived as consonant shows a measured power because many partials of spectrum of the keys the corresponding natural A2 (110 Hz) and E3 series coincide (165 Hz). As first theorized (marked by the arrows in by Hermann von the figure).

because (3/2)k = (2/1) for all k, ∈ N. Mathemati- keyboard). This means that music can be played in cally speaking, the concatenation of just musical any key, differing only in the global pitch but not in intervals (by multiplying their frequency ratios) is harmonic texture. an operation that does not close up on any finite set This high degree of can, however, of tones per octave. only be established at the expense of Fortunately, the does approximate (cf. Duffin 2008). In fact, the only just interval a closure, with only a small mismatch: When in ET is the octave, with the frequency ratio 2:1, stacking twelve just fifths on top of each other, whereas all other intervals are characterized by the resulting frequency ratio (3/2)12:1 differs from irrational frequency ratios, deviating from the just that of seven octaves (ratio 27:1) by only a small intervals. For some intervals the variation is quite amount, explaining why the Western chromatic small and hardly audible. For example, the equally is based on twelve per octave. The tempered fifth differs from the just perfect fifth remaining difference of approximately 1.4 percent by only two cents. For other intervals, however, (23.46 cents), known as the ,is the deviations are clearly audible, possibly even nevertheless clearly audible and cannot be neglected disturbing. For example, the minor in ET is in a scale with fixed frequencies. Likewise, a almost 16 cents smaller than the natural frequency sequence of four just perfect fifths transposed back ratio 6:5. The same applies to the , which down by two octaves ((3/2)4/22) differs from a major is about 14 cents greater than the ratio 5:4. These third of 5:4 by the so-called of discrepancies may explain why there was some 21.51 cents. reluctance among many musicians to accept ET. It Because it is impossible to construct a musical was not until the 19th century that ET became a scale that is based exclusively on pure beatless new tuning standard, presumably both because of intervals, one has to seek suitable compromises. Western music’s increasingly complex Over the centuries this has led to a fascinating and because of an increasing intonational tolerance variety of tuning systems, called temperaments, on the part of the audience. that reflect the harmonic texture of the music in the epochs in which they were developed (see, e.g., Barbour 2004). With the increasing demand of Just Intonation flexibility, (ET) finally prevailed in the 19th century and has established itself Although musical temperaments provided a good as a standard temperament of Western music. solution for most purposes, music theorists and In ET, the octave is divided into twelve equally instrument makers have searched for centuries sized semitones with the constant frequency ratio for possible ways to overcome the shortcomings 1:21/12. The homogeneous geometric structure of ET of temperaments, aiming to play music solely on ensures that all interval sizes are invariant under the basis of pure intervals (see, e.g., Duffin 2006). transposition (i.e., horizontal displacement on the This is referred to as just intonation (JI). Tuning an

48 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Table 1. Five-Limit Tuning

semitones 0 1 2 3 4 5 6 7 8 9 10 11

f : f ∗ 1:1 16:15 9:8 6:5 5:4 4:3 45:32 3:2 8:5 5:3 9:5 15:8 Five-limit tuning is the most common choice of frequency ratios in just intonation. The tuning gets its name from the fact that all terms in the ratios have prime factorizations using no primes larger than 5.

instrument in just intonation means adjusting the where all tones are tuned statically in advance. twelve pitches of the octave such that all frequency In comparison, many other instruments (such as ratios are given by simple rational numbers with strings) allow the musician to recalibrate pitch respect to a certain reference frequency f ∗. For during performance, and the same applies, of course, example, a possible choice of such frequency ratios to the . Musicians playing such in- is listed in Table 1. struments tune the pitches dynamically while the Just intonation always refers to the tonic of a music is being played. By listening to the harmonic given scale, referred to in this article as the keynote. consonance and its progression, well-trained musi- In its own reference scale, JI sounds very consonant, cians are able to estimate the appropriate frequency possibly even sterile, but a transposition to other intuitively and to correct their own pitch instanta- scales is, unfortunately, not possible. For example, neously. As pointed out by Duffin (2006), the notes tuning a piano in just intonation with keynote C, played are a compromise between just intervals a C-major triad sounds consonant, whereas most and the prevailing ET. By dynamically adapting the triads in other keys sound out of tune. The same pitches, performers can significantly improve the applies to modulations from one key to another. harmonic texture. It is in this context that we quote Thus, just intonation has the reputation of being the cellist Pablo Casals (taken from Applebaum and impractical, for good reason. Applebaum 1972), To overcome this problem, a possible solu- tion would be to increase the number of tones Don’t be scared if your intonation differs from per octave. Important historical examples are, that of the piano. It is the piano that is out of for example, a keyboard with 19 keys per oc- tune. The piano with its tempered scale is a tave, suggested by the Renaissance music theo- compromise in intonation. rist Gioseffo Zarlino (1558), and the two-manual archichembalo with 36 keys per octave by Nicola Vincento (for a demonstration see, for instance, Dynamically Adaptive Tuning Schemes https://youtu.be/0akGtDPVRxk). More recent ex- amples include the Bosanquet organ with 48 keys per Is it possible to mimic the process of dynamic ocatave (see Helmholtz 1877), a harmonium with 72 tuning by constructing a device that instantaneously keys per octave by Arthur von Oettingen (1917), and calculates and corrects pitch, like a singer in a choir? the 31-tone Fokker organ (cf. www.huygens-fokker This idea can be traced back to the early days of .org/instruments/fokkerorgan.html). Today, various electronic keyboard instruments. Since then various types of electronic microtonal interfaces are avail- implementations have been suggested, the most able (see Keislar 1987; MacRitchie and Milne 2017). important ones including Groven.Max, Justonic As one can imagine, however, such instruments are Pitch Palette, Mutabor, Hermode Tuning, and difficult to play. TransFormSynth, which we now describe. Temperaments are primarily relevant for key- One of the first pioneers of dynamic tuning board instruments (e.g., piano, , or schemes was the Norwegian microtonal composer organ) and fretted instruments (e.g., lute or ), and music theorist Eivind Groven (cf. Code 2002,

Stange et al. 49

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 see also http://wmich.edu/mus-theo/groven). In knowledge, it is the only adaptive tuning scheme 1936 he constructed a driven by an that has reached a wider dissemination, ranging electric circuit of relays used in the telephone from implementations in church organs to plug- switchboards of the day. The organ had three sets of ins for software packages such as Cubase. Instead pipes differing by a syntonic comma. Playing a chord of determining the chordal root, the algorithm on the manual, the electromechanical logic circuit instantly tunes intervals between the vertically computed the optimal of the chord and adjacent tones of a given chord to just ratios. triggered the pipes accordingly. In 1995 this method At the same time, the global pitch is adjusted was implemented on a computer, redirecting the such that the difference from the usual ET is output of a MIDI keyboard to three MIDI , minimized. This reduces the disturbing frequency each differing from the next in pitch by a syntonic shifts between subsequent chords. Hermode tuning comma. also attempts to compensate for a problem known Justonic Pitch Palette was proprietary software as pitch drift (discussed in further detail later in this produced by the company Justonic Tuning, based on article). a method developed and patented by Gannon and TransFormSynth is a software-based Weyler (1995). This tuning method was dynamic developed by (1994). Unlike other to the extent that the performer could change approaches (including the one presented here), which the keynote frequency f ∗ during performance. are based on the idea of dynamically modifying the The corresponding frequencies were then retrieved fundamental frequencies and, thereby, the whole from a table and sent to a microtonal synthesizer. series of corresponding partials, Sethares proposes The selection of the keynote required additional keeping the fundamental frequencies fixed (e.g., ac- hardware, such as an extra manual. cording to ET). Instead, his algorithm modifies the Mutabor is a microtonal software project initiated frequencies of the higher partials in such a way that by Martin Vogel at the University of Darmstadt, they match. As a result, even though the available at www.math.tu-dresden.de/∼mutabor. spectra are distorted, the synthesized sound tends The first version, referred to as Mutabor I, was nevertheless to be perceived as consonant. (Note that designed as “a system with 171 steps per octave a similar phenomenon occurs in the context of piano for electronic keyboard instruments.” Depending tuning. Because the overtone spectra of stiff steel on the chord being played, the program calculated strings are slightly inharmonic, piano tuners stretch the actual chordal root and tried to tune all fre- the tuning to compensate for these deviations.) As quencies in pure fifths, fourths, and thirds. This far as we can see, this method is restricted to synthe- led to audible frequency shifts between subsequent sizers that allow the overtone spectra to be specified chords, however. From 1987 onwards, Mutabor individually, but it cannot be applied to ordinary mu- II improved this method, aiming to produce us- sical instruments with natural harmonic overtone able software for MIDI devices and to allow the spectra. user to develop individual tuning algorithms. In All these methods, except for the last, are similar a third stage, starting in 2006, Mutabor has now in that they analyze a given chord and then make evolved into a fully fledged microtonal program- decisions about tuning the frequencies. That is, ming language. Nevertheless, for music with greater they are defined in procedural terms. Depending on harmonic complexity, the chordal root is not al- the harmonic context, these decisions can be quite ways detected reliably. To address this problem, complex, with different possible solutions for the Mutabor offers a means for the user to predeter- same situation. mine the succession of keynotes in a separate MIDI In this article we investigate an alternative file. adaptive tuning scheme based on a method that Hermode Tuning is a commercial adaptive tuning was originally proposed by John de Laubenfels (for scheme (Mohrlok and Mohrlok 1995). To our a brief summary see Sethares 2005). Rather than

50 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 making a sequence of conditional if-then decisions, predominantly based on equal temperament with this method continuously solves a system of linear twelve semitones of equal size, defined by equations. As described subsequently, the system − / ET = (k k0) 12 of equations may be viewed as a resistor network fk : fk0 2 ,(1) or as a mechanical network of springs representing interval sizes. Roughly speaking, each spring prefers where k0 denotes the index of the reference key and to relax into a state where its length corresponds fk0 the corresponding reference frequency (usually = to the natural size of a pure interval and it will A4 with fk0 440 Hz).  do so whenever possible, producing a chord in just An interval between two tones k and k is characterized by a frequency ratio fk : fk.InET intonation. If the spring network is so complex that  ET/ ET = (k −k)/12 it is impossible for all springs to simultaneously this ratio is given by fk fk 2 .Themain be situated in their tension-free state, the system advantage of ET is that this ratio depends only on  will approach a nontrivial state under tension, the difference k − k, meaning that the frequency representing a tempered harmonic compromise. ratios are invariant under transpositions (that is, a This happens automatically, without making any key change maps k to k+ const). Therefore, apart explicit conditional decisions and may resemble from the global tonic pitch, ET sounds identical in the way in which musicians find the best possible all keys. intonation. As an additional advantage, the method finds a harmonic compromise for all intervals in a given chord, not only for the intervals between Consonance and Just Intonation adjacent tones. To demonstrate the technical feasibility of Two tones are in just intonation if the corresponding this dynamically adaptive tuning scheme, we frequency ratio fk : fk is given by a simple rational implemented the algorithm in an open-source number R = m/n. For example, a just octave has application available for various platforms, including the frequency ratio 2:1, and the just perfect fifth mobile devices. This software will be described in corresponds to the ratio 3:2 (see Table 2). As outlined more detail at the end of this article. in the introduction, the impression of consonance is particularly pronounced if mand n are small. Just intonation (JI) is a tuning scheme where Definitions and Notation the frequencies fk are tuned according to rational numbers with respect to a given keynote k∗ in a We start with basic definition and notation that will pattern repeating at the octave: be used throughout this article. JI = JI JI . fk Rk,k∗ fk∗ (2)

JI Frequencies and Equal Temperament A possible choice of the rational numbers Rk,k∗ is given in Table 2. The resulting interval ratios JI JI In the following we consider a standard chromatic fk : fk∗ are, with respect to the keynote, exactly keyboard with keys enumerated from left to right those listed in the table. In contrast to ET, however, with the index k ∈{0, ..., K − 1}. For example, in these frequency ratios are not invariant under the MIDI standard, k runs from 0 to 127 with transpositions. For example, for keynote C the fifth the reference key A4 located at k0 = 69. For tra- C–G has the correct frequency ratio 3:2 but the fifth ditional keyboard instruments, the corresponding –A has the ratio 40:27  1.48, which is clearly too frequencies f0, ..., fN−1 are constant throughout the small. Therefore, as outlined in the introduction, performance, meaning that they have to be tuned JI as a static tuning can only be used in the scale beforehand according to a certain temperament. referring to its keynote (and a few complementary As noted earlier, contemporary Western music is keys), sounding dissonant in most other keys.

Stange et al. 51

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Table 2. List of Chromatic Interval Sizes

 − ET/ ET JI = JI ET φ JI k k Interval fk fk Rk,k m:n k,k [cents] k,k [cents] Deviation k,k [cents] 0 1 1:1 0 0 0 1 1.0595 16:15 111.73 100 +11.73 2 1.1225 9:8 203.91 200 +3.91 3 1.1892 6:5 315.64 300 +15.64 4 Major third 1.2599 5:4 386.31 400 −13.69 5 Fourth 1.3348 4:3 498.04 500 −1.96 6 1.4142 45:32 590.22 600 −9.78 7 Fifth 1.4983 3:2 701.96 700 +1.96 8 1.5874 8:5 813.69 800 +13.69 9 1.6818 5:3 884.36 900 −15.64 10 1.7818 9:5 1017.60 1000 +17.60 11 1.8878 15:8 1088.27 1100 −11.73 12 Octave 2 2:1 1200 1200 0  − ET ET The table shows the number of semitones k k, the frequency ratio fk : fk in equal temperament (ET), the JI = /  just ratios Rk,k m n according to Table 1, the interval sizes k,k in cents for just intonation (JI) and ET, as φ JI well as the cent difference k,k between the two values. Note that the choice of m:n for a given interval is not always unique. For example, the minor seventh can be tuned to the ratios 9:5 or 7:4 (shown later in Table 3).

Logarithmic Pitches and Interval Sizes For the actual pitch deviation of the key k relative to ET we use the notation As noted in the introduction, when two or more musical intervals are combined, the ratio of the ET λk := k −  . (5) resulting interval is the product by multiplication k of the individual component intervals. Therefore, as The microtonal absolute interval size k,k already pointed out by Christian Huygens (1691; see  also Cohen 1984), it is convenient to work with the between two keys k and k is defined as the corre- logarithms of frequency ratios, quantified in units of sponding pitch difference in units of cents: cents. The logarithm transforms multiplication into  =   −  =  − . addition and allows one to add the sizes of adjacent k,k k k 1200 (log2 fk log2 fk) (6) intervals. Using this convention, we define pitches and interval sizes as follows. In ET (Equation 1) the interval sizes are given by the  The k of the key k on the number of semitones times 100: keyboard is defined as the cent difference between the frequency of the key k and that of the reference ET ET ET   =   −  = 100(k − k). (7) key k0 (A4): k,k k k fk  := 1200 log = 1200 (log f − log f ) ,(3) For the actual interval size deviation from ET we k 2 f 2 k 2 k0 k0 use the notation = / where log2 f log f log 2 denotes the logarithm φ  =  − ET = λ  − λ . to the base 2. For example, the pitches in ET k,k : k,k k,k k k (8) (Equation 1) are simply given by multiples of 100 cents: JI φJI For JI a list of possible values for k,k and k,k is ET = − . k 100(k k0) (4) given in Table 2.

52 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Figure 2. Simplified a battery in series with to Kirchhoff’s laws, choice of the resistors sketch of the vertical a resistor between each where the voltages at the determines a tempered tuning scheme proposed of the 4 × 3/2 = 6 possible key contacts represent the compromise where the in this article. The intervals. Assuming that desired microtonal pitches. dissipated power measures figure shows a keyboard each battery has a voltage If all electrical currents how much the chord on which a C-major equal to the ideal pitch in the network vanish (as is tempered. The system chord is played. Viewing difference JI in JI, the in the present example), is coupled to an external ki,kj these keys as electrical resistor network will attain the chord is tuned exactly voltage that controls contacts we place an equilibrium according in JI. If not, the specific the reference pitch.

the ideal ratios of JI. In other words, for a chord consisting of N tones according to the keyboard keys { ... } { ...  } k1, k2, , kN we have to find pitches k1 , , kN such that the interval sizes ki ,kj agree as much as possible with the values JI listed in Table 2. ki ,kj Most of the existing approaches mentioned in the introduction consider only the intervals between adjacent tones of a chord. In contrast, our method also takes intervals between nonadjacent tones into account, putting them on an equal footing with adjacent intervals. This means that, for a chord consisting of N tones, there are N(N − 1)/2 intervals that have to be tuned as close to just intonation as possible. As there are N(N − 1)/2 intervals but only N degrees of freedom, it is clear that it is not always possible to find a consistent solution where all interval sizes ki ,kj exactly match the given cent differences JI . For example, the triad C-E-G can ki ,kj be tuned in just intonation (with ratios C–E = 5:4, E–G = 6:5, and C–G = 5:4 × 6:5 = 3:2) although the triad C–E–G cannot (because the combination of two major thirds results in the frequency ratio / 2 = / Vertical Intonation: Adaptive Tuning (5 4) (20 16), which differs from the ratio 8:5 listed in Table 2). In such a situation, where a chord of a Single Chord cannot be tuned consistently in just intonation, the algorithm should render an acceptable tempered Adaptive tuning schemes are confronted with two compromise. In fact, this is basically what musicians important aspects of tuning. On the one hand, do: They do not solve complicated mathematical each new chord has to be in tune “vertically,” that calculations, they simply adjust their own pitch is, one has to tune the relative pitches between on an intuitive basis such that the best possible simultaneously played notes. On the other hand, harmonic compromise is achieved. subsequent chords have to be intoned relative to The solution investigated here is based on a each other in the “horizontal” (temporal) direction simple idea that can be explained as follows. As according to the harmonic progression, as will be sketched in Figure 2, we consider a fictitious discussed later in the section “Vertical Intonation: battery-resistor network, where each battery has a Adaptive Tuning of a Single Chord.” voltage corresponding to the ideal pitch difference JI of JI, as listed in the table. If the chord can be ki ,kj tuned in JI (e.g., as a major triad), the voltages will Vertical Tuning at First Glance adjust exactly at the corresponding pitches and the currents passing the resistors are zero. Otherwise, To tune a given chord vertically, we want to for chords that cannot be tuned exactly in JI, the determine the pitches such that the resulting network will produce a compromise that depends on interval sizes are equal to, or at least close to, the specific choice of the resistors. As pointed out

Stange et al. 53

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 previously, the dissipated power can be regarded as and where a measure of how strongly this tuning compromise 1 is tempered. c = w φ2 (12) 4 ij ij i, j

Mathematical Formulation is a constant. The optimal pitches λ opt,whichwe would like to use to tune the chord, correspond to    Consider a chord of N tones with key indices a situation where V[λ] is minimal, that is, ∇λV = 0, ...   k1, k2, , kN in increasing order. The chord consists leading to the system of equations Aλ + = 0. Thus, of N(N − 1)/2 intervals with index pairs i, j ∈ if A was invertible, the solution would be given by {k1, ..., kN} ordered by i < j. The task would be to  opt −1  tune the pitches i (with i ∈{k1, ..., kN})insucha λ =−A b. (13) way that the pitch differences  j − i deviate as little as possible from the ideal pitch differences Thus, the whole tuning process amounts to solving JI listed in Table 2, or equivalently, that the a system of linear equations. Finally, the potential ki ,kj differences λ j − λi deviate as little as possible from JI JI 1 φ := φ . We solve this problem by minimizing V[λ opt] = c − b · A−1b (14) i, j ki ,kj 2 the squared deviations as follows. Denoting the vector of pitch deviations from ET of the pressed evaluated at λ = λ opt gives the dissipated power, keys by λ = (λ , ..., λ )T, we define a deviation k1 kN telling us to what extent the result is tempered. potential by Inspecting A, however, one can easily see that 1 2 the column sum is zero, hence the matrix does λ = w λ − λ − φJI V[ ] ij j(t) i(t) ij ,(9)not have full rank and thus is not invertible. This 4 ∈{ ... } i, j k1, ,kN i< j can be traced back to the fact that the potential is defined in pitch differences, leaving the absolute which is just the sum of all quadratic deviations of pitch of the chord undetermined. This can be the interval sizes weighted by factors wij, assuming easily circumvented by coupling the network to an that wii = 0. The weights can be chosen freely and external source that determines the global concert can be viewed as the conductivity of the resistors in pitch, as described in Appendix A. Figure 2. Their purpose is to determine the “rigidity” of the respective intervals in the tuning process. In practice it is meaningful to assign a high weight Horizontal Intonation: Adaptive Tuning factor to intervals with simple fractional ratios. In in Harmonic Progression addition, the weight factors may also take the actual volume of the notes played into account. We perceive combinations of tones as “in tune” or The deviation potential (Equation 9) can be “out of tune” if they are played simultaneously, but written more compactly in the bilinear form we are also aware of the intonation of sequentially 1 played tones, as long as the intervening time V[λ] = λ · Aλ + b · λ + c, (10) 2 between successive pitches is not too long (see, e.g., Milne, Laney, and Sharp 2016). It is apparent that our  where A is a symmetric N × N matrix and b is a sense of hearing is able to memorize sounds and their vector with the components spectra for short periods of time. In empirical studies ⎧ it was found that this psychoacoustic intonational ⎪ −w if i = j ⎨ ij short-term memory is characterized by a typical = = w φ Aij , bi ij ij (11) time scale of about 3 seconds (Wittmann and Poppel¨ ⎩⎪ wi if i = j j 1999; Lehmann and Goldhahn 2016).

54 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 If the chords are tuned separately, as described Among musicians, the typical value of τR is ex- in the previous section, the sudden change of the pected to be smaller than τM, and it seems that chordal root may lead to unpleasant intonational values in the vicinity of 1 second are a reasonable discontinuities between chords. This requires that choice. intonational memory has to be taken into account by correlating the pitches of subsequent chords in a harmonic progression. In the following we Horizontal Adaptive Tuning describe how intonational memory can be incor- porated into the proposed framework of adaptive To correlate the intonation of subsequent chords, tuning. we use the same mechanism as described above for the case of vertical tuning. To this end, consider a memorized key with the index km that was tuned Intonational Memory to the pitch ˜ m, followed by a newly pressed key with the index ki (including the case that the same Pressing a key k, the instrument produces a sound key is pressed again). The aim is to tune the pitch with time-dependent intensity (volume) Ik(t), which i(t) dynamically in such a way that the interval decays to zero when the key is released. To imple- size ˜ m − i(t) approximates as much as possible ment intonational memory, we introduce a memory the ideal interval size JI of JI, as listed in Table ki ,km function Mk(t), interpreted as the “virtual intensity” 2. In other words, we have to determine λ in such a at which the sound of a key k is memorized. When way that λ˜ m − λi(t) deviates as little as possible from a new key is pressed, Mk(t) is initially set to the φJI := φJI . This leads to simply adding a memory im ki ,km actual intensity Ik(t). Thereafter, it follows I(t)by term to the potential means of the over-damped first-order differential equation 1 2 V[λ] = w (t) λ (t) − λ (t) − φJI 4 ij j i ij i, j dMk(t) = 1 − (Ik(t) Mk(t)) , (15) dt τM 1 2 + w˜ (t) λ˜ − λ (t) − φJI , (17) 2 im m i im i m where τM ≈ 3 sec is the characteristic time scale of intonational memory. For example, if the volume of k k i j ∈{ ... N} a key drops suddenly to zero after releasing a key, where i, j (with , 1, , ) run over all audible − /τ keys while k (with m∈{1, ..., M}) runs over the M(t) will decrease exponentially as e t m. m w t This simple model of intonational memory can memorized keys. Here ˜ im( ) is a time-dependent be improved further by observing that it also takes weight factor reflecting the actual intensity of the k k some time to recognize the pitch of a newly pressed key i and the memorized intensity of the key m. key. In fact, it is quite easy to memorize the pitches Again, this potential can be written in the vector of long sustained notes, while individual short notes notation of Equation 10 with in a fast tempo are much harder to remember. This ⎧ ⎪ −w if i = j suggests that there is another typical time scale ⎨ ij = τR for recognizing the pitch of a sound that can be Aij w + w = (18) ⎩⎪ i ˜ im if i j taken into account by considering the dynamics m ⎧ ⎪ 1 bi = wij φij + w˜ im(φim − λ˜ m) (19) ⎪ I t − M t M t < I t ⎨ ( k( ) k( )) if k( ) k( ) j m τR dMk(t) = . ⎪ (16) 1 1 dt ⎪ = w φ2 + w φ − λ˜ 2 ⎩⎪ 1 c ij ij ˜ im( im m) (20) (Ik(t) − Mk(t)) if Mk(t) ≥ Ik(t) 4 2 τM i, j i m

Stange et al. 55

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 and its minimum is attained at λ opt =−A−1b.Note takes place immediately after pressing a new key, that this method automatically finds a tempered the time scale for the pitch compensation is much compromise if the chordal roots of a harmonic larger and should be chosen such that the gradual progression are incompatible. compensation is not noticeable for the listener.

Compensating for Pitch Drift Dealing with Nonunique Interval Sizes One of the major disadvantages of dynamic tuning schemes with temporal correlation is the gradual The method outlined so far determines the best migration of the overall pitch. For example, playing possible tuning result for a fixed table of interval a full of twelve semitones with sizes (see Table 2). The frequency ratios in JI are not JI unique, however. There are various possible choices fixed sizes k,k+1=111.73 cents (frequency ratio 16:15) one ends up with 1340.76 cents, which for certain intervals, defining different variants of is more than a semitone higher than an octave. just intonation (see Table 3). This suggests that the In practice, pitch drift meanders in both positive tuning result can be improved by finding the best and negative directions, depending on the actual possible solution among these variants. harmonic progression. The advantage of admitting several variants Pitch drift can be reduced by admitting different can be explained by the following example. Two interval sizes, as will be discussed in the next successive major seconds with the ratio of 9:8 (+3.9 section, “Dealing with Nonunique Interval Sizes.” cents) make up a major third with the ratio of For example, twelve semitones with alternating 81:64 (+7.8 cents), which differs significantly from sizes of 111.73 cents (16:15) and 92.18 cents (135:128) the just ratio of 5:4 (−13.7 cents). If we combine form six whole tones of 203.91 cents (9:8) each, and two different JI variants of major seconds with the add up to 1223.46 cents, which is much closer to a ratios of 9:8 (+3.9 cents) and 10:9 (−17.6 cents), just octave of 1200 cents. But even this improvement however, the resulting major third has exactly the does not eliminate pitch drift entirely. just frequency ratio of 5:4 (−13.7 cents). It is therefore meaningful to implement an What determines the correct choice of the additional mechanism that compensates for size? In a procedural setting, this is a highly drift by slowly adjusting all pitches uniformly such complex problem in that requires that the desired reference pitch is approximated, as a thorough analysis of the harmonic progression. described by the differential equation In practice, however, the decision for the best ⎛⎛ ⎞ ⎞ fitting interval is made aurally on an intuitive dλ 1 1 basis (although a general understanding of the j = ⎝⎝ λ ⎠ − λref⎠ j ∈{k ... k }. τ i , 1, , N harmonic progression is part of the process). Inspired dt c N ∈{ ... } i k1, ,kN by this observation, we implement nonunique (21) interval sizes in the algorithm described above by repeating the minimization procedure for all λref = · / Here 1200 log2( fk0 440 Hz) is the global pitch possible combinations of the alternative interval with respect to 440 Hz, and τc defines the typical sizes listed in Table 3 and then taking the solution time scale on which the compensation takes place. that has the lowest deviation from JI. Note that the pitch drift affects the frequencies of all The four alternative ratios listed in Table 3 have pressed keys equally without changing the relative been chosen empirically. There are, of course, many frequency ratios between them. This means that the more possible ratios that could be added. Because we harmonic texture of the sound remains the same, minimize over all possible combinations of interval only the overall pitch varies slowly with time. In sizes, however, it is clear that execution time grows contrast to the vertical and horizontal tuning, which exponentially with the number of alternative ratios.

56 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Table 3. Alternative Frequency Ratios for Just Chromatic Intervals

 − φ JI k k Interval Name Alternative Tunings p:q ( k,k [cent ]) 0 Unison 1:1 (0) 1 Semitone 16:15 (+11.73) 25:24 (−29.32) 2 Major second 9:8 (+3.91) 10:9 (−17.60) 3 Minor third 6:5 (+15.64) 4 Major third 5:4 (−13.69) 5 Fourth 4:3 (−1.96) 6 Tritone 45:32 (−9.78) 7 Fifth 3:2 (+1.96) 8 Minor sixth 8:5 (+13.69) 9 Major sixth 5:3 (−15.64) 10 Minor seventh 16:9 (−3.91) 9:5 (+17.60) 7:4 (−31.17) 11 Major seventh 15:8 (−11.73) 12 Octave 2:1 (0) The third column uses the same ratios as Table 2. Additionally, the most important alternative tuning ratios are shown.

This is the reason the table is restricted to only four with each other via Qt signals. MIDI messages alternative entries for the most flexible intervals. generated by an integrated player or an external device are sent to the tuning module and to the sound-generating modules. Depending on the MIDI Open-Source Demonstration Software data, the tuning module continually computes the vector λ opt according to the formulas given To demonstrate the tuning method discussed in previously and emits the calculated pitches via this article, we initiated an open-source project Qt signals to the audio modules. The application called Just Intonation (this article refers to version includes a built-in microtonal sampler that can 1.3.2 of the software, available at https://gitlab play triangular waves as well as realistic samples .com/tp3/JustIntonation). This software allows the (piano, organ, and harpsichord) recorded by the user to hear and play music with and without authors. As the application is designed primarily adaptive tuning. Audio examples, a short video for educational purposes, there is no particular and download links for various platforms are emphasis on low-latency audio. available at www.mitpressjournals.org/doi/suppl Alternatively, it is possible to connect an external /10.1162/COMJ a 00478. MIDI device that is capable of processing pitch-bend The application has been designed as an educa- messages. Normally, the MIDI pitch-bend message tional application rather than a professional tool modifies the frequencies of all depressed keys uni- for producing music. It provides a “simple” mode formly. To circumvent this restriction, the MIDI for getting started as well as an “expert” mode for output module remaps the incoming MIDI stream more sophisticated experiments (see the screenshot to 15 different channels, tuning each of them indi- in Figure 3). vidually using pitch bend. Note that this restricts Just Intonation is a multiplatform application the output to a 15-voice polyphony of a single for desktop computers and mobile devices, written instrument. It should be mentioned at this point in C++ and based on Qt (www.qt.io). As sketched that the MIDI standard has recently been extended. in Figure 4, it contains various submodules that This new standard, called MIDI Polyphonic Expres- run partially in different threads and communicate sion, overcomes the aforementioned limitations and

Stange et al. 57

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Figure 3. Screenshot of the Figure 4. Basic structure of application Just the Just Intonation Intonation, version 1.3.2, application and its while being used in expert modules. mode.

Figure 3

Figure 4

allows for direct microtonal control of the individual Its internal structure is shown in Figure 5. Its main pitches (for details, see www..org/articles/midi functionality is: (1) receiving MIDI signals and -polyphonic-expression-mpe). sending tuning signals, (2) emulating the intensity The main module of interest is the tuning module. I(t) as well as the memory M(t) for each key This module runs entirely in a separate event loop of of the keyboard, (3) keeping track of key status an independent thread and communicates with the (including MIDI note on and note off, volume, application via Qt signals, ensuring thread safety. and basic envelope) in an array of type KeyData,

58 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Figure 5. Internal structure of the tuner module.

(4) executing the TunerAlgorithm every 20 msec become accepted on a broader scale, however. By or upon incoming MIDI events, and (5) managing the early 20th century, interest in just intonation compensation for pitch drift. abated, probably in part because many composers For further technical details, code excerpts, and were writing music that was highly dissonant and a link to full code documentation, the interested even atonal. reader is referred to Appendix B. In the second half of the 20th century, a renewed interest in just intonation and different ways of tuning arose alongside an increasing attention to Outlook historical performance practices (see Duffin 2006). The new technologies becoming available con- The development of temperaments and the ongoing, stituted another factor stimulating this process. century-long tug-of-war between just intonation, on Following the visionary contributions by Eivind the one hand, and a desire for the ability to freely Groven (cf. Code 2002), the emerging computer transpose and modulate to different keys, on the technology led to a variety of proposals, patents, and other, is a fascinating facet of the history of music software packages reflecting the technological capa- theory and practice. At the beginning of the 20th bilities of the respective time. Unfortunately, apart century it seemed as if the universal acceptance from a few exceptions, none of these approaches of ET had finally settled this issue and, in fact, reached a broader dissemination, partly because the this is the prevailing view of our time. In contrast, whole issue retained a reputation for being exotic we share the opinion that the quest for better and academic, and it was linked to the microtonal intonation is not yet over and that ET is probably community, where twelve tones per octave are only an intermediate rather than a final solution. considered as an exception rather than the rule. Looking back at the past 150 years, it seems that In the meantime, an ordinary mobile phone has the search for better intonation oscillates between become more powerful than a supercomputer of enthusiasm and disillusionment. For example, the 1980s, offering new and previously undreamed- starting with the seminal work in 1863 by Hermann of possibilities. For example, solving a system of von Helmholtz, who was among the first to provide equations in real time, as proposed in the present a scientific basis for the sensation of musical tones, work, would have been inconceivable two decades many theorists and instrument makers at the end of ago. Moreover, digital information technology the 19th century were inspired by the challenge of continues to change the musical landscape and the constructing a Reininstrument, that is, a keyboard art of instrument-making entirely. The purpose of instrument capable of playing in just intonation. this project is to demonstrate that we now have The solutions were simply too complicated to new means at our disposal to allow us to consider

Stange et al. 59

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 different approaches and to make dynamic tuning References schemes suitable for everyday use. A systematic evaluation of the tuning method is beyond the scope Applebaum, S., and S. Applebaum. 1972. The Way They of this article, but we invite interested readers to Play: Book 1. Neptune City, New Jersey: Paganiniana. form their own subjective conclusions by testing Barbour, J. M. 2004. Tuning and Temperament: A His- our software or by listening to the available sound torical Survey. North Chelmsford, Massachusetts: examples on our Web site www.just-intonation.org. Courier. Finally, electronic communication increasingly Code, D. L. 2002. “Groven.Max: An Adaptive Tuning System for MIDI Pianos.” Computer Music Journal enhances the interaction between different musical 26(2):50–61. cultures. On the one hand, it is obvious that Cohen, H. F. 1984. Quantifying Music: The Science many traditional intonation systems throughout of Music at the First Stage of Scientific Revolution the world are increasingly influenced (not to say 1580–1650. Berlin: Springer. destroyed) by Western ET. On the other hand, it Duffin, R. W. 2006. “Just Intonation in Renaissance The- should not be underestimated that this interaction ory and Practice.” Music Theory Online 12(3). Avail- also influences the Western world, and it cannot be able online at www.mtosmt.org/issues/mto.06.12.3 ruled out that at some point in the future it may /mto.06.12.3.duffin.html. Accessed June 2018. become fashionable to deviate from ET. In addition, Duffin, R. W. 2008. How Equal Temperament Ruined it is to be expected that the art of instrument Harmony (and Why You Should Care).NewYork: making will continue to evolve rapidly and that, Norton. Gannon, J. W., and R. A. Weyler. 1995. Just intonation in the long run, the importance of statically tuned tuning. Canada Patent 2,182,662, filed 10 February temperaments may decrease. All this suggests 1995, and issued 17 August 1995. that a dynamically adaptive tuning scheme might Geller, D. 1997. Praktische Intonationslehre fur¨ Instru- become more important in the future. This does not mentalisten und Sanger:¨ 60 Horbeispiele¨ zum Thema necessarily mean that just intervals are the ultimate Intonation und . Kassel: Barenreiter¨ BKV goal. In fact, it has been shown by Mathews and 1266, compact disc. coworkers (1988) that small deviations from rational Helmholtz, H. 1877. On the Sensations of Tone, trans. A. frequency ratios may certainly be perceived as J. Ellis. New York: Dover. pleasant, but perhaps there will be a growing Huygens, C. 1691. “Lettre touchant le cycle harmonique.” interest in intonation schemes that are more Histoire des Ouvrages de Sc¸avans 6(October):78– consonant. With our contribution, we would like 88. Available online at huygens-fokker.org/docs /lettre.html. Accessed June 2018. to note that there is considerable room for further Keislar, D. 1987. “History and Principles of Mi- research and development in this direction. crotonal Keyboards.” Computer Music Journal 11(1):18–28. Revised 1988 as “History and Prin- ciples of Microtonal Keyboard Design,” Report STAN-M-45, Stanford University. Available online Acknowledgments at ccrma.stanford.edu/STANM/stanms/stanm45. Ac- cessed 17 May 2018. We would like to thank the anonymous reviewers for Lehmann, A. C., and S. Goldhahn. 2016. “Duration their substantial suggestions and, in particular, for of Playing Bursts and Redundancy of Melodic Jazz making us aware of the work by John de Laubenfels. Improvisation in John Coltrane’s ‘Giant Steps.”’ Musicae Scientiae We would also like to thank Ross W. Duffin for the 20(3):345–360. MacRitchie, J., and A. J. Milne. 2017. “Exploring the stimulating exchange of ideas, in particular for his Effects of Pitch Layout on Learning a New Musical suggestion to consider variable interval sizes. We are Instrument.” Applied Sciences 7(12):1218. also grateful to Ulrich Konrad, who made it possible Mathews, M. V., et al. 1988. “Theoretical and Experimen- to record the samples for the application. Finally, tal Explorations of the Bohlen–Pierce Scale.” Journal we would like to thank Adam Whisnant for critical of the Acoustical Society of America 84(4):1214– reading of the manuscript. 1222.

60 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 McDermott,J.H.,A.J.Lehr,andA.J.Oxenham. adding an extra term to the potential (Equation 10): 2010. “Individual Differences Reveal the Basis of N N Consonance.” Current Biology 20(11):1035–1041. 1 2 λ = w λ − λ − φJI + λ − λ 2 Milne, A. J., R. Laney, and D. B. Sharp. 2015. “A Spectral V[ ] ij j(t) i(t) ( i ref) , 4 ij 2 Model of the Probe Tone Data and Scalic i, j=1 i=1 .” Music Perception 32(4):364–393. λ = / Milne, A. J., R. Laney, and D. B. Sharp. 2016. “Testing where ref 1200 log2( fk0 440 Hz) is the deviation a Spectral Model of Tonal Affinity with Microtonal from the reference pitch and wij isasmall Melodies and Inharmonic Spectra.” Musicae Scientiae coupling parameter, replacing Equations 11 and 12 20(4):465–494. by the modified expressions Mohrlok, W., and H. Mohrlok. 1995. Method of and ⎧ control system for automatically correcting a pitch of ⎨⎪ −wij if i = j a . US Patent 5,442,129, filed 14 = Aij + w = January 1993, and issued 15 August 1995. ⎩⎪ i if i j Parncutt, R., and G. Hair. 2011. “Consonance and Disso- nance in Music Theory and Psychology: Disentangling =− λ + w φ Dissonant Dichotomies.” Journal of Interdisciplinary bi ref ij ij Music Studies 5(2):119–166. j ⎛ ⎞ Sethares, W. A. 1994. “Adaptive Tunings for Musical Scales.” Journal of the Acoustical Society of America 1 c = ⎝2N λ2 + w φ2 ⎠ . 96(1):10–18. 4 ref ij ij Sethares, W. A. 2005. “Tuning the Gamelan.” In Tuning, i, j , Spectrum, Scale. Berlin: Springer, pp. 178–182. Stolzenburg, F. 2015. “Harmony Perception by Period- Now the matrix A is invertible and the optimal λ opt =− −1  icity Detection.” Journal of Mathematics and Music pitch differences can be computed by A b. 9(3):215–238. A similar modification can be made if horizontal von Oettingen, A. J. 1917. “Die Grundlage der Musik- tuning is to be taken into account. wissenschaft und das duale Reininstrument.” Ab- handlungen der Mathematisch-Physischen Klasse der Koniglich-S¨ achsischen¨ Gesellschaft der Wis- Appendix B: Technical Details of the senschaften 34(2):155–361. White, H. E., and D. H. White. 2014. Physics and Music: Tuning Module The Science of Musical Sound. North Chelmsford, Massachusetts: Courier. In the source code, which can be downloaded from Wittmann, M., and E. Poppel.¨ 1999. “Temporal Mecha- https://gitlab.com/tp3/JustIntonation, the core of nisms of the Brain as Fundamentals of Communication: the tuning module can be found in the directory With Special Reference to Music Perception and application/modules/tuner. The tuner interface is Performance.” Musicae Scientiae 3(1):13–28. realized as an instance of the class Tuner,whichin Zarlino, G. 1558. Le istituzioni harmoniche. Venice. turn is running an instance of the TunerAlgorithm Available online at imslp.org/wiki/Le Istitutioni in an independent thread. Harmoniche (Zarlino, Gioseffo). Accessed 17 May A greatly shortened excerpt of the main algorithm, 2018. without optimization, is given in Figure 6. As can be seen, the function tuneDynamically is called with three arguments, passing a structure containing the status of all keys (depressed or not), a vector of Appendix A: Controlling Global Pitch the desired interval sizes in cents, and a vector of the corresponding weights (which can be adjusted To solve the problem of noninvertibility we weakly individually in the expert mode of the application). couple the network to the global reference pitch, as The implementation of the tuner algorithm is indicated at the bottom of Figure 2. This amounts to based on the open-source library Eigen, a C++ library

Stange et al. 61

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021 Figure 6. Code excerpt from the tuning module (see text for details).

double TunerAlgorithm::tuneDynamically (KeyDataVector &keyDataVector, const QVector intervals, const QVector weights) { using namespace Eigen;

...

VectorXd pitch(N); VectorXd significance(N);

MatrixXi semitones(N,N); MatrixXi direction(N,N); MatrixXd weight(N,N); MatrixXd interval(N,N);

...

VectorXd diagonal = VectorXd(weight.array().rowwise().sum()); MatrixXd A = -weight.block(0,0,P,P) + MatrixXd::Identity(P,P)*epsilon + MatrixXd(diagonal.head(P).asDiagonal()); VectorXd B = (interval * weight).diagonal().head(P) - epsilon*pitch.head(P); double C = (interval.array() * interval.array() * weight.array()).sum() / 4;

VectorXd U = - A.inverse() * B; double V = C - B.dot(AI*B)/2; }

for linear algebra (see http://eigen.tuxfamily.org), weight — an array containing the tuning weights which is used here to solve the system of linear according to the slider setting in expert mode. equations described above. First, two vectors interval — contains the desired JI interval sizes and four matrices are declared and initialized in cents. as follows (the initialization is not shown in After initializing these objects, we use the Eigen Figure 6): library to set up A, B,andC (see Figure 6) and finally pitch — a vector containing the actual pitches of we solve Equations 18–20. The actual solution of the pressed keys in cents. the problem is carried out in a single line, namely, significance — a vector holding the weight of each pressed key, depending on its volume. VectorXd U = - A.inverse() * B; semitones — a matrix counting the number of For further details, we refer the interested reader semitones between each pair of pressed keys. to the documentation at www.mitpressjournals.org direction — indicates whether the correspond- /doi/suppl/10.1162/COMJ a 00478/documentation.pdf. ing interval is going up or down.

62 Computer Music Journal

Downloaded from http://www.mitpressjournals.org/doi/pdf/10.1162/comj_a_00478 by guest on 27 September 2021