If you inspect a FLAC file with ffprobe or a media player and see 16-bit / 44.1 kHz / 942 kbps, you still do not know whether the audio is lossless. Transcoding a 128 kbps MP3 into FLAC does not restore discarded spectral data; it simply wraps the decoded, quantized PCM stream inside a lossless entropy coder. The resulting file passes every structural integrity check—valid fLaC framing, clean CRC-16 frame checksums, and a matching PCM MD5—while carrying a high bitrate tag generated strictly from the encoded file size divided by duration.

Catching a lossy-to-lossless transcode requires two layers of inspection: raw binary header verification and statistical spectral forensics. Both run comfortably in the browser without uploading files or installing desktop spectrogram utilities like Spek.

Step 1: Parsing Raw STREAMINFO Before Decoding

Before invoking Web Audio's decodeAudioData, read the raw ArrayBuffer to verify the container's true PCM geometry. Relying solely on AudioBuffer.sampleRate can mislead you because browsers often resample decoded buffers to the host hardware clock (typically 48 kHz).

A valid FLAC stream begins with the 4-byte ASCII signature fLaC (0x664C6143), immediately followed by a 4-byte metadata block header and the mandatory 34-byte STREAMINFO block (type 0). The sample rate, channel count, bit depth, and total sample count are bit-packed across bytes 18 to 25 of the file:

JavaScript

function parseFlacStreamInfo(buffer) { const view = new DataView(buffer); if (view.getUint32(0) !== 0x664c6143) throw new Error("Not a FLAC stream"); const blockType = view.getUint8(4) & 0x7f; if (blockType !== 0) throw new Error("First metadata block is not STREAMINFO"); // Bytes 18..25 hold: 20-bit sampleRate | 3-bit (ch-1) | 5-bit (bps-1) | 36-bit totalSamples const hi = view.getUint32(18); const lo = view.getUint32(22); const sampleRate = hi >>> 12; const channels = ((hi >>> 9) & 0x07) + 1; const bitsPerSample = ((hi >>> 4) & 0x1f) + 1; const totalSamples = ((hi & 0x0f) * 2 ** 32) + lo; return { sampleRate, channels, bitsPerSample, totalSamples, nyquist: sampleRate / 2 }; } 

This establishes the true Nyquist limit (fN​=fs​/2, or 22,050 Hz for Red Book audio) and prevents false alarms on legitimately 32 kHz source recordings.

Step 2: Brickwall Shelves vs. Natural Analog Roll-Off

Lossy psychoacoustic codecs (MP3, AAC, Ogg Vorbis) discard high-frequency MDCT bins to preserve bit budget for midband masking thresholds. In LAME MP3 encoders, scalefactor band 21 (sfb21, above 16 kHz) lacks its own scalefactor, making high-frequency coding disproportionately expensive. Consequently, encoders apply steep low-pass brickwall filters at predictable cutoffs:

Codec Profile Typical Brickwall Shelf Forensic Signature
128 kbps MP3 (CBR) 15.8 – 16.2 kHz Sudden 35–50 dB cliff; flat digital silence above 16.5 kHz
192 kbps MP3 / AAC-LC 17.8 – 18.5 kHz Sharp shelf with sporadic energy islands from temporal noise shaping
320 kbps MP3 (CBR) 19.8 – 20.5 kHz Steep drop near 20 kHz, often with visible sfb21 notch gaps
True Lossless (44.1 kHz) No brickwall Gradual 6–12 dB/octave roll-off extending to 21.5–22.05 kHz

Authentic analog and lossless digital recordings rarely drop to −∞ dBFS at a straight horizontal frequency line. Cymbal transients, room air, tape hiss, and microphone self-noise decay smoothly toward Nyquist.

Step 3: 80-Slice 2048-Point FFT and 90th-Percentile Band Math

Scanning an entire 5-minute track frame-by-frame is unnecessary. Instead, extract M=80 evenly spaced slices across the active 5%–95% duration of the mono-summed signal. Each slice takes N=2048 samples multiplied by a Hann window:

w[n]=0.5(1−cos(N−12πn​))

At fs​=44,100 Hz, the frequency resolution is Δf=204844100​≈21.533 Hz/bin. Compute each bin's power in dBFS:

Pm​[k]=20log10​(N/2∣Xm​[k]∣​+10−12)

Do not average Pm​[k] across the 80 slices, and do not take the maximum. Arithmetic mean drags high-frequency energy down during quiet verses, while maximum gets fooled by a single transient click or dither spike. Take the 90th percentile (P90​[k]) across the 80 slices for every bin k. This isolates sustained energetic passages (choruses, hi-hats, vocal sibilance).

Next, evaluate median P90​ levels across a reference band Bref​=[10,14] kHz and three diagnostic shelf bands:

  • B16​=[16.5,17.8] kHz
  • B18​=[18.5,19.8] kHz
  • B20​=[20.5,21.8] kHz

Compute the band drop Δb​=mediank∈Bb​​(P90​[k])−mediank∈Bref​​(P90​[k]). When median(Bref​) sits above −55 dBFS (confirming the track actually has bright program material) and B16​ plunges below −85 dBFS with Δ16​≤−32 dB, you have a definitive 128 kbps transcode. Similar calibrated thresholds on B18​ and B20​, combined with local spectral slope ∂f∂P90​​, distinguish 192 kbps and 320 kbps shelves from dark acoustic recordings.

Practical Browser-Local Workflow

Running this exact STREAMINFO parser and 80-slice FFT forensic pass requires zero server infrastructure. You can verify suspicious downloads directly in RAM—with no file uploads and no Spek installation—using AIAC's Fake FLAC Checker. Once you confirm a master is genuinely lossless and need compact delivery files where you control the exact encoding bitrate rather than inheriting unknown generational loss, AIAC's FLAC to MP3 Converter handles the transcoding 100% locally in the browser as well.