fix(audio,punch): true-peak headroom and punch-in calibration

Two defects affecting EVERY clip, both measured on the corpus.

Audio: loudnorm hits the level target (median -14.2 LUFS, 13/14 inside the
band) but its true-peak ceiling is enforced BEFORE the AAC encode, and the
codec then adds inter-sample peaks on top. At TP=-1.5 one clip came out at
+0.2 dBTP, i.e. clipping. TP=-2.0 removes it at no cost to level (12/14 in
band); -3.0 does cost level (8/14). Tried and rejected: an alimiter afterwards
(limits sample peaks, not inter-sample, and measured WORSE at +0.7) and
two-pass loudnorm with linear=true (+0.4, still clipping).

Punch-in: the shipped defaults produced 8.4 punches per minute, one every seven
seconds. Swept both knobs over 20 clips; 18s/0.60 gives a median of 2.8 and a
max of 3.0, chosen for having the tightest spread rather than just the right
median.
This commit is contained in:
juancarlos.cavero 2026-07-31 13:28:46 +02:00
parent f88d843fda
commit 38f37137ee
2 changed files with 36 additions and 8 deletions

View file

@ -63,11 +63,25 @@ METADATA_SCRUB = ["-map_metadata", "-1", "-map_chapters", "-1",
# which means the quiet ones just sound thin next to everything else in the # which means the quiet ones just sound thin next to everything else in the
# feed — the loud ones aren't rewarded, the quiet ones are punished. # feed — the loud ones aren't rewarded, the quiet ones are punished.
# #
# I=-14 matches the platforms' target, TP=-1.5 leaves headroom so their own # I=-14 matches the platforms' target, LRA=11 is the usual allowance for speech.
# re-encode can't clip, LRA=11 is the usual allowance for speech. Applied at # Applied at the clip cut, where the audio is being encoded to AAC anyway, so it
# the clip cut, where the audio is being encoded to AAC anyway, so it costs # costs nothing extra. AUDIO_NORMALIZE=0 turns it off.
# nothing extra. AUDIO_NORMALIZE=0 turns it off. #
LOUDNORM_FILTER = "loudnorm=I=-14:TP=-1.5:LRA=11" # TP=-2.0, not the -1.5 that matches the platforms' own advice, because the
# ceiling is enforced BEFORE the AAC encode and the encoder then adds
# inter-sample peaks on top. Measured over 14 corpus clips (31-jul-2026):
#
# TP=-1.5 peak reached +0.2 dBTP, 1 clip clipping, 8 above -1.0
# TP=-2.0 peak reached -0.3 dBTP, 0 clipping, 5 above -1.0
# TP=-3.0 peak reached -0.9 dBTP, 0 clipping, 1 above -1.0
#
# -3.0 also costs level: only 8 of 14 stayed inside -15..-13 LUFS versus 12 at
# -2.0, and level is what the listener notices. Two other fixes were tried and
# do NOT work, so don't reach for them again: an `alimiter` after loudnorm
# (limits sample peaks, not inter-sample, and measured WORSE at +0.7), and
# two-pass loudnorm with linear=true (+0.4, still clipping). The overshoot is
# the codec's, so the only lever is headroom.
LOUDNORM_FILTER = "loudnorm=I=-14:TP=-2.0:LRA=11"
def audio_encode_args(): def audio_encode_args():

View file

@ -36,14 +36,28 @@ FALL_SECONDS = 0.55
# Never punch twice inside this window. Two pushes in quick succession read as a # Never punch twice inside this window. Two pushes in quick succession read as a
# glitch, and the second one lands before the first has released. # glitch, and the second one lands before the first has released.
MIN_GAP_SECONDS = 4.0 #
# Audio-envelope resolution used to find beats. # Audio-envelope resolution used to find beats.
BEAT_WINDOW = 0.2 BEAT_WINDOW = 0.2
# A beat must exceed the clip's median loudness by this much of the gap to its # A beat must exceed the clip's median loudness by this much of the gap to its
# peak. Low values punch on every syllable; this keeps it to real emphasis. # peak. Low values punch on every syllable; this keeps it to real emphasis.
BEAT_PROMINENCE = 0.45 #
# These two were shipped at 4.0/0.45 and that produced 8.4 punches per minute of
# clip, one every seven seconds. That is not a push on the beat, it is a twitch.
# Swept over 20 corpus clips (31-jul-2026), punches per minute, median and max:
#
# gap prom median max gap prom median max
# 4.0 0.45 8.4 11.8 12.0 0.60 2.9 4.6
# 4.0 0.75 2.4 5.8 18.0 0.45 2.9 3.9
# 8.0 0.60 3.4 5.9 18.0 0.60 2.8 3.0
#
# 18.0/0.60 is picked for having the tightest spread, not just the right median:
# a setting whose worst case is 3.0/min never surprises anyone, while 12.0/0.60
# has the same median but can still reach 4.6 on a loud clip. No setting left a
# clip with zero punches.
MIN_GAP_SECONDS = 18.0
BEAT_PROMINENCE = 0.60
def _ease(t): def _ease(t):