Classical vs Punk: Why They Sound Different, in Numbers
Timbre features (centroid, rolloff, flatness, contrast, zero crossings, brightness) measured by my music engine on a Bach cello prelude, a Sum 41 song and the whole catalogue, by genre.

Timbre is the shape of the spectrum
Two notes at the same pitch and loudness can still sound nothing alike. That difference is timbre, and my engine measures it with fourteen numbers read off one shared spectrogram (22,050 Hz, 2,048-point window, 512 hop), averaged over the middle 60 seconds of each track.
Classical vs punk in 40 seconds

timbre_analysis.py: the timbre descriptors (excerpt)
centroid = librosa.feature.spectral_centroid(S=sp.S, sr=sr)[0]
contrast = librosa.feature.spectral_contrast(S=sp.S, sr=sr, n_bands=6)
flatness = librosa.feature.spectral_flatness(S=sp.S)[0]
rolloff = librosa.feature.spectral_rolloff(S=sp.S, sr=sr, roll_percent=0.85)[0]
zcr = librosa.feature.zero_crossing_rate(y, frame_length=settings.n_fft, hop_length=settings.hop_length)[0]Bach vs Sum 41
| | Bach, Cello Suite No. 1, Prelude | Sum 41, Fat Lip | |---|---|---| | spectral centroid | 950 Hz | 2,666 Hz | | rolloff (85 %) | 1,740 Hz | 5,605 Hz | | flatness | 0.0003 | 0.035 | | zero-crossing rate | 0.047 | 0.122 | | brightness (energy above 1.5 kHz) | 0.022 | 0.141 | | percussive ratio (HPSS) | 0.036 | 0.377 |
The centroid is the spectrum's centre of mass. Flatness is 1 for white noise and near 0 for a pure tone; my tests require white noise to read at least 0.3. The bowed cello is close to a tone; distorted guitars and cymbals push Fat Lip 111 times further toward noise.
Brightness by genre

Timbre by genre

The catch
Medians separate the extremes. The middle of the catalogue (hip-hop, pop, indie, electronic) overlaps heavily, which is why these fourteen numbers are inputs to a model, not a genre rule. And the genre labels are catalogue values, not a hand-checked set: a Spider-Man score is filed under classical.
Part 4 of 14, next: MFCCs: The 20 Numbers Every Model I Train Has to Beat.
Part 4 of 14, next: MFCCs: The 20 Numbers Every Model I Train Has to Beat.
More: LinkedIn · Instagram. Portfolio and case studies: designsbyduhart.org.
If any of this saved you an afternoon, Buy me a coffee.