SAURON's "coolant flush sound glitched and perma" is one instance of a systemic
defect. SetupPatch (L4AUDLVL.cpp) decided looping from the SAMPLE flag alone:
AL_LOOPING = (info.loop != ForceStatic)
That armed every non-ForceStatic sample -- 224 of the 603 authored zones,
including unmistakable one-shots -- as an OpenAL source that never ends on its
own. Any such sound whose note-off never arrives plays forever. Measured 1946
LoopAtWill x Transient arming events in one short session.
The sample flag expresses PERMISSION; the SOURCE decides. Three facts [T1]:
* the enum's own comments (L4AUDLVL.h:14-19) -- LoopAtWill = "will play once
OR LOOP AS DESIRED", ForceStatic = "plays only once EVEN IF LOOPED" (a
veto), LoopAlways = "ramp up and then down";
* LoopAtWill is enum value 0, i.e. the DEFAULT an unauthored sample receives
(WTPresets.cpp:37) -- it cannot mean "loop forever";
* LoopAlways, the real always-loop, is used by ZERO shipped samples.
"As desired" is the source's authored AudioRenderType (Transient=one-shot vs
Sustained=held), streamed from AUDIO*.RES (AUDLVL.cpp:28) and already consulted
by the renderer (L4AUDRND.cpp:567, AUDREND.cpp:184). SetupPatch now takes it,
threaded from all three L4AudioSource call sites (Direct/Dynamic3D/Static3D).
New rule: LoopAlways->1, ForceStatic->0, LoopAtWill->the source's render type.
MEASURED before changing behaviour (BT_LOOP_AUDIT=1, scratchpad/loopaudit.py):
LoopAtWill x Transient -> loop=0 (was 1) 1946 events
LoopAtWill x Sustained -> loop=1 unchanged 65 events
ForceStatic x Transient -> loop=0 unchanged 292 events
The engine loops (EngineAccel07_z0..z2, EngineMotor01, EnginePower01) are all
LoopAtWill/Sustained and PRESERVED -- no regression there. All 24 reclassified
samples are genuine one-shots: laser charge/fire/explosion/loaded, missile
loading, engine shift, coolant pressure inc/dec.
A/B PROOF (scratchpad/loopab.py, same session both arms, only BT_LOOP_LEGACY
differs), asking the engine's own BT_AUDIO_DUMP what is still playing with
loop=1 long after every release:
[legacy] EnginePower01, CoolantPresInc03_z2, CoolantPresDcr03_z2
[fixed] EnginePower01
The two stuck coolant sources are the reported symptom. They were eventually
reclaimed when a later trigger reused the source, which is why the bug was
intermittent -- the "perma" case is when nothing else retriggers it. The fix
removes the mechanism.
BT_LOOP_LEGACY=1 restores the old rule for a field A/B without a rebuild. The
layers to listen to are the beam sustains: LaserA/CSustain* are authored
LoopAtWill on a TRANSIENT source, so they now end with the sample instead of
looping until note-off. The render type is T1 authored data; the interpretation
that LoopAtWill defers to it is a strong reading of the enum + defaults rather
than a disassembled statement, and is flagged as such in the KB.
Plausibly bears on #32 (audio cutting in/out late in a match): a stuck looping
source holds its pool slot for the rest of the round.
Rigs: scratchpad/flushsnd.py (flush start/stop pairing), flushsnd2.py (stuck-
source hunt), loopaudit.py (the classification matrix), loopab.py (the A/B).
KB: context/wintesla-port.md audio section, context/decomp-reference.md env
table (BT_LOOP_AUDIT / BT_LOOP_LEGACY / BT_AUDIO_DUMP / BT_AUD_TAIL),
docs/AUDIO_FIDELITY.md F38. checkctx.py CLEAN.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
118 lines
4.0 KiB
Python
118 lines
4.0 KiB
Python
"""Gitea #51 part 2 -- catch the STUCK looping coolant source red-handed.
|
|
|
|
Part 1 (flushsnd.py) showed the flush picks one of five CoolantDump variants and
|
|
that the note-off does arrive. But three of the five variants contain a zone
|
|
authored **LoopAtWill**, and SetupPatch (L4AUDLVL.cpp:290-296) maps anything that
|
|
is not ForceStatic to **AL_LOOPING = 1** -- an OpenAL source that never ends on
|
|
its own. The enum's own comment says LoopAtWill means "will play once OR loop as
|
|
desired" (L4AUDLVL.h:16), i.e. permission to loop, not a command.
|
|
|
|
So: drive several flushes (variant selection differs per trigger), then sit idle
|
|
and use the engine's own BT_AUDIO_DUMP once-a-second playing-source dump to see
|
|
whether anything is STILL playing with loop=1 long after the last release.
|
|
|
|
PASS (bug absent) = no [playing] lines with loop=1 after the idle period.
|
|
FAIL (bug present) = a coolant source still playing with loop=1 forever.
|
|
|
|
Kills only the PID it spawns.
|
|
"""
|
|
import ctypes
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
KEYUP = 0x0002
|
|
VK_H = 0x48
|
|
user32 = ctypes.windll.user32
|
|
|
|
REPO = r"C:\git\bt411"
|
|
LOG = os.path.join(REPO, "scratchpad_flushsnd2.log")
|
|
if os.path.exists(LOG):
|
|
os.remove(LOG)
|
|
|
|
env = dict(os.environ)
|
|
env.update({
|
|
"BT_START_INSIDE": "1",
|
|
"BT_KEY_NOFOCUS": "1",
|
|
"BT_DEV_GAUGES": "1",
|
|
"BT_FLUSH_LOG": "1",
|
|
"BT_AUD_TAIL": "1",
|
|
"BT_AUDIO_DUMP": "1", # once-a-second dump of every PLAYING source + its loop flag
|
|
"BT_LOG": LOG,
|
|
})
|
|
proc = subprocess.Popen(
|
|
[os.path.join(REPO, "build", "Release", "btl4.exe"), "-egg", "LAST.EGG"],
|
|
cwd=os.path.join(REPO, "content"), env=env,
|
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
print("pid", proc.pid)
|
|
|
|
|
|
def tap(hold=0.35):
|
|
user32.keybd_event(VK_H, 0, 0, 0)
|
|
time.sleep(hold)
|
|
user32.keybd_event(VK_H, 0, KEYUP, 0)
|
|
|
|
|
|
try:
|
|
deadline = time.time() + 240
|
|
while time.time() < deadline:
|
|
if os.path.exists(LOG) and "first frame" in open(LOG, errors="replace").read():
|
|
break
|
|
time.sleep(2)
|
|
else:
|
|
print("FAIL: never reached the mission")
|
|
proc.terminate()
|
|
sys.exit(2)
|
|
time.sleep(6)
|
|
|
|
# six flushes, spaced -- the variant selection differs per trigger
|
|
for i in range(6):
|
|
tap()
|
|
print(" flush %d dispatched" % (i + 1))
|
|
time.sleep(3.0)
|
|
|
|
print(" idling 25s -- anything still playing now is STUCK")
|
|
idle_mark = len(open(LOG, errors="replace").read())
|
|
time.sleep(25)
|
|
finally:
|
|
proc.terminate()
|
|
time.sleep(1)
|
|
|
|
t = open(LOG, errors="replace").read() if os.path.exists(LOG) else ""
|
|
tail_t = t[idle_mark:] if "idle_mark" in dir() else t
|
|
|
|
tx = re.findall(r"^\[flush-tx\].*$", t, re.M)
|
|
variants = sorted(set(re.findall(r"file=(CoolantDump\d+_z\d+\.wav)", t)))
|
|
# playing-source dumps recorded DURING the idle window (post-release)
|
|
idle_play = re.findall(r"^\[playing\].*$", tail_t, re.M)
|
|
stuck = [l for l in idle_play if "loop=1" in l]
|
|
stuck_coolant = [l for l in stuck if "oolant" in l]
|
|
|
|
print("\n=============== RESULT ===============")
|
|
print("[flush-tx] edges:", len(tx), "(expect 12 = 6 press + 6 release)")
|
|
print("coolant zones that actually played:", len(variants))
|
|
for v in variants:
|
|
print(" ", v)
|
|
|
|
print("\n[playing] lines during the 25s IDLE window:", len(idle_play))
|
|
seen = {}
|
|
for l in idle_play:
|
|
m = re.search(r"src=(\d+) (\S+).*loop=(\d+)", l)
|
|
if m:
|
|
seen[(m.group(1), m.group(2), m.group(3))] = seen.get((m.group(1), m.group(2), m.group(3)), 0) + 1
|
|
for (src, nm, lp), n in sorted(seen.items(), key=lambda kv: -kv[1]):
|
|
print(" src=%-4s %-28s loop=%s seen %dx" % (src, nm, lp, n))
|
|
|
|
print("\nSTILL PLAYING with loop=1 after all releases:", len(stuck))
|
|
print(" ...of which coolant:", len(stuck_coolant))
|
|
for l in stuck_coolant[:5]:
|
|
print(" ", l[:120])
|
|
|
|
print("\nVERDICT:", "REPRODUCED -- a looping coolant source outlives its release (#51)"
|
|
if stuck_coolant else
|
|
("looping sources stuck, but not coolant -- same class, different sample"
|
|
if stuck else "no stuck looping source in this run"))
|
|
sys.exit(0)
|