Files
Sylpheed/tools/port/strip-padding
Sylpheed port agent 33bb50e80d port: stripping driver padding is exact -- the gate on S00A is cleared
The Decoder made this the gate on S00A and that was the right order: ADV plays
itself on boot and can be captured with --gpu=null at 0.96x real time, but S00A
starts ~4.5 s after (A) on a save slot, which needs a driven run, which needs
screens, which rules out --gpu=null. So S00A is necessarily the 0.70x rendered
route with ~10% additive padding, and is only worth a boot if stripping is exact.

It is. A real music+SFX bed -- 137.37 s, carrying 454 genuine zero runs of its
own -- had 1149 holes inserted at 8.37/s to +9.9% length, matching the observed
ALSA profile, then was stripped and correlated in the low band:

  original vs itself      r 1.000  lag   0.0 s  margin +0.141   ceiling
  PADDED   vs original    r 0.436  lag -12.2 s  margin +0.006   destroyed
  STRIPPED vs original    r 1.000  lag   0.0 s  margin +0.142   recovered
  stripped vs orig-also-stripped   r 1.000      margin +0.143

Two things worth reading off that. Padding at that profile destroys correlation
completely -- r 0.436 in the known-absent regime -- which independently confirms
on a file whose contents I control that the earlier captures were unusable for
the reason claimed and not for some other one. And recovery does NOT require
stripping both sides: the stripped capture matches the UNSTRIPPED source at the
ceiling, so the port's reference assets never need touching.

`tools/port/strip-padding` implements it, and its header leads with when the
operation is vandalism rather than with what it does: PulseAudio's monitor
SUBSTITUTES silence and deleting those holes repairs nothing, while Xenia's ALSA
writer PADS and removing that is exact. Running it on the wrong artefact would
look like it worked.

Its output is byte-identical to the control's own stripping, so the tool and the
experiment are one operation rather than two implementations that agree.

Not licensed by this: stripping removes genuine silence too and cannot tell them
apart. Here the genuine runs total 0.71 s in 137 s and cost nothing measurable;
on material that is mostly silence they would.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N7FiFFFwbvG2uxdcEh8HyF
2026-08-29 17:04:05 +00:00

68 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Remove driver-inserted silence from a capture, exactly.
#
# tools/port/strip-padding in.wav out.wav
#
# WHEN THIS IS VALID, AND WHEN IT IS VANDALISM. The distinction is the whole
# tool and getting it backwards destroys the artefact:
#
# * PulseAudio's monitor SUBSTITUTES silence. It advances on a wall clock and
# replaces audio that existed when the producer was late. Information is
# gone; deleting the holes compresses time unevenly and repairs nothing.
# DO NOT RUN THIS ON A MONITOR CAPTURE.
# * Xenia's ALSA writer PADS. It inserts silence between samples the guest
# emitted when its ring is empty (`alsa_audio_driver.cc:359`). Nothing is
# lost and nothing is overwritten, so removing the padding is EXACT -- it
# hands back the contiguous stream the guest produced.
#
# CONTROLLED, not argued. A real music+SFX bed (137.37 s, with 454 zero runs of
# its own) had 1 149 holes inserted at 8.37/s to +9.9 % length, matching the
# observed ALSA profile, then was stripped:
#
# original vs itself r 1.000 lag 0.0 s margin +0.141 [ceiling]
# PADDED vs original r 0.436 lag -12.2 s margin +0.006 [destroyed]
# STRIPPED vs original r 1.000 lag 0.0 s margin +0.142 [recovered]
#
# Frame counts: original 6 593 984, stripped 6 559 880, and the original stripped
# of its own genuine zero runs 6 560 044 -- a difference of 164 frames, 3.4 ms in
# 137 s, from inserted holes abutting genuine ones and merging.
#
# ⚠️ It removes GENUINE silence too, and cannot tell the two apart -- that is why
# the reference above is the unstripped original: recovery does not depend on
# stripping both sides. On this material the genuine runs total 0.71 s in 137 s
# and cost nothing measurable. On material that is mostly silence they would.
set -euo pipefail
in="${1:?usage: strip-padding IN.wav OUT.wav}"; out="${2:?usage: strip-padding IN.wav OUT.wav}"
python3 - "$in" "$out" <<'PYEOF'
import array, struct, sys, wave
src, dst = sys.argv[1], sys.argv[2]
w = wave.open(src); ch = w.getnchannels(); rate = w.getframerate()
if w.getsampwidth() != 2:
print("strip-padding: 16-bit PCM only (got %d-bit)" % (w.getsampwidth()*8)); raise SystemExit(2)
n = w.getnframes(); a = array.array('h'); a.frombytes(w.readframes(n)); w.close()
MIN = max(1, rate // 1000) # a gap is a run, not a sample
sil = bytearray(n)
for f in range(n):
b = f * ch
if not any(a[b+c] for c in range(ch)): sil[f] = 1
keep = array.array('h'); f = 0; removed = 0; holes = 0
while f < n:
s = f
if sil[f]:
while f < n and sil[f]: f += 1
if f - s < MIN: keep.extend(a[s*ch:f*ch])
else: removed += f - s; holes += 1
else:
while f < n and not sil[f]: f += 1
keep.extend(a[s*ch:f*ch])
k = len(keep) // ch
o = wave.open(dst + ".partial", "wb") # temp name, renamed on completion
o.setnchannels(ch); o.setsampwidth(2); o.setframerate(rate)
o.writeframes(keep.tobytes()); o.close()
import os; os.replace(dst + ".partial", dst)
print("%s: %d frames (%.3f s) -> %s: %d frames (%.3f s)"
% (src, n, n/rate, dst, k, k/rate))
print(" removed %d run(s) totalling %.3f s (%.2f %% of the input)"
% (holes, removed/rate, 100.0*removed/n))
PYEOF