Shazam vs. CLAP: What Actually Breaks When Audio Gets Messy¶
Imagine recognising a song two completely different ways. One method memorises its exact acoustic characteristics such as the precise frequency and timing of its loudest moments i.e the way Shazam has been doing since 2003. The other listens to it the way a person might, forming a general "vibe" and guestimation from a neural network trained on millions of sounds (that's LAION-CLAP).
Now play both of them the same song, but degrade the audio a little: bury it in crowd noise, pitch-shift it up a semitone, run it through a tinny lo-fi filter. Which one still knows what it's hearing?
That's the whole experiment. GTZAN's 999 tracks, degraded 17,982 different ways, fed to three systems: Shazam-style fingerprinting, a general-purpose CLAP model, and a CLAP model fine-tuned specifically on music.
TL;DR: Shazam is unmatched on noise but hits a hard wall the moment pitch shifts at all. The two CLAP models – one trained broadly, one fine-tuned for music – are effectively tied under musical transforms, where both degrade gradually rather than hitting a wall; under noise the music-tuned model is clearly ahead, though both struggle when the noise is as loud as the music. And the systems fail differently: Shazam says "no match" when unsure, while CLAP always answers – usually with a song from the right genre.
The setup, quickly¶
- Data: GTZAN – 999 tracks, 10 genres, 30s each, (almost) perfectly balanced.
- Degradations: additive noise (white/crowd/street noise at 0/10/20 dB SNR) and musical transforms (±1–3 semitone pitch shift, 3 levels of lo-fi bandpass filtering).
- Models/Contestants:
- Shazam – constellation-map fingerprinting + time-coherence matching, the real algorithm.
- CLAP General – LAION-CLAP trained broadly on speech, environmental sound, and music.
- CLAP Music – the same architecture, fine-tuned specifically on music.
- Questions asked: Can it find the exact right song (Top-1 retrieval)? Does that hold up across genres? And when it gets the song wrong, does it at least land on the right genre – or, in Shazam's case, does it say "no match" instead?
Every system is shown with the same six charts – overall Top-1 by noise and by transform, Top-1 by genre for each, and, for each, the share of misses that still land in the right genre – so the sections line up chart-for-chart.
Full methodology notes live in notes.md if you want the fine print.
The dataset, in one picture¶
GTZAN is clean and mostly balanced – 100 tracks per genre, 1,000 in total. One file, jazz.00054.wav, is corrupted at the source (fails to decode – "format not recognised") and is excluded everywhere in this analysis, so jazz actually contributes 99 tracks and the working dataset is 999 clean originals. Every augmentation was applied to every one of those 999 tracks, which is why genre counts below are even everywhere except jazz, and why you'll see "99" instead of "100" anywhere jazz is broken out individually later on.
Section 1 – Shazam¶
Shazam's approach is treating a song like a fingerprint. It grabs the loudest peaks in the frequency spectrogram, timestamps them precisely, and hashes pairs of them together. Match enough of those exact (hash, timing) pairs and you've found your song.
Shazam's matcher only ever returns a single best guess or "no match", so the comparison throughout this notebook sticks to the metrics all three systems share: Top-1 retrieval, and how often a miss still lands in the right genre.
Where this system comes from¶
Unlike the CLAP sections below, there's no pretrained checkpoint here — this is a from-scratch implementation of Wang (2003)'s landmark-hashing algorithm (the original Shazam paper), built for this project in Shazam/src/. Nothing is downloaded or fine-tuned; every number in this section comes from custom DSP and hashing code running against the GTZAN audio directly. The pipeline, in order:
audioprocessing.py– loads the audio, converts to mono, applies a 20 Hz–5 kHz Butterworth bandpass, resamples to 11,025 Hz, then computes a magnitude spectrogram (1024-sample Hamming-windowed FFT frames, 50% overlap).fingerprinting.py(extract_peaks) – finds the strongest frequency bin in each of 6 logarithmic bands per time frame, then keeps only the peaks whose magnitude exceeds the global mean (coefficient 1.0). This is the "constellation map."hashing.py(hashingAlgorithm) – for each peak (as an anchor), pairs it with up to 5 nearby peaks within a target zone (50 frames forward, ±80 frequency bins) and packs(anchor_freq, target_freq, delta_time)into a 32-bit integer hash.database.py– stores every(hash, song_id, offset)triple from indexing the full 30 s of each GTZAN original in a SQLite table, indexed onhashfor O(1)-ish lookup.identify.py(identify_audio) – fingerprints the query snippet the same way, looks up its hashes in the DB, and for each candidate song finds the most common(db_offset − query_offset)value (the time-coherence vote). The song/offset combination with the most votes wins, subject to a confidence gate (details innotes.md).
build_gtzan_db.py runs step 4 once over all 999 usable GTZAN originals (jazz.00054.wav is corrupt and is skipped); evaluate_shazam.py runs step 5 once per query file in this evaluation.
Full detail on the confidence gate (all six thresholds) is in notes.md rather than here.
Clean baseline¶
Even with no augmentation at all, Shazam identifies the correct track only 77.9% of the time — not the ~100% you'd expect from a deterministic exact-match algorithm on unmodified audio. The shortfall isn't random: it's concentrated in loop-heavy genres. Hip-hop sits at 50% and jazz at 68% even clean, while blues and rock hit 95%. That's the coherence gate doing its job — rejecting ambiguous time-alignments — but it has a real, measurable cost even before any degradation is applied.
Overall Top-1 retrieval accuracy¶
Additive noise is Shazam's strongest condition: 70.2% at 0 dB SNR (noise as loud as the music itself) rising to 77.7% at 20 dB. It's close to the clean baseline (77.9%) at the gentler SNRs — loud spectral peaks do survive noise mixing almost untouched, as designed — but 0 dB visibly costs several points versus clean.
Musical transforms are a different story entirely, and the two transform types behave very differently. Pitch shift is a wall: accuracy is 0.07% across all six pitch conditions (±1–3 semitones, up and down) — a small number of accidental hits, not real robustness. A ~6% frequency shift moves every peak out of its hash bin, so there's structurally nothing left to match. Lo-fi filtering does not behave the same way: it lands at 55.2% (L1) → 44.5% (L2) → 35.0% (L3) — a real, gradual decline, not a second wall. The bandpass filter trims some peaks but leaves plenty of mid-band structure intact. Averaged across all three transform types (lo-fi + both pitch directions), overall accuracy is 15.0%, against 75.0% for noise overall (70.2% at the worst 0 dB condition).
Retrieval accuracy by genre¶
Genre matters a lot under noise. Accuracy ranges from 43.3% (hip-hop) to 94.4% (blues) averaged across all nine noise conditions (three noise types × three SNR levels), a >50-point spread. This tracks the clean-baseline pattern exactly: loop-based, rhythmically repetitive genres (hip-hop 43%, reggae 53%, jazz 67%) sit well below genres with more continuously-evolving spectral content (rock 94%, blues 94%, disco 85%). The mechanism is the same one behind the clean-baseline shortfall — repeated musical structure creates competing in-song time-alignments that the coherence gate can reject — and noise doesn't fix or worsen it much, it just rides on top.
The transform heatmap shows pitch-shift as a flat wall of ~0.00 for every genre, in both directions. Lo-fi tells a very different story: classical holds up best (80.3% averaged across all three severities), with blues (65.7%) and country (63.7%) close behind, while metal (12.0%) and hip-hop (12.3%) are the weakest. Hip-hop is weak everywhere for the loop-structure reason above; metal is the surprise – mid-table under noise (77%) but bottom under lo-fi, plausibly because its dense, distorted spectrum puts many of its strongest peaks in the frequency ranges the bandpass removes. Classical's slower-moving, less repetitive content plays to the coherence gate's strength once the peaks themselves survive the filter.
Misses that land in the right genre¶
These charts look only at the queries that missed, and ask what share of them still pointed at a song from the right genre. A "no match" counts as not landing in the right genre. For Shazam the share is essentially zero (0–0.9% in every condition), because when Shazam misses it almost never names a song at all: the misses are "no match" (25% of noise queries, 85% of transform queries). Across all 17,982 augmented queries, Shazam named a wrong song only 25 times, and every one of those 25 was from the right genre, which is consistent with same-genre tracks sharing similar enough peak structure to produce a false alignment. Shazam fails safely: it goes quiet rather than guessing.
Section 2 – CLAP Music¶
CLAP Music is LAION-CLAP fine-tuned specifically on music (music_audioset_epoch_15_esc_90.14.pt) – the specialist checkpoint. It doesn't do exact hash matching like Shazam; it embeds audio into a vector space and finds the closest match by cosine similarity. Same test set and same charts as Shazam. Unlike Shazam, CLAP has no "no match" option – it always returns its nearest neighbour.
This checkpoint uses a different, larger audio encoder (HTSAT-base) than the CLAP General checkpoint, and ships as a raw training snapshot rather than a ready-to-load state dict — loading it correctly needs the right encoder architecture plus a small amount of unwrapping. Full detail is in notes.md.
Overall Top-1 retrieval accuracy¶
Accuracy climbs from 15.7% at 0 dB to 76.6% at 20 dB – a normal similarity-search curve: near-useless when the noise is as loud as the music, close to Shazam once it's 20 dB quieter. Street noise is the easiest noise type (84% at 20 dB); crowd and white noise are both noticeably harder.
Transforms degrade gradually rather than hitting a wall: 44.5% at L1 down to 21.1% at L3 (32.4% overall). Lo-fi has the widest range, from 67.4% at the mildest severity down to 19.0% at the harshest; pitch shift sits in a narrower 18–37% band, with pitch-up (26–37%) consistently easier than pitch-down (18–30%).
Retrieval accuracy by genre¶
Under noise, genre matters less here than it did for Shazam (a 28-point spread vs. Shazam's 51), but the ranking is different: rock (61.2%) and metal (59.6%) hold up best and classical (33.6%) lags, whereas Shazam handles classical well (82%) and struggles most with hip-hop – which CLAP Music handles fine (51%). Different systems, different weaknesses.
Under transforms the genre ranking flips again: classical (52.7%) is now the strongest genre by a wide margin, metal (22.7%) the weakest. Most of the heatmap stays in double digits; the six cells that drop below 10% are all at L2–L3 (mostly pitch-down, plus lo-fi L3 for country and metal), with pop at pitch-down L3 the single cell that hits zero.
Misses that land in the right genre¶
These charts look only at the queries that missed, and ask what share of them still landed on a song from the right genre. Because the denominator is the misses, not all queries, the measure doesn't depend on how accurate the model is, and it tracks how well genre survives the degradation. Under noise it falls from 89.9% at 20 dB to 74.7% at 10 dB and 50.9% at 0 dB: mild noise only nudges the embedding to a neighbouring same-genre track, while loud noise pushes it somewhere far less related. Street noise preserves genre best (94% of misses at 20 dB, 64% at 0 dB), crowd noise worst (87% → 38%). Under transforms it falls from 67.0% at L1 to 57.4% at L3. Lo-fi keeps genre best (89% → 63%); pitch-down keeps it worst (60% → 51%). Even at the harshest settings, at least half of the misses are still in the right genre, more than five times what random guessing across ten genres would give (~10%).
Section 3 – CLAP General¶
CLAP General is the same architecture as CLAP Music, but trained broadly on speech, environmental sound, and music together (630k-audioset-best.pt) – the generalist checkpoint, never fine-tuned to specialise on music. Same tests, same layout as the CLAP Music section above, so the two are directly comparable chart-for-chart.
Overall Top-1 retrieval accuracy¶
Noise: 8% at 0 dB climbing to 68% at 20 dB – the same shape as CLAP Music's curve but consistently lower (CLAP Music: 16% → 77%). Street noise is the easiest noise type for both CLAP models.
Transforms: 41% at L1 down to 24% at L3, averaged across lo-fi and both pitch directions. Lo-fi runs 60% → 28%; pitch shift sits in a 22–33% band. That's almost identical to CLAP Music overall (32.7% vs. 32.4%) – the two CLAP models only really differ under noise, where CLAP Music is ahead.
Retrieval accuracy by genre¶
Rock (48% averaged across all noise conditions) and metal (45%) hold up best, classical (30%) is weakest – the same top and bottom as CLAP Music, just lower across the board. Every genre craters at 0 dB (3–15%, vs. 9–25% for CLAP Music).
Classical is again the strongest genre under transforms (51%), disco the weakest (22%). Only three cells drop below 10%, all at pitch-shift L3; nothing hits zero. Lo-fi is handled noticeably better than pitch shift across the board (44% vs. 27%), which lines up with the idea that an embedding can still recognise a track through a narrowed frequency band more easily than through a shifted one.
Misses that land in the right genre¶
The same pattern as CLAP Music, a few points lower throughout. Under noise the share of misses landing in the right genre falls from 83.7% at 20 dB to 63.4% at 10 dB and 36.2% at 0 dB; under transforms it falls from 62.6% at L1 to 55.5% at L3. Lo-fi again preserves genre best (79% → 64%) and pitch-down worst (55% → 49%). The biggest gap to CLAP Music is at 0 dB noise (36% vs. 51%), the same condition where its Top-1 accuracy is also furthest behind. When CLAP General misses, it degrades towards an unrelated answer a little sooner than the music-tuned model does.
Section 4 – Review: So, Who Wins?¶
These two charts are the whole story side by side. Under noise, Shazam stays within 8 points of its clean baseline at every SNR – far ahead at 0 and 10 dB, though CLAP Music almost catches it at 20 dB (77.7% vs. 76.6%). Both CLAP models fall away sharply as noise gets louder. Under transforms the picture splits by transform type: on pitch shift Shazam drops to ~0% while both CLAP models hold 18–37%; on lo-fi all three degrade gradually, with the CLAP models ahead at the mildest level and Shazam ahead at the harsher two (L3: Shazam 35%, CLAP General 28%, CLAP Music 19%).
Summary table¶
| System | Top-1, Noise (0 dB) | Top-1, Noise (overall) | Top-1, Lo-fi (L1→L3) | Top-1, Pitch (all) | Misses in right genre (noise / transform) | How it fails |
|---|---|---|---|---|---|---|
| Shazam | 70% | 75% | 55% → 35% | ~0% | 0.5% / 0.2% | Pitch: hard wall. Otherwise says "no match" rather than guessing. Weak on loop-heavy genres even clean. |
| CLAP Music | 16% | 50% | 67% → 19% | 18–37% | 64% / 62% | Gradual decline; misses mostly stay in the right genre |
| CLAP General | 8% | 38% | 60% → 28% | 22–33% | 54% / 59% | Gradual decline; misses mostly stay in the right genre |
(Shazam's clean, unaugmented baseline is 77.9% for reference – the CLAP models don't have a comparable clean row, see the fine print.)
What we learned¶
Shazam's weakness is narrow and absolute. It memorises exact time-frequency coordinates, so anything that moves every peak – a pitch shift of even one semitone – leaves nothing to match. Anything that leaves the peaks where they are – added noise, or a bandpass that only removes some of them – is handled well. Lo-fi is the in-between case: a real, gradual decline (55% → 35%), not a wall – and at the harsher lo-fi levels Shazam actually beats both CLAP models.
Shazam also has a failure mode that has nothing to do with degradation: repetitive music. Hip-hop (43% under noise) and reggae (53%) sit far below blues and rock (94%), and the same gap is there on clean audio. Loop-based structure creates several plausible time-alignments, and the matcher's confidence gate rejects the ambiguity as "no match."
The two CLAP models are much closer than their training would suggest. Under transforms they're effectively tied (32.4% vs. 32.7% overall); CLAP Music is better at mild lo-fi and at pitch-up, CLAP General at harsh lo-fi and at pitch-down. Under noise, the music-specialist model is clearly ahead (50% vs. 38% overall). Fine-tuning on music bought noise robustness without costing anything on transforms.
The systems fail in fundamentally different ways. Almost none of Shazam's misses land in the right genre, because it almost never commits to a wrong answer: when it isn't sure, it says nothing. The CLAP models have no reject option: they always return a nearest neighbour, and when that's the wrong song it's still the right genre more than half the time (54–64% of misses overall). That share shrinks as the audio gets worse, from ~84–90% of misses under mild noise to 36–51% at 0 dB, so genre survives degradation better than exact identity does, but not indefinitely. It also means CLAP's mistakes look exactly like its correct answers from the outside.
Genre difficulty is system-specific. Under noise, Shazam handles classical well (82%) while it's the CLAP models' worst genre; hip-hop is Shazam's worst but mid-table for CLAP Music. Under transforms, classical is the best genre for all three systems. Loop-heavy genres hurt Shazam everywhere; dense genres like metal and disco hurt CLAP under transforms.
Takeaway: exact fingerprinting and learned embeddings are complementary, not competing. Shazam is the right tool when the query is the original recording under noise or filtering, and it fails safely. CLAP is the only option once the pitch has moved, and degrades gracefully – but always gives an answer whether or not it has one. Between the two CLAP models, music fine-tuning helped under noise and cost nothing under transforms.
The fine print¶
Four caveats worth knowing before you take these numbers to the bank:
- Shazam gets a small home-field advantage — the test audio has no MP3/AAC re-encoding or room echo, both of which a real "noisy bar" query would have. Relative comparisons still hold since all three systems see the same augmented files.
- CLAP embeds the full 30 s augmented clip; Shazam only gets a random 10 s snippet. CLAP's numbers are technically upper bounds under a stricter, apples-to-apples protocol.
- Shazam's numbers depend heavily on its confidence gate: a stricter gate trades correct matches for fewer wrong ones, and is what drives the loop-heavy-genre shortfall. Thresholds are documented in
notes.md. - Only Shazam has a clean (unaugmented) baseline in this notebook. For CLAP, a clean retrieval baseline would be tautological: the retrieval index is the clean embeddings, so querying with them again gives cosine similarity ≡ 1.0 and ~100% Top-1 by construction.
More detail on all four in notes.md.