Getting Lost in Bird's Lines
I’m building an application, a tool for musicians who want to learn music by ear. It’s an audio player that lets you load a recording, slow it down, loop sections, and visualize the notes against a piano keyboard. The idea was to take it a step further by analyzing those notes and suggesting the underlying harmony. Or at least that was the original idea…
One of the first things I needed was a way to visualize the frequencies in a recording, so I wrote a small script that uses a Short-Time Fourier Transform to plot a spectrogram. I tested it with a few audio clips, including a clip from one of my favorite musicians, a recording of Charlie Parker warming up.
I was only checking whether the code worked. Then I didn’t get much done that evening, because I kept staring at the plot.
The clip
The bright yellow lines trace what Charlie Parker is playing. Press play and try to follow them.
Seeing lines has always been part of how I hear this music, and part of how I play it. Sometimes when I improvise, I’m not thinking about individual notes at all, but rather following a shape. Looking at this plot got me thinking more about the visual dimension of music, how we can almost see the movement of a phrase as we hear it and how much of our understanding of music might be connected to shapes.
A detail that caught my attention on this plot, between seconds 5 and 9 while Charlie Parker is playing you can hear someone in the room reacting to it. You can’t really understand what they say, but there’s definitely a tone of amazement in their voice. At that moment Bird’s line leaves a trace in the spectrogram that looks like a heart. A super cool coincidence. 
Steve Coleman
I’ve heard musicians talk like this for years: about the shape of a phrase, about a chord having a color, and just mixing in a bunch of other senses to describe musical phenomena.
Steve Coleman raps about it as well. This is from an interview in 2006:
I wanted to be able to look at a mountain and play the mountain.
I wanted to be able to look at the flight pattern of a bee, the flight pattern of a bird, and play that.
He says he was an artist before he was a musician, and that he began to program computers in 1985 to investigate what he was already doing in music. The whole interview is worth reading.
Dan Weiss
Around the same time I saw this: the drummer Dan Weiss listening to Sonny Rollins. No drums, just his hands.
He is following the shape of Sonny Rollins’s lines with his hands. He’s drawing the music in the air, following the turns, accents and movement of each phrase. It reminds me of Charlie Parker’s spectrogram, except here the visualization isn’t coming from a computer but from a musician who understands the language. There’s something about connecting sound with shapes and movement, even when only listening.
What I’ve built so far
Not much. The core is one function that computes a short-time Fourier transform. In plain words:
- A recording is just a long list of numbers, called samples, tens of thousands for every second of sound.
- Take a short piece of it, about a tenth of a second.
- Smooth the edges of that piece, so the sudden cut doesn’t show up as frequencies that aren’t in the music.
- Measure how strong each frequency is in that piece.
- Move forward a little and repeat, until the end of the recording.
Put all those measurements side by side and you get the picture: time goes left to right, frequency goes up, and the louder a frequency is, the brighter its color. Here’s the result.
This is the loop that does steps 2 to 5:
window = get_window("hann", frame_size)
magnitudes = []
for start in range(0, len(audio) - frame_size + 1, hop_size):
# Extract a short piece of audio
frame = audio[start:start + frame_size]
# Smooth the edges
frame = frame * window
# Find the frequencies present in this frame
spectrum = np.fft.rfft(frame)
magnitudes.append(np.abs(spectrum))
Each piece is 4,096 samples long, and a new one starts every 1,024, so they overlap.
Where this might go
I have my doubts about the original idea. An app that tells you the chords might not be great for a musician’s ear. Working out the harmony yourself is how you improve it, and it’s part of the transcription process.
The plot made me think of something else. When musicians talk about shapes and colors, it is not only a way of describing music. For a lot of them it is where ideas come from. A shape can be a reason to play something.
So this project might change direction and become some kind of visualizer for music, you give it a recording and see some sort of painting being made in real time. I don’t know yet. I’ll write about it here as I go.
