4.1 Steps and pitch

4.1 Steps and pitch#

Before going further, we need to take a short detour through musical pitch, which is difficult to avoid once we start referencing scores in the Western tradition. In Chapter 3 we saw that a tone’s fundamental frequency (in Hertz) determines our perception of pitch: higher frequency, higher pitch. However, musicians rarely communicate about pitch in Hertz. Instead, they speak in pitches and steps, a symbolic convention layered on top of the physical property of frequency. Our pitch kwargs from the pq.Score objets in the previous section ("C4", "G4", "A4") are exactly this convention, so let’s unpack it.

The convention is organized around the notion of a step (or semitone). A step is a relative unit: moving up by a fixed number of steps multiplies frequency by a fixed factor, rather than adding a fixed number of Hertz. Specifically, raising a frequency \(f\) by \(k\) steps multiplies its frequency by \(2^{k/12}\).

Definition 9 (Step)

A step (or semitone) is a relative pitch unit: raising a frequency \(f\) by \(k\) steps multiplies it by \(2^{k/12}\),

\[f + k \text{ steps} \iff f \cdot 2^{k/12} \text{ Hz}.\]

This convention is rooted in the most important frequency relationship: that of the octave. An octave is a doubling of frequency (the base \(2\) in the formula above), which is universally perceived by humans as a special relationship. In particular, we perceive two frequencies an octave apart as having “the same pitch, just higher up”. We divide the octave into \(12\) geometrically-spaced steps (we’ll answer “why \(12\)?” later in Chapter 15), but that chosen division is less important than the octave itself.

You can hear this doubling relationship directly. In each example below, we play the lower tone, then the tone an octave above it (double the frequency), then both together:

220 Hz, then 440 Hz, then both

330 Hz, then 660 Hz, then both

Two octave demonstrations. Doubling a frequency (\(220 \to 440\) Hz, or \(330 \to 660\) Hz) produces a tone we hear as the “same note, higher up.”

We capture this perceived equivalence with the notion of a pitch class: the set of all frequencies related to \(f\) by whole numbers of octaves.

Definition 10 (Octave and pitch class)

An octave is an interval of \(12\) steps, which multiplies frequency by \(2^{12/12} = 2\) (a doubling). All frequencies separated by a whole number of octaves form a pitch class,

\[\text{PitchClass}(f) \triangleq \{\, f \cdot 2^{i} \mid i \in \mathbb{Z} \,\}.\]

Because steps only express relative distances, converting to absolute frequency requires a single anchor point. The MIDI specification fixes the standard: MIDI pitch \(69\) is the note A4, defined as exactly \(440\) Hz.

Definition 11 (Pitch)

A pitch is an absolute position on the step scale, anchored by the MIDI standard at pitch \(69 \triangleq \text{A4} \triangleq 440\) Hz. Converting between MIDI pitch \(p\) and frequency \(f\) is accomplished via:

\[p = 69 + 12 \log_2\!\left(\frac{f}{440}\right), \qquad f = 440 \cdot 2^{(p - 69)/12}.\]

You don’t need to memorize the conversion formulas (pyquist implements them as pq.helper.frequency_to_pitch and pq.helper.pitch_to_frequency) but the multiplicative relationship \(2^{k/12}\) between steps and frequency is worth committing to memory.

Finally, the \(12\) pitch classes have names: [C, C#/Db, D, D#/Eb, E, F, F#/Gb, G, G#/Ab, A, A#/Bb, B], where each slashed pair is two names for the same class (enharmonics, for the musically-inclined). Appending an octave number picks out a specific pitch: A4 is the A in the octave containing middle C (C4), and equals MIDI \(69\) = \(440\) Hz. pyquist’s pq.helper.pitch_name_to_pitch turns a name like "C4" into its MIDI number — precisely the strings we passed as pitch kwargs in our Twinkle score.

Three octaves of the chromatic scale plotted as MIDI pitch (vertical, linear) against frequency in Hertz (horizontal, linear). The 37 notes from A2 (110 Hz) to A5 (880 Hz) trace an upward-curving exponential, bunching together at low frequencies and spreading apart at high frequencies. Each note is colored by its pitch class, so the A's (110, 220, 440, 880 Hz), the C's, and every other class repeat the same color once per octave.

Fig. 10 Three octaves of the chromatic scale, from A2 (\(110\) Hz) to A5 (\(880\) Hz). Because equal pitch steps correspond to equal multiplicative jumps in frequency, the notes trace an exponential curve, packed tightly at low frequencies and spread out at high ones. Color marks pitch class: every A shares a color, as does every C, and so on, one repetition per octave (dashed lines mark the octave boundaries at C3, C4, and C5).#