Chapter 10

Music, Number, and Nature

Topics: Connecting nature, music and number, Pythagorean theorem, music from math curves, sin() and cos() functions, the Python math library, visualizing oscillations, the harmonograph, sonifying oscillations, Kepler’s harmony of the world revisited.

10.1 Overview

In the previous chapters, we studied essential building blocks of music and computer science. We now know enough about music and programming to return to the themes introduced in Chapter 1. In this chapter we will deepen our exploration into the connections between music, number, and nature, and introduce you to ideas that will hopefully inspire and guide you in your own personal journey into music and programming.

The Pythagoreans discovered that music harmony can be modeled by numbers. As Aristotle mentions, they thought that the principles of mathematics “were the principles of all things. Since, of these principles, numbers are by nature the first, and in numbers there seemed to see many resemblances to the things that exist and come into being” (Aristotle 1992, pp. 70–71).

The Pythagoreans observed that strings exhibit harmonic proportions, that is, they resonate at integer ratios of their length (i.e., 1/1, 1/2, 1/3/, 1/4, 1/5, etc.). They also observed that these proportions are aesthetically pleasing to the human ear. Accordingly, they developed musical modes based on these ratios, which formed the basis of our modern-era musical scales.

Among other things, the Pythagoreans quantified “harmonious” musical intervals in terms of proportions (ratios) of the first few whole numbers: a unison is 1:1, octave is 2:1, perfect fifth is 3:2, perfect fourth is 4:3, and so on (Miranda 2001, p. 6). The Pythagorean scale was refined over centuries to produce well-tempered and equal-tempered scales (Livio 2002, pp. 29, 186).

Aristotle supported the Pythagorean view that “[the interplay] between opposites is the beginning of all beings” (Aristotle 1992, pp. 72–73). Plato, Euclid, and others provided a more precise description of this interplay in the form of proportional analogies (e.g., “A is to B as C is to D”). The apogee of this exploration may have been the discovery of the golden mean. This is a special proportion (i.e., 1.61803398875 ...) that humans find aesthetically very pleasing. It is found in natural or human-made artifacts (Beer 2008; Calter 2008, pp. 46–57; Hemenway 2005, pp. 91–132; Livio 2002; May 1996; Pickover 1991, pp. 203–205). It is also found in the human body (e.g., the bones of our hands, the cochlea in our ears, etc.). The golden ratio reflects a place of balance in the structural interplay of opposites.

How did the Pythagoreans accomplish this much? And why did they care? What drove them to this?

Here is a possible answer, called “The Great Theme”:

“Picture to yourself, if you can, a universe in which everything makes sense. A serene order presides over the earth around you, and the heavens above revolve in sublime harmony. Everything you can see and hear and know is an aspect of the ultimate truth: the noble simplicity of a geometric theorem, the predictability of the movements of heavenly bodies, the harmonious beauty of a well-proportioned fugue—all are reflections of the essential perfection of the universe” (James 1995, p. 3)

10.2 Origins and Representations

Although Pythagoreans coined the term mathematics,* they were not the first to study it. The origins of exploring patterns in nature (e.g., seasons, astronomical patterns, etc.) and trying to comprehend the principles behind them goes back to Chinese emperors, Babylonian priests, prehistoric cave people in France, and the Mayans, among others (Pickover 2002, pp. 11–35).

We know that these different peoples were studying patterns in nature and were developing mathematical knowledge and skills, because they left behind various representations (inscriptions and objects) of that knowledge. Naturally, as we examine representations from these diverse societies, we see that they and the knowledge they depict changed over time.

Which brings us to an important realization.

Fact: The representation of knowledge is independent from the actual knowledge.

For example, let’s explore some the history of one of those expressions of “the ultimate truth” captured in “the noble simplicity of a geometric theorem,” the Pythagorean Theorem.

10.2.1 Pythagorean Theorem

The Pythagorean Theorem revolves around a balance emerging from right triangles. Why did the Pythagoreans care about triangles? Probably because triangles emerge from first principles (i.e., ab initio, or “from the beginning”), as we will see in the next section. Why right triangles? Probably because their orthogonality may have been a way to model the “[interplay] between opposites is the beginning of all beings” (Aristotle, pp. 72–73).

Fact: In right triangles, the (area of the) square of the hypotenuse always equals the (areas of the) squares of the two other sides (see Figure 10.1).

Interestingly, the Pythagorean Theorem did not originate with the Pythagoreans. As we know now, sometime around 1800 BCE, a Babylonian clay tablet was inscribed using cuneiform script with instances of Pythagorean triples (see Figure 10.2). Pythagorean triples are numbers that demonstrate the property of right triangles captured by the Pythagorean Theorem (e.g., 3, 4, 5).

Figure 10.1

Image of A Pythagorean triangle

A Pythagorean triangle (source Wikipedia).

Figure 10.2

Image of A Babylonian clay tablet with instances of Pythagorean triples

A Babylonian clay tablet with instances of Pythagorean triples (no 322, Plimpton Collection, Columbia University) (source Wikipedia—public domain).

As the centuries passed, people developed different languages to represent this significant piece of knowledge. In our culture, we use the following representation:

c2 = a2 + b2

One of the advantages of this notation is that it is succinct. One of its disadvantages is that it succinct, and thus “compresses” a lot of knowledge in few symbols (which, linguistically, makes it hard to interpret). It is easy to produce, but it is hard to deconstruct, in order to understand what’s being said.

Similarly to Western notation for music, this modern notation for mathematics is only one of several possible representations.

10.2.2 Python as a Representation

Interestingly, Python is also a representation. What sets it apart from the above representations is that Python comes “alive” when you run it on a computer. It can handle music data, but also musical processes. It can handle numbers, but also mathematical processes. Such power in a knowledge representation is unseen in the history of civilization (however, the Antikythera mechanism design and implementation comes close). In summary, Python’s representational power enables us to explore connections between music, number, and nature.

Since in previous chapters we have seen how to model music data and musical processes, this chapter will focus on modeling mathematical (and physical) processes. Since mathematical processes have been used for centuries to model nature (e.g., physics and astronomy), we can tap into this knowledge, translate it to Python, and then write programs that are driven by these processes to create music and sound. The possibilities are endless.

Now we will return to the Pythagorean Theorem and explore its possible connection to the Pythagorean fascination with musical (and other) harmonies.

Let’s begin.

10.3 Case Study: Music from Math Curves

A mathematical function describes a line or curve. These curves could be thought of as describing a musical gesture, for example, a melodic contour. A function can be mapped to any musical parameter, that is, pitch in the case of a melodic curve, or volume in the case of an amplitude envelope. The mapping between the function values and the musical parameters is entirely up to the composer; for instance, a function may influence more than one parameter at a time.

A simple mathematical function is the sine. It describes a smooth repetitive oscillation (i.e., a wave). The sine function is a trigonometric function.§ It is used in measuring right triangles.

The sine of angle α (see Figure 10.3) is equal to the ratio of two triangle sides:

Figure 10.3

Image of Two complementary views of the sine function

Two complementary views of the sine function: (a) as a measurement of a right triangle, and (b) as the rise of a point traversing a unit circle. (source Wikipedia).

  • the opposite side to α, compared to
  • the hypotenuse.

Alternatively (see Figure 10.3), if point B was traveling the circumference of a unit circle (a circle with radius 1), the sine of angle α corresponds to how high B is from the horizontal centerline (its vertical distance).

Notice that as point B moves around the circle, the sine traverses an oscillation.

  • sin(0) is 0 (point B is on the centerline),
  • sin(90) is 1 (point B is on the vertical centerline), and so on.

Python provides this and other useful math functions. These are defined in the math library (see next section). One thing to remember about the sin() function is that, in Python, it works with radians. If your angle is in degrees, you can convert it with function radians(). For example:

>>> from math import *
>>> sin(0)
0.0
>>> sin(pi/2)
1.0
>>> radians(90) == pi/2
True
>>> sin(radians(90))
1.0
>>> radians(180) == pi
True

and so on. Similarly, if the angle is in radians, you can convert with function degrees().

>>> degrees(pi/2)
90.0
>>> degrees(pi)
180.0

10.3.1 Hearing the Music

The following program demonstrates how to create a simple melodic contour using the sin() function. This program creates the piano roll shown in Figure 10.4, which traces the sine wave oscillation discussed above.

Figure 10.4

Image of Melodic contour from a sine wave

Melodic contour from a sine wave.

The “sineMelody.py” program creates notes from one cycle of a sine wave function, that is, 0 radians (or 0 degrees) to 2*pi radians (or 360 degrees). It creates many notes, whose pitches correspond to the sine value, inside the for loop. The density variable adjusts how many notes are spread across each cycle of the sine wave. The program uses the music library mapValue() function to map sine wave values to the appropriate musical parameters.

Here is the code:

# sineMelody.py
#
# This program demonstrates how to create a melody from a sine wave. 
# It maps the sine function to a melodic (i.e., pitch) contour.
#
from music import *
from math import *  
phr = Phrase()
density = 25.0	# higher for more notes in sine curve
cycle = int(2 * pi * density)	# steps to traverse a complete cycle
# create one cycle of the sine curve at given density
for i in range(cycle):
	value = sin(i / density)	# calculate the next sine value
	pitch = mapValue(value, -1.0, 1.0, C2, C8)	# map to range C2-C8
	note = Note(pitch, TN)
	phr.addNote(note)
# now, all the notes have been created
View.pianoRoll(phr)	# so view them
Play.midi(phr)	# and play them

The constant pi is approximately 3.141592653589793. It corresponds to half a circle (or 180 degrees). Accordingly, 2*pi is a full circle (or 360 degrees).

Notice the following:

density = 25.0			# higher for more notes in sine curve
cycle = int(2 * pi * density)	# steps to traverse a complete cycle

It is used to adjust how many data points (i.e., notes) to generate while traversing the circle. The higher the density, the more data points (notes) will be generated. The more data points, the slower the music will be (since every note has duration TN).

Next we connect additional musical parameters to the sine function, namely, note duration, dynamic, and panning. The piano roll generated by the updated program is shown in Figure 10.5. Notice the distortion in the sine wave graph. Why does that happen? The sine wave graph assumes steady movement on the x-axis (time), that is, constant note durations. Since we connected the sine function to note duration, the resultant note durations fluctuate, hence the distortion in the graph.**

Figure 10.5

Image of Melodic contour from sine wave also mapped to duration of notes

Melodic contour from sine wave also mapped to duration of notes.

Here is the code:

# sineMelodyPlus.py
#
# This program demonstrates how to create a melody from a sine wave. 
# It maps the sine function to several musical parameters, i.e., 
# pitch contour, duration, dynamics (volume), and panning. 
#
from music import *
from math import *  
sineMelodyPhrase = Phrase()
density = 25.0	# higher for more notes in sine curve
cycle = int(2 * pi * density)	# steps to traverse a complete cycle
# create one cycle of the sine curve at given density
for i in range(cycle):
	value = sin(i / density)	# calculate the next sine value
	pitch = mapValue(value, -1.0, 1.0, C2, C8)	# map to range C2-C8
	#duration = TN
	duration = mapValue(value, -1.0, 1.0, TN, SN)	# map to TN-SN
	dynamic = mapValue(value, -1.0, 1.0, PIANISSIMO, FORTISSIMO)
	panning = mapValue(value, -1.0, 1.0, PAN_LEFT, PAN_RIGHT)
	note = Note(pitch, duration, dynamic, panning)
	sineMelodyPhrase.addNote(note)
View.pianoRoll(sineMelodyPhrase)
Play.midi(sineMelodyPhrase)

To best appreciate the results (e.g., the smooth oscillation in panning), use a set of good headphones.

10.3.2 Exercises

  1. Currently, panning fluctuates from center to right, to left, and back to center. How would this change if you used the cosine function, cos(), instead? Why?
  2. Experiment with additional math functions to create interesting melodic and other contours. See the next section for some possibilities. Also see Watkins, 2001.

10.4 Math Library

The Python math library provides various math constants and operations. Similarly to the other libraries we have seen, you have to import it in your programs:

from math import *

Among others, this gives you access to the following (in the examples below, assume a is 2, and b is 3):

Operator

Description

Example

pi

The mathematical constant π

3.141592653589793

E

The mathematical constant e

2.718281828459045

sqrt(x)

The square root of x

sqrt(25) evaluates to 5

log(x, base)

The logarithm of x (the power by which to raise base in order to get x)

log(9, 3) evaluates to 2.0

degrees(x)

Converts x radians to degrees

degrees(pi) evaluates to 180.0

radians(x)

Converts x degrees to radians

radians(180) evaluates to 3.14159...

sin(x)

The sine of x in radians

sin(0) evaluates to 0.0

cos(x)

The cosine of x in radians

cos(0) evaluates to 1.0

hypot(x, y)

The hypotenuse of the Pythagorean triangle whose other sides have lengths x and y (or Euclidean distance)

hypot(3, 4) evaluates to 5

10.5 Case Study: The Harmonograph

Although the Pythagorean Theorem might appear unrelated to our musical narrative, it is not. It is encompassed in a very interesting device called the harmonograph.

The harmonograph is a device used to study what happens when you combine harmonic oscillations. It is closely related to the Pythagorean discoveries about musical intervals and their relationship to harmonic ratios to various other musical tunings and scales (Ashton, 2003).

Definition: A harmonograph is a device with a pen attached to two pendulums moving in orthogonal directions to each other (see Figure 10.6). As the pendulums move, the pen draws geometric shapes on a paper.

In the lateral harmonograph (Figure 10.6, left), each pendulum swings in a plane; the two planes are perpendicular. The right pendulum has a square paper atop its shaft; the paper oscillates back and forth in one direction, forced by the pendulum’s movement. The left pendulum has an attached arm that moves a pen back and forth in a direction perpendicular to the direction the paper’s movement.

Figure 10.6

Image of Two types of harmonographs

Two types of harmonographs. Left is a lateral, two-pendulum harmonograph (note the orthogonal direction of the pendulums). Right is a rotary, three-pendulum harmonograph (third pendulum has a rotary bearing, which allows circular motion). (From Ashton, A. (2003). Harmonograph: A Visual Guide to the Mathematics of Music. Glastonbury, UK Wooden Books., p. 19.)

In the rotary harmonograph (Figure 10.6, right), the paper is attached to a third shaft that traces a circular path. The two pendulums push the pen in two perpendicular directions.

Some harmonographs have additional components (e.g., an additional pendulum) to help model more complicated harmonic relationships and movements.

Fact: Harmonographs are used to explore and easily visualize the relationships between different harmonic ratios.

For example, see Figure 10.7. It demonstrates the shapes generated from common harmonic ratios (i.e., 1:1, 2:1, and 3:2). On the left are the shapes generated from a lateral harmonograph with pendulums moving in same (or opposing) phase. On the right are the shapes generated from a rotary harmonograph with pendulums moving in same (or opposing) circular motion. Both versions will be shown below in Python.

Figure 10.7

Image of Using two harmonographs, lateral (left) and rotational (right) to generate shapes for different ratios

Using two harmonographs, lateral (left) and rotational (right) to generate shapes for different ratios (e.g., 1:1, 2:1, etc.). (From Ashton, A. (2003). Harmonograph: A Visual Guide to the Mathematics of Music. Glastonbury, UK Wooden Books., p. 19.)

Notice how simple geometric shapes naturally emerge from harmonic ratios (e.g., the octave, or 2:1 ratio) of orthogonal movement. Harmonograph drawings are related to Chladni patterns (seen in Chapter 1) and clearly help elucidate the principles of harmonics, overtones, and tunings of musical instruments.

Harmonographs are similar to the popular spirograph children’s toy (which uses plastic gears to accomplish a similar result).††

The Antikythera mechanism (seen in Chapter 1) demonstrates that the ancients understood how to model different ratios using gears. It also demonstrates they knew how to create same and opposite circular motion (Vallianatos, 2012).

The Pythagoreans explored ways to sonify existing knowledge about harmonious ratios. Apparently, this knowledge came from ancient Egyptian and Mesopotamian scholars, who had been studying the periodicities of the night sky. These observations originated with early humans being curious about the bright lights moving in the night sky, at the beginning of civilization. Eventually, these observations coalesced into theories and (eventually) models, possibly over thousands of generations and across cultures (each inheriting some, but not necessarily all of the knowledge of its predecessors).

Next we will see that harmonographs can be easily described with simple Python trigonometric functions, i.e., sin() and cos(). The function cos() is similar to sin().

Going back to Figure 10.3, sin(α) corresponds to how high B is from the horizontal centerline (its y distance). Accordingly, cos(α) corresponds to how far B is from the vertical centerline (its x distance).

These two functions all that we need. They provide a concise representation for the movement of the two pendulums (as shown below). It is all that we need to see this “[interplay] between opposites” which, according to the Pythagoreans, was “the beginning of all beings” (Aristotle, pp. 72–73).

10.5.1 Lateral Harmonograph

A lateral harmonograph is a device with a pen attached to two pendulums moving in orthogonal directions to each other. As the pendulums move, the pen draws geometric shapes on a paper. Our controls include:

  • The length of the pendulums—this affects the frequency of their oscillation. By combining different frequency ratios (e.g., 2:3), we get the shapes shown in Figure 10.7 (and more).
  • The phase of the pendulums, relative to one another. In Python this is modeled by either using two sin() functions (same phase) or one sin() and one cos() function (opposite, or orthogonal) phase.

The program below creates a display onto which it draws points that trace the movement of the virtual pen connected to the pendulums. It also outputs the current ratio setting (see Figure 10.8). If you are wondering why the use of sin() and cos() accurately describe the motion of the pen on the paper, the answer lies in Figure 10.3 and Figure 10.7 (top left).

Figure 10.8

Image of Output generated by lateral harmonograph program

Output generated by lateral harmonograph program (2:3 ratio, same phase).

Here is the code:

# harmonographLateral.py
# 
# Demonstrates how to create a lateral (2-pendulum) harmonograph 
# in Python.
#
# See Ashton, A. (2003), Harmonograph: A Visual Guide to the 
# Mathematics of Music, Wooden Books, p.19.
#
from gui import *
from math import *
d = Display("Lateral Harmonograph", 250, 250)
centerX = d.getWidth() / 2	# find center of display
centerY = d.getHeight() / 2
# harmonograph parameters
freq1 = 2	# holds frequency of first pendulum
freq2 = 3	# holds frequency of second pendulum
ampl = 50	# the distance each pendulum swings
density = 250	# higher for more detail
cycle = int(2 * pi * density)	# steps to traverse a complete cycle
times = 6	# how many cycles to run
# display harmonograph ratio setting
d.drawText("Ratio " + str(freq1) + ":" + str(freq2), 95, 20)
# go around the unit circle as many times requested
for i in range(cycle * times):
	# get angular position on unit circle (divide by a float
	# for more accuracy)
	rotation = i / float(density)
	# get x and y coordinates (run and rise)
	x = sin(rotation * freq1) * ampl	# get run (same phase) 
	#x = cos(rotation * freq1) * ampl	# get run (opposite phase)
	y = sin(rotation * freq2) * ampl	# get rise
	# convert to display coordinates (move display origin to center, 
	# from top-left)
	x = x + centerX
	y = y + centerY
	# draw this point (pixel coordinates are int)
	d.drawPoint(int(x), int(y))

Notice how we calculate the center of the display:

centerX = d.getWidth()/2 # find center of display
centerY = d.getHeight()/2

This is used later in the program to move the origin of the virtual pen from top-left to the center, so that the shapes are drawn centered in the display.

Notice the various harmonograph parameters (defined as constants at the program’s beginning). Again, this makes it easy to adjust the harmonograph to new settings.

# harmonograph parameters
freq1 = 2	# holds frequency of first pendulum
freq2 = 3	# holds frequency of second pendulum
ampl = 50	# the distance each pendulum swings

The comments should be self-explanatory.

Parameter times is used to determine how many cycles to let the simulated pendulums oscillate (i.e., how many times to go back and forth).

Fact: When using integer ratios (e.g., 3:2), the generated shapes are complete after one cycle. Additional cycles simply retrace the original orbit (or shape).

Fact: When using noninteger ratios (e.g., 5.1:4), the generated shapes take more cycles to complete.‡‡

Notice how we can change from same to opposite phase by switching the comments in the following:

# get x and y coordinates (run and rise)
x = sin(rotation * freq1) * ampl	# get run (same phase)
#x = cos(rotation * freq1) * ampl	# get run (opposite phase)

Finally, we shift the origin of the shape from (0, 0), the top-left of the display, to the display’s center. And we draw the point.

# convert to display coordinates (move display origin to center, 
# from top-left)
x = x + centerX
y = y + centerY
# draw this point (pixel coordinates are int)
d.drawPoint(int(x), int(y))

10.5.2 Rotary Harmonograph

A rotary harmonograph is a device with a pen attached to two pendulums moving in orthogonal directions to each other. As the pendulums move, the pen draws geometric shapes on a paper. Additionally, the paper is placed on another pendulum mounted on a rotary bearing (i.e., gimbals), which adds a third circle (oscillation) to the drawing.

The next program creates a display onto which it draws points that trace the movement of the virtual pen connected to the pendulums. It also outputs the current ratio setting (see Figure 10.9).

Figure 10.9

Image of Output generated by rotary harmonograph program

Output generated by rotary harmonograph program (left) 2:3 ratio, opposite rotation—(right) 8:13 ratio, same rotation.

Let’s see the code:

# harmonographRotary.py
# 
# Demonstrates how to create a rotary (3-pendulum) harmonograph 
# in Python.
# 
# Here, the position of the pen is determined by two pendula, 
# and is modeled by either (sin, sin) or (cos, sin).
# The third pendulum has its own sin() and cos() to model the second 
# circle. 
#
# See Ashton, A. (2003), Harmonograph: A Visual Guide to the 
# Mathematics of Music, Wooden Books, p.19.
#
from gui import *
from math import *
d = Display("Rotary Harmonograph", 250, 250)
centerX = d.getWidth() / 2	# find center of display
centerY = d.getHeight() / 2
# harmonograph parameters
freq1 = 2	# holds frequency of first pendulum
freq2 = 3	# holds frequency of second pendulum
ampl1 = 40	# holds swing of movement for pair of pendulums 
	# (radius of first circle)
ampl2 = ampl1	# holds swing of movement for third pendulum 
	# (radius of second circle)
#friction = 0.0003	# how much energy is lost per iteration
density = 250	# higher for more detail
cycle = int(2 * pi * density)	# steps to traverse a complete cycle
times = 4	# how many cycles to run
# display harmonograph ratio setting
d.drawText("Freq Ratio " + str(freq1) + ":" + str(freq2), 80, 10)
# go around the unit circle as many times requested
for i in range(cycle * times):
	# get angular position on unit circle (divide by a float
	# for more accuracy)
	rotation = i / float(density) 
	# get x and y coordinates (run and rise)
	#x1 = sin(rotation * freq1) * ampl1	# get run (same phase)
	#y1 = cos(rotation * freq1) * ampl1	# get rise
	x1 = cos(rotation * freq1) * ampl1	# get run (opposite phase)
	y1 = sin(rotation * freq1) * ampl1	# get rise
	x2 = sin(rotation * freq2) * ampl2	# get run (second pendulum)
	y2 = cos(rotation * freq2) * ampl2	# get rise
	# combine the two oscillations
	x = (x1 - x2)
	y = (y1 - y2)
	# convert to display coordinates (move display origin to center,
	# from top-left)
	x = x + centerX
	y = y + centerY
	# draw this point (pixel coordinates are int)
	d.drawPoint(int(x), int(y)) 
	# loss some energy due to friction
#	ampl1 = ampl1 * (1 - friction)
#	ampl2 = ampl2 * (1 - friction)

This program is very similar to the previous one. Notice how we can change from same to opposite rotation by switching the comments in the following:

# get x and y coordinates (run and rise)
#x1 = sin(rotation * freq1) * ampl1	# get run (same phase)
#y1 = cos(rotation * freq1) * ampl1	# get rise
x1 = cos(rotation * freq1) * ampl1	# get run (opposite phase)
y1 = sin(rotation * freq1) * ampl1	# get rise

Notice the second pair of coordinates, x2 and y2, calculated with a second pair of sin() and cos() functions:

x2 = sin(rotation * freq2) * ampl2	# get run (second pendulum)
y2 = cos(rotation * freq2) * ampl2	# get rise

These contribute the second circle (caused by the rotation of the third pendulum). These are coordinates of the paper plane, as it rotates, being attached to the third pendulum. Also notice the addition of a second amplitude variable; again, this controls the amount of swing of the third pendulum.

Finally, notice how we have added a way to dampen both oscillations, if we wish (using variable friction). Simply uncomment the last three statements. Damping the oscillations introduces another element of control, which produces more interesting shapes.

10.5.3 Exercises

  1. Compare Figure 10.9 (right) with Figure 10.10. The former is created by the harmonograph from a 8:13 ratio, using same (concurrent) rotation. The second is the trajectory of Venus on the Earth night sky (the Earth orbits 8 times for every 13 orbits of Venus). This creates a pentagram on the night sky.
  2. Research the importance of the pentagram to the Pythagoreans.
  3. Research the connection between the pentagram and the golden ratio. As you will soon realize, the pentagram contains the golden ratio in many ways. What does this mean?

10.5.4 Noninteger Ratios

Noninteger ratios correspond to musical intervals that are not harmonious, that is, not pleasing to the ear.

Figure 10.10

Image of Successive inferior conjunctions of Venus as seen from Earth

Successive inferior conjunctions of Venus as seen from Earth (from Wikipedia—public domain).

Interestingly, such ratios generate chaotic behavior in the path traced by the harmonograph pen. When exploring, increase the value of variable times to allow the pen to trace orbits over several cycles, so that you can begin to see the behavior that emerges. For example, Figure 10.11 shows the shapes generated by particular non harmonic ratios (with times set to 6).

Figure 10.11

Image of Lateral harmonograph and rotational harmonograph

(Left) Lateral harmonograph (5.01:4 ratio, same phase, 6 times/cycles). (Right) Rotational harmonograph (5.01:4 ratio, same phase, 6 times/cycles).

Certain ratios will never converge, that is, no matter how many cycles you run, they will always add more detail (as allowed by the resolution of your computer screen).

10.6 Case Study: Kepler’s Harmony of the World, No. 2

The following program explores a more advanced sonification of the planetary velocities we explored in Chapter 7. Here we apply some of the same processes used in the lateral harmonograph to convert planetary velocities to music (or to sonify planetary velocities).

Here is the code:

# harmonicesMundiRevisisted.py
#
# Sonify mean planetary velocities in the solar system.
#
from music import *
from math import *
from random import *
# Create a list of planet mean orbital velocities
# Mercury, Venus, Earth, Mars, Ceres, Jupiter, Saturn, Uranus, 
# Neptune. (Ceres is included in place of the 5th missing planet 
# as per Bode's law).
planetVelocities = [47.89, 35.03, 29.79, 24.13, 17.882, 13.06, 9.64, 6.81, 5.43]
numNotes	= 100	# number of notes generated per planet
durations	= [SN, QN]	# a choice of durations
instrument	= EPIANO	# instruent to use 
speedFactor	= 0.01	# decrease for slower sound oscillations
score = Score(60.0)	# holds planetary sonification
# get minimum and maximum velocities:
minVelocity = min(planetVelocities)
maxVelocity = max(planetVelocities)
# define a function to create one planet's notes - returns a Part
def sonifyPlanet(numNotes, planetIndex, durations, planetVelocities):
	"""Returns a part with a sonification of a planet's velocity."""
	part = Part(EPIANO, planetIndex)	# use planet index for channel
	phr = Phrase(0.0)
	planetVelocity = planetVelocities[planetIndex]	# get velocity 
	# create all the notes by tracing the oscillation generated using
	# the planetary velocities
	for i in range(numNotes):
	# pitch is constant
	pitch = mapScale(planetVelocity, minVelocity, maxVelocity, 
	C3, C6, MIXOLYDIAN_SCALE, C4)
	# panning and dynamic oscillate based on planetary velocity
	pan = mapValue(sin(i * planetVelocity * speedFactor * 2), -1.0, 1.0, PAN_LEFT, PAN_RIGHT)
	dyn = mapValue(cos(i * planetVelocity * speedFactor * 3), -1.0, 1.0, 40, 127)
	# create the note and add it the the phrase
	n = Note(pitch, choice(durations), dyn, pan)
	phr.addNote(n)
	# now, all notes have been created
	part.addPhrase(phr)	# add phrase to part
	return part	# and return it
# iterate over all plants
for i in range(len(planetVelocities)): 
	part = sonifyPlanet(numNotes, i, durations, planetVelocities)
	score.addPart(part)
View.sketch(score)
Write.midi(score, "harmonicesMundiRevisisted.mid")
Play.midi(score)

After importing the required libraries, the program starts by declaring some variables to hold constant values that will be used through the work. The most important of these is a list of the planetary velocities.

planetVelocities = [47.89, 35.03, 29.79, 24.13, 17.882, 13.06, 9.64, 
	6.81, 5.43]
numNotes	= 100	# number of notes generated per planet
durations	= [SN, QN]	# a choice of durations
instrument	= EPIANO	# instruent to use 
speedFactor	= 0.01	# decrease for slower sound oscillations

The core musical mapping happens in this code fragment:

# create all the notes by tracing the oscillation generated using
# the planetary velocities
for i in range(numNotes):
	# pitch is constant
	pitch = mapScale(planetVelocity, minVelocity, maxVelocity, C3, C6, MIXOLYDIAN_SCALE, C4)
	# panning and dynamic oscillate based on planetary velocity
	pan = mapValue(sin(i * planetVelocity * speedFactor * 2), -1.0, 1.0, PAN_LEFT, PAN_RIGHT)
	dyn = mapValue(cos(i * planetVelocity * speedFactor * 3), -1.0, 1.0, 40, 127)
	# create the note and add it the the phrase
	n = Note(pitch, choice(durations), dyn, pan)
	phr.addNote(n)
# now, all notes have been created

Notice how the pitch of a planet remains the same for all generated notes—it depends on its planetary velocity.§§

The panning position and dynamic level of the notes associated with each planet are continually modulated using sin() and cos(). The rate of change is associated with the planetary velocity. This way, different planets will vary at different speeds.

Since the planetary velocities have harmonic relationships to each other, this musical mapping sonifies these harmonies using the panning and dynamic musical dimensions. The effect is breathtaking—dynamic variations give an impression of proximity (loud appears close to the listener, while soft appears far), and panning gives an impression of left to right movement. Two orthogonal (harmonic) oscillations perceivable in one ever-changing sound.

Notice how this program combines the lateral harmonograph model to provide harmonious oscillations for the panning and dynamic (volume) of the notes produced. The effect is quite stunning. Since the planet velocities are related to their orbits, the harmony of the spheres literally emerges. Play with variable speedFactor to adjust the speed of the oscillations.

This sonification requires a nice pair of stereo headphones (or speakers).

The comments, and your familiarity by now with Python, should make the rest of the code self-explanatory.

10.6.1 Exercises

  1. The two orthogonal oscillations for panning and dynamic have an 1:1 ratio. Modify the above program to use other harmonic ratios, e.g., 1:2, 2:1, 3:2, 5:8, etc. What do you notice? Which ratios do you prefer for panning and dynamic?
  2. Modify the above program to use the rotary harmonograph model. Notice that the rotational harmonograph combines two orbits (oscillations). Use the planet periods (in days) around the sun (including Ceres in the asteroid belt, and Pluto¶¶), from inner to outer: 87.969 (Mercury), 224.701 (Venus), 365.256 (Earth), 686.980 (Mars), 1680.1 (Ceres), 4,332.6 (Jupiter), 10,759.2 (Saturn), 30,685 (Uranus), 60,190 (Neptune), and 90,465 (Pluto).
    1. One idea is to sonify the celestial harmonies these planets generate relative to Earth.*** First try them in the rotary harmonograph program above. Then combine this code with the case study above to generate music.
    2. Another possibility is to try ratios of consecutive planets, from inner to outer.
    3. Finally, try different ratios. Some interesting possibilities include Mercury:Venus, Venus:Ceres, Mars:Ceres, Jupiter:Neptune, and Neptune:Pluto (see Martineau, 2002, pp. 54–58).
    4. Consider truncating the ratios (by dividing them, say, by 100, and then converting the result to an int); for example, the ratio Venus:Earth (i.e., 224.701:365.256) will become 2:3. Not accurate, but nice.

Use the rotary harmonograph to first visualize these ratios. Then choose the ones you like better, that is, consider, visualize, and then sonify.

10.7 Summary

Up to this point in the book, we have exposed you to fundamentals in music theory, computer programming, and algorithmic design (that is, finding ways to express musical or other processes through the computer). This chapter focused on the themes introduced in Chapter 1 and explored deeper connections between music, number, and nature.

The last case study was particularly insightful. It demonstrated the types of possibilities that open up when different paths in an exploration converge. In particular, it combined knowledge about math (sin and cos), knowledge about harmonic ratios (the type of ratios that Kepler was exploring when he derived his three laws), principles of music theory and composition (pitch, duration, dynamic, and panning), and, finally, computer programming (how to put all this in a program that works). Now you have a thorough understanding of how to connect music, number, and nature.

Is this the end? Well, it could be... But we hope it is only a beginning. We hope we have inspired you and have provided the foundation for you to continue this exploration on your own. Some of you may even possibly further the state-of-the-art in computer music and (why not?) the knowledge of this new discipline defined by the intersection of computing and the arts. Therefore, we give you one more chapter. In it, we present several powerful ideas that may guide your exploration. Pay close attention!


* Derived from μάθημα = lesson, μαθαίνω = learn. The Pythagoreans divided people who attended their school to three groups, the akoustikoi (from άκουσμα = listening, i.e., those who listen), to mathematikoi (from μάθημα = lesson, i.e., those who learn), and the physikoi (from φύση = nature, those who study nature, the natural philosophers) (Cooke 2005, p. 271).

Orthogonal, in addition to perpendicular, refers to two independent forces or artifacts.

This holds for other programming languages as well.

§ From τρίγωνο = triangle + μέτρηση = measurement.

Recall that 90 degrees equals π/2 radians, 180 degrees equals π radians, and so on.

** This sine wave inside a sine wave is the basis for FM synthesis (or frequency modulation) — a technique used for creating realistic, rich sounds for synthesizers.

†† Both harmonographs and spirographs combine rotary movements at different ratios to trace orbits generated from this combination. The relationship of such devices with models of astronomical circular movement should be obvious.

‡‡ Some ratios, actually, never terminate (i.e., produce chaotic behavior). We will return to this soon.

§§ This statement could be moved before the loop, for efficiency. We leave it in the loop to facilitate further experimentation, e.g., we may wish to try to somehow alter the pitch of each note for this planet.

¶¶ Although Pluto is officially not a planet, it is still out there revolving in a sustainable orbit, so feel free to use it.

*** That is the harmonic patterns observed by the ancients in the night sky, which most probably inspired the Pythagoreans (and the Egyptians and Babylonians before them) to try and model what they saw through mathematics.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset