Music Lessons — Math Behind the Music

An interactive 5-stage AI-assisted tutor that teaches the mathematical foundations of music. Each stage pairs a live interactive visualization with an AI tutor (Claude Sonnet via OpenRouter) that guides you through exercises and corrects your answers. Bring your own OpenRouter API key.

Stage 1: Numbers & Notes

The chromatic scale has 12 semitones. Each semitone multiplies frequency by the twelfth root of 2 (approximately 1.0595). An octave doubles frequency exactly. The core formula is: f = 220 × 2^(octave − 3 + semitone / 12). An interactive piano keyboard lets you select any octave (2–5), click any of the 12 semitone keys, and see the full frequency formula and Hz value. Base frequency: A3 = 220 Hz; A4 = 440 Hz; A5 = 880 Hz.

Stage 2: Intervals & Ratios

Two notes are consonant when their frequencies form a simple integer ratio. A Perfect 5th (7 semitones) has ratio 3:2 — the simplest after the octave. A Minor 2nd (1 semitone) has ratio 16:15, producing audible beating. A canvas visualization draws the two sine waves side by side. Intervals covered: Unison (1:1), Minor 2nd (16:15), Minor 3rd (6:5), Major 3rd (5:4), Perfect 4th (4:3), Perfect 5th (3:2), Major 6th (5:3), Octave (2:1).

Stage 3: Chords as Vectors

A chord is a list of semitone offsets applied to a root note. Minor = [0, 3, 7]. Major = [0, 4, 7]. Major 7 = [0, 4, 7, 11]. Minor 7 = [0, 3, 7, 10]. Pentatonic = [0, 2, 4, 7, 9]. The same shape rotates around the chromatic clock to produce any chord in any key. An SVG clock diagram shows all 12 notes; active chord tones are highlighted with connecting lines. Click any note to change the root. This is how The Mountain music sequencer stores its chord progressions (Am/G/C/F).

Stage 4: Rhythm & Fibonacci

A bar has 16 sixteenth-note steps. Rhythm is a set of active step indices. Uniform 8th notes fill steps 0, 2, 4, 6, 8, 10, 12, 14 with even gaps. Fibonacci rhythm uses offsets 0, 1, 2, 4, 7, 12 — gaps of 1, 1, 2, 3, 5 — producing a dense cluster at the front that breathes out toward silence (Bach mode). Euclidean rhythm distributes 5 hits as evenly as possible: steps 0, 3, 6, 9, 12. BPM timing: 1 step = 60,000 ms ÷ BPM ÷ 4; at 110 BPM, 1 step ≈ 136 ms.

Stage 5: Synthesis & Hz Math

Real instrument tones are sums of harmonics — sine waves at integer multiples of a fundamental. Sliders control the amplitude of the 1st (fundamental), 2nd (octave, 2×), 3rd (fifth up, 3×), and 4th (two octaves, 4×) harmonics. A canvas waveform updates in real time to show the composite shape. A BPM selector (60–160) displays 1-step, 1-bar, and 16-bar timings in milliseconds. Reference: A4 = 440 Hz. The Mountain uses Web Audio OscillatorNode at pentatonic frequencies with GainNode envelopes for attack and release.

AI Tutor

Each stage includes an AI chat panel powered by Claude Sonnet (OpenRouter model anthropic/claude-sonnet-4). The tutor is aware of the current stage and The Mountain sequencer design. It gives short 3–5 sentence replies, one exercise at a time, using physical language to describe wave behavior. Type “next stage” to advance. Quick-reply buttons: “Give me a hint”, “Show me the answer”, “Next stage →”.

Full machine-readable specification: llms.txt