Tuesday, March 26, 2024

Circulation

In yesterday's post I discussed a type of musical instrument that presents a fixed number of keys the player can strike or press etc. to produce pitches. These pitches would be from a section of the chain of fifths. This is a very traditional meantone approach, but it can be generalized to a chain of whatever other interval is of interest. The instruments I described would have some kind of auxiliary control to allow the section to be shifted along the chain. The idea is that by shifting one step along the chain, the pitch of a single key is changed by some relatively small amount, so the pitch order of the keys is not altered. An example of such an instrument is a harp, which has seven strings per octave. Pedals allow the player to sharpen or flatten strings to follow key signature changes.

This only works for sections of suitable length. For example, a section of five pitches along the chain of fifths would be F C G D A. The next pitch on the chain is E. To shift the section along the chain one step, the F must be replace by E. This does not change the pitch order of the keys, so this works.

If one tries to use a section of six pitches, F C G D A E, to move the section one step along the chain of fifths, one would have to replace the F by B. This is a very large change in pitch that severely disrupts the pitch order of the keys of the instrument and so would be be quite unwieldy.

A seven pitch section is again practical. To shift F C G D A E B along the chain of fifths, the F needs to be replaced with F#, which again does not disrupt the pitch order of the keys of the instrument.

Observe that sometimes moving the section up a fifth along the chain involves sharpening the changing pitch, as with the seven pitch section, and sometimes involves flattening the changing pitch, as with the five pitch section.

Which size sections of the chain will preserve the pitch order when shifting along the chain depends on the exact size of the fifth. For the just tuned fifth of Pythagorean tuning, sections of size 7, 12, and 53 shift by sharpening a pitch; sections of size 5, 17, 29, 41, and 94 shift by flattening a pitch. To take 1/5 comma meantone as a contrasting example, sections of size 7, 19, 31, 74, and 117 shift by sharpening a pitch; 5, 12, and 43 shift by flattening a pitch.

These various lengths all correspond to useful ways to divide octaves to form practical tuning systems. The chain of fifths of length n needs to wrap around the octave circle to come back very close to where it started, if shifting the chain is to involve a small pitch change. So n fifths must be very close to m octaves. So m/n needs to be good approximation to the size of the fifth relative to the size of the octave. This means that dividing octaves into n equal parts will provide a good approximation to the fifth, which will be at m steps of this division.

In celebration of the beauty of these mathematical aspects of music, here is an algorithmic composition using a 19 pitch section of the fifths of 43edo: 43edo scale 19.

Monday, March 25, 2024

Shifting along the Chain of Fifths

Musical tuning systems continue to fascinate me. One path of exploration is innovation, to explore fresh territory. Another path is to look at history and to explore the foundations that the present conventions are built on. Meantone is a historically important tuning system that can still offer innovative possibilities.

The conventional 12 tone equal tempered system of today is built on the circle of fifths. The more fundamental meantone system is build on a chain of fifths. Meantone is actually a family of tuning systems. The conventional 12 tone system is just one of these. Some members of the family will close the chain of fifths into circles of different sizes; others will leave the chain unclosed.

More fundamental than the circle of fifths is the circle of octaves. One can start a scale at C, move up through D, E, F, G, A, and B, and then return to C again: a higher C that where the scale started, but the name repeats. It's another C.

The higher C has twice the frequency of the lower C. One C might be at 256 Hz, and the next higher C would be at 512 Hz. Generally, the theory of tuning systems is built on the principle that two pitches will sound consonant together if their frequencies have a simple ratio. 2:1 is about as simple as a ratio can get; that's why pitches an octave apart are so intimately related that we often just ignore their difference. That's what I'll be doing here, largely. I'll just look at pitches within a single octave range.

After 2:1, the next simplest ratio is 3:2. That's the frequency ratio for pitches a perfect fifth apart. That's why the chain of fifths is so important: the chain is like the main highway, the path built by moving from one pitch along to the pitch it is most consonantly related to (again, ignoring octaves).

The picture above shows the conventional names for the pitches along a central section of the chain of fifths. The chain can be extended indefinitely in either direction, just by adding more and more sharp symbols in one direction, or flat symbols in the other. A musical composition generally uses a finite number of pitches, and so will use just a finite section of this infinite chain. Pentatonic music will just use a five pitch section of the chain. A diatonic scale encompasses a seven pitch segment. The note naming convention A, B, C, D, E, F, G is based on the diatonic scale.

Musical compositions can be based on different sections of the chain of fifths, or might be broken into parts that use different sections, or might use more than seven pitches even in a single part. To slide a seven pitch subset up the chain, one adds the next pitch in the direction of motion and removes the trailing pitch. With the seven pitch subset, these two pitches will be nearby. If the chain is built of precise 3:2 perfect fifths, the difference between the new and old pitches will be a ratio of 2187:2048 (folding the octaves together as needed). This small ratio is the basis for the sharp and flat notation: sliding one step down the chain of fifths involves just a small tweak to one pitch of the seven in a diatonic scale.

The tuning system built on a chain of precise 3:2 ratios is called Pythagorean tuning. It runs into trouble. The Pythagorean major third is a ratio of 81:64. This is very close to the simple ratio of 5:4. When two pitches are quite close to a simple ratio like this, but still significantly off that simple ratio, they sound harsh or out of tune.

Meantone tuning is a solution to this problem. The perfect fifths are slightly flattened, in order to reduce the error in the major third. Exactly how much to flatten, that is not fixed. A range of possibilities has been used historically. The conventional 12 tone system is only a little flat, and the error in the major thirds remains significant. The graph above shows the practical range. One can see that, for example, 1/5 comma meantone balances the errors in the perfect fifth and the major third. 2/7 comma meantone balances the errors in the major and minor thirds. These and other choices have been advocated and used historically.

The fundamental problem with meantone tuning is that, in general, it is still working with the infinite chain of fifths. Many musical instruments can only provide a limited choice of pitches to be played. If there are enough choices, composers won't be overly constrained by the requirement that they don't run so far along the chain that they exceed the capacity of the instrument. Another practical possibility is that the size of the perfect fifth is chosen so that the chain is closed into a circle. This is the great virtue of the conventional 12 tone system. 12 pitches per octave is a very practical number. One can wander up and down the chain of fifths, and because it has been closed into a circle, one will never run into a wall. One can use 19 and 31 pitches per octave, along with other choices. The major thirds can be significantly better than those in the conventional 12 tone system, but the extra pitches per octave can be a bit unwieldy.

While conventional piano keyboards have 12 keys per octave, 7 white and 5 black, harpsichords and organs have been built with additional black keys, tucked alongside the conventional 5. Sometimes just one or two black keys are split. The graph above shows the pitches in a range of meantone choices for a fully extended keyboard, where each black key has been split for a total of ten black keys. One can see in this graph that the sharps and flats cross for the 12 tone conventional tuning system. In the exact Pythagorean system C# is higher than Db. For most of the usual meantone choices, such as 1/5 comma meantone, C# is lower than Db.

Another way to manage the chain of fifths, other than walls and circles, is to add shift controls to instruments. Harps are a good example of this approach. A harp has just seven strings per octave, but allows further movement along the chain of fifths by way of pedal controls. Modern electronic instruments could easily support unbounded movement along the chain of fifths. For example, a conventional 12 tone keyboard could work with a full range of the chain of meantone fifths. At any one time, the keyboard would present a range of 12 pitch choices per octave. There would be one "wolf" fifth in the tuning. But a pedal or other control could be provided, to shift the location of this wolf. At one time the keyboard might provide a range along the chain from Eb to G#. If the music requires moving a fifth up from G#, the required D# is not immediately available. But the auxiliary control could shift the Eb to D#. Generally a piece of music is not going to need the Eb at any time close to when it needs the D#, so handling the auxiliary control should not be too burdensome.

The next natural such circulating keyboard would have 19 keys per octave. These could be arranged by splitting the five black keys, and then adding single black keys between B and C, and between E and F. This could work as a simple system with 19 equal steps per octave, which is approximately 1/3 comma meantone. But such a keyboard could also work in arbitrary meantone tunings using an auxiliary shift control. So, for example, in one setting of the auxiliary control, the key between B and C would provide Cb, while in another setting it would provide B#.

Wednesday, March 13, 2024

Finding the Phase Transition

I've been using an algorithmic approach to music composition, based on thermodynamic simulation. One advantage of an algorithmic approach is its generality. One can use the same software to generate music in a wide variety of tuning systems. Other parameters can be adjusted easily, too. Of course, no algorithm is likely to generate music of the quality that a skilled human composer could produce. On the other hand, there can be some value to music that is outside the usual patterns.

These days a different algorithmic approach to composition has gained some traction, an approach that works with a large number of existing compositions, extracts some patterns, and then follows these patterns to generate a new composition that sounds much like the existing compositions. Just to be clear, the approach I am using does not use existing compositions in the execution of the software. I listen to a lot of music, and I listen to the output of my software; I tweak my software in an effort to coax it into producing something as music-like as I can. But this is a long way from the Deep Learning methods of the predominant Artificial Intelligence software.

Thermodynamic simulation is a randomized process that repeatedly adjusts the values of a large number of inter-related variables. The variables are connected in some kind of network, that defines the interactions between the variables. In my music composition software, the variables are the pitches of what is to be played at each particular time by each particular voice. When a voice is to sound a pitch at one time and then a second pitch at a succeeding time, these pitches should be nicely related if the music is to sound good. The pitches should not be too far apart, and should be reasonably consonant. Similarly, if one voice is sounding one pitch, and another voice is sounding another pitch at the same time, these two pitches need to be consonant if the music is to sound good.

If a piece is ten minutes long, each voice might involve a thousand pitch choices. During the simulation, all of these choices have provisional pitch values. Again and again, one or another of these choices is selected at random, and then the pitch selection for that specific time is reevaluated, in the context of the provisional choices in place for what that voice is to sound before and after, etc. The software will choose a new pitch for that voice at that time, preferring pitches that are consonant with the other pitch choices nearby in space and time. Then some other voice and time will have its pitch reevaluated. Over the course of the composition process, each pitch will change hundreds of times. Other related pitches will have changed between one evaluation and the next, so which pitch is most consonant may well change over the course of the simulation.

Thermodynamic simulation is driven by a key parameter, the temperature. At high temperature, the preference for consonant pitches is not very strong. At low temperature, only the most consonant pitches will be assigned. At very high temperature, the simulation will assign pitches essentially at random, so the music will be pure noise. At very low temperature the simulation will strive to maximize consonance. But if the pitches are initially very random and then the simulation is run at very low temperature, very often it will happen that in evaluating the best pitch for a particular voice at a particular time, the related pitches don't pull in a consistent direction. One pitch choice will be consonant with some neighbors but dissonant with others. There will often be no choice that is consonant with all the nearby pitches.

The way to generate pitch assignments that are mutually consonant throughout the network is to start the simulation at a high temperature and then to slowly lower the temperature. Each pitch selection provides some communication between more remote regions of the composition. The entire system can eventually negotiate mutually agreeable pitch choices in this way.

Thermodynamic simulation thus has the capability of generating pure noise at high temperature and pure order at low temperature. Neither of these makes interesting music: either extreme is quite dull! Interesting music happens in the region between total noise and total order.

The fascinating thing about this kind of thermodynamic system, whether simulated or in real physical systems, is that the transition between order and disorder is often not smooth and gradual, but can be quite abrupt. Right at the boundary between the ordered phase and the disordered phase, the system can exhibit fractal fluctuations as it wavers between the behaviors of the different phases. Fractal fluctuations are a characteristic of interesting music. So the approach I generally use for generating interesting music with thermodynamic simulation is to set the temperature to where the phase transition happens and make the pitch choices at that temperature, where consonant choices are preferred but not too strongly.

One challenge with this approach is that the temperature at which the phase transition happens is not something one can calculate in any simple way. One is basically stuck with simulating the system at different temperatures, observing its behaviors, and identifying an abupt shift. That's what the graph at the top of this post illustrates. At each temperature, the system will settle into an overall level of consonance, which corresponds to energy in thermodynamics. A highly consonant system has very low energy; a highly dissonant system has very high energy.

The graph above has a clear enough abrupt shift at a temperature of around 380. There is a sudden drop in the energy with a small change in the temperature. Locating this sudden drop is a bit tricky though, because of the random nature of the simulation. The energy is always bouncing around even at a fixed temperature. What I do to filter out this randomness is to fit a smooth curve through each small family of temperature and energy measurements. Then I look for which such small curve shows the most abrupt change in energy over a small change in temperature. That tells me the temperature of the phase transition.

Once the temperature of the phase transition has been determined, I can set the simulation temperature to that value and let the simulation run so all the pitch choices come to reflect that boundary behavior, to exhibit fractal fluctuations.

Here are two pieces generated using this approach: