Barrios AI

Artificial Intelligence for Musicians

  1. Introduction
  2. Emergent Harmonic Structures | Software 1.0
  3. Pythagoras and the Music of the Spheres
  4. Building the Modes from Ancient Theory
  5. Harmonic Ratios in Nature and Music
  6. Musical Mathematics
  7. Exploring Chance and Randomness
  8. Statistics of Sound
  9. Software 2.0 | Deep Learning: Teaching Computers to See
  10. Software 2.0 | Deep Learning: Teaching Computers to Hear
  11. Software 3.0 | Generative AI: Teaching Computers to Read & Write
  12. Software 3.0 | Gemini Notebook as RAG

Chapter 7: Statistics of Sound

Free Preview

7.1 Music as Data

Think of a melody as numbers: pitch, duration, timbre. Simple statistics reveal style and structure.

# Example melody in MIDI pitches
melody_pitches = [60, 62, 64, 65, 67, 65, 64, 62, 60, 64, 67, 72]
melody_pitches

7.2 Music Analysis with Pandas and Python

Spreadsheets are just tables: every row describes one song, every column stores the same kind of fact for each song (tempo, key, energy, …).
Why is that powerful?

  • Consistency → quick math Uniform columns let us sort, filter, and average in a single line of code.
  • Clarity → better questions Well-labeled tables make patterns jump out: which keys dominate? How fast is the typical Miles Davis tune?
  • Automation → scale The Pandas library treats a CSV file like a programmable spreadsheet, so the same analysis works on twenty songs or twenty-thousand.

In the table below each row is a jazz classic; the columns capture five numeric (quantitative: countable values) or categorical (qualitative: descriptive categories) features:

  • Title: song name (categorical)
  • Artist: performer or ensemble (categorical)
  • Tempo: beats per minute (numeric)
  • Key: tonal center (categorical)
  • Energy: 0 to 1 proxy for loudness, density, rhythmic drive (numeric)

You’ll compute summary stats and build three quick plots:

  1. Histogram of tempo: see how fast most tunes sit.
  2. Scatter of tempo vs energy: spot the tunes that break the fast-equals-intense rule.
  3. Box-plot of tempo by key: and a lesson in what happens when most keys hold a single song.

By the end you’ll have a repeatable workflow: tabular data → Pandas → visual insight.

One honest label before we start: this table is hand-built teaching data, and the handwritten card in this chapter's video makes the point visually: someone wrote these numbers down, and that someone was me. The tempos and keys are close to common performance practice, though recordings vary, and Energy is my own 0-to-1 score of how intense each track feels, not a measurement taken from audio. Real datasets arrive with choices like these baked in, usually undocumented; ours documents them. Two spelling notes: keys are written ASCII-style (Eb for E flat) because CSV files and chart labels are happier without the flat glyph, and minor keys carry an m (Dm), with modal tunes listed by their tonal center.

Continue reading this chapter

You're reading a free preview. Purchase the book to unlock every chapter in Artificial Intelligence for Musicians.

✓ Full book unlocked✓ Every chapter✓ Runnable code✓ Lifetime access

Want a hand with the code or building your own setup?

I'm an AI/ML engineer and a professional musician. Bring a question, a real project, a tool you wish existed, or a workflow that's eating your time, and we'll build it on your machine with your files. First call is free, 15 minutes, no commitment.

Book a free 15 minute call →