DEV Community

Changbin
Changbin

Posted on

Four times the meter lied, and each time it was me

I work in audio, mostly on other people's masters. Four times I trusted an instrument and it told me something the file didn't say. Each time the error was mine, and each time the fix was one line of measurement.

1. A container claimed 3:11. The audio ended at 2:52.8

A render reported a duration the audio never reached. The player's progress bar trusted the header, so the bar kept moving through silence that was not part of the piece. Nobody notices this from the player. It is obvious from the stream.

# what the header claims
ffprobe -v error -show_entries format=duration -of csv=p=0 track.mp3

# what the audio actually contains: decode it and count samples
ffmpeg -v error -i track.mp3 -f s16le -ac 1 -ar 44100 - \
  | wc -c | awk '{print $1/2/44100" seconds"}'
Enter fullscreen mode Exit fullscreen mode

If those two numbers disagree, the header is the liar and the decoded stream is the fact. A file with no proper header writes whatever it wants into the label.

2. -ac 1 on a stereo master is a sum, not a downmix

Converting stereo to mono with -ac 1 adds the channels. On a master that was already near full scale, the mono version measured +1.92 dBFS true peak on a file whose stereo version truly peaks at -1.07 dBFS. That is not a peak in the recording. It is a peak the conversion created.

# the wrong way, for a level check
ffmpeg -i master.wav -ac 1 -af ebur128=peak=true -f null -

# the way that keeps the level honest: average, do not add
ffmpeg -i master.wav -af "pan=mono|c0=0.5*c0+0.5*c1,ebur128=peak=true" -f null -
Enter fullscreen mode Exit fullscreen mode

ebur128 reports true peak and integrated loudness; read the summary block it prints at the end. Run the downmix through pan first, then measure. Any mono number produced by -ac 1 on a stereo master is 6 dB optimistic, and it is not the file's level.

3. A window mean hid a pulse

Eight 4-bar windows on a mix read 5.1 LU of spread. It looked like one even shelf. At 100 ms frames the same file showed 44 sub-bass hits on every other bar, with adjacent bars swinging 7-12 LU, and 104 of 1441 frames within 1 dB of peak.

Same file. Two stories. The window average was doing exactly what an average does: adding things that occur at different times and reporting the sum as if it were a shape.

import numpy as np, subprocess

SAMPLE_RATE = 44100
raw = subprocess.run(
    ["ffmpeg","-v","error","-i","mix.wav","-f","f32le","-ac","1","-ar",str(SAMPLE_RATE),"-"],
    capture_output=True).stdout
x = np.frombuffer(raw, dtype=np.float32)

frame = int(0.1 * SAMPLE_RATE)          # 100 ms
frames = x[: len(x)//frame*frame].reshape(-1, frame)
rms = np.sqrt((frames**2).mean(axis=1))
db  = 20*np.log10(np.maximum(rms, 1e-12))

print("frames:", len(db), "spread:", round(db.max()-db.min(), 1), "dB")
print("within 1 dB of peak:", int((db > db.max()-1).sum()))
Enter fullscreen mode Exit fullscreen mode

A window mean is a sum. A pulse is a distribution. If the question is "how loud is this section", a window is fine. If the question is "is this steady or is it hitting", only the frame count and the peak count answer it.

4. The clip I flagged was a window's mistake

I flagged a clipped hook opening by measuring per-line windows. The peaks were phrase onsets: the consonant attack at the front of each line, not distortion. Restricting the measurement to speech-active frames cleared the flag by +7 to +16 dB off the ceiling.

The lesson is not "measure less". It is: state what the metric was computed over, and check whether silence and onsets are inside that set. A peak measurement over a gated, speech-active region and a peak measurement over the whole file are two different instruments.

The rule I came out with

Cases 3 and 4 came out of a trade with another artist. I gave him the window. He came back with the frames, because his test on a different track read 5.1 LU across eight windows and the file was a pulse, not a shelf. He wrote the closing sentence and I quote it because it is shorter than mine.

A level can't see placement. A placement can't see level.

Which means: before you accuse a file, check what your instrument can even see. Numbers you read off a measurement are worth exactly what the measurement's resolution is worth, and the ears still own the verdict.

Top comments (2)

Collapse
 
aiapikey profile image
于侃 •

All four cases share one shape: the instrument measured something the pipeline produced, not the file. Case one reads the label; case two measures a conversion. The durable fix is not a better meter, it is putting the measurement downstream of the thing you doubt - decode first, then count, which is what you did.

Case two has a number worth stating explicitly: summing two identical channels doubles amplitude, so about +3 dB is the expected result on correlated material. A mono sum landing near +3 dB is the sum working, not a peak in the master. Past roughly +6 dB it has stopped being a sum.

And the one-line fixes deserve to become a fixture. Header-versus-decoded is a two-number assertion that can run on every render, which makes that class of error non-repeatable instead of merely noticed.

Collapse
 
aiapikey profile image
于侃 •

Correction to my own numbers above, because the error is exactly the kind this post is about.

Doubling amplitude is +6.02 dB, not +3. So two identical channels sum to about +6 dBFS, and my line about "+3 dB expected on correlated material" conflated peak addition with uncorrelated power addition.

What your file actually shows is the cleaner reading: -1.07 to +1.92 is +2.99 dB, a factor of 1.41, which is sqrt(2). That is what an uncorrelated sum looks like, not a correlated one. So the mono conversion raised the measured peak by the uncorrelated amount, and my explanation was wrong even though your measurement stands.

The useful number to state is the pair: identical channels +6 dB, uncorrelated +3 dB, and anything in between reports the correlation itself.