Designs by Duhart All writing

·1 min read·audioprocessing · machinelearning · musictech · featureengineering · datascience

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.

Cover slide: Classical vs Punk: Why They Sound Different, in Numbers. Bottom left, an "Interviewing at" badge with the logos of Spotify, Apple Music, YouTube Music, SoundCloud.

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

Numbers come from the stored records and the catalogue medians; sources at the end.
Opening frame of the video: Classical vs Punk: Why They Sound Different, in Numbers
Numbers come from the stored records and the catalogue medians; sources at the end. Watch the video: https://designsbyduhart.org/blog/classical-vs-punk-timbre-in-numbers/

timbre_analysis.py: the timbre descriptors (excerpt)

python
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

Slide 3 of 8 of "Classical vs Punk: Why They Sound Different, in Numbers", near-black background, white Inter type with mono labels. Brightness, by genre. Median spectral centroid over my catalogue. Classical sits low, punk sits highest. Chart or diagram from the video at its final state.
Median spectral centroid per catalogue genre; the number of tracks is in brackets.

Timbre by genre

Median spectral centroid per genre over my catalogue. Hover for flatness and percussive share. Open full screen
Cover slide: Classical vs Punk: Why They Sound Different, in Numbers. Bottom left, an "Interviewing at" badge with the logos of Spotify, Apple Music, YouTube Music, SoundCloud.
Median spectral centroid per genre over my catalogue. Hover for flatness and percussive share. Interactive version: https://designsbyduhart.org/blog/classical-vs-punk-timbre-in-numbers/

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.