From a11a6978241af51cf8f18c23d6ed44744a9cf9a5 Mon Sep 17 00:00:00 2001 From: arcattack Date: Thu, 16 Jul 2026 15:11:17 -0500 Subject: [PATCH] Audio: footsteps arrive on the FIRST stride -- the 10-20 s warm-up bug User report: footfalls silent for the first 10-20 s of every mission (all mechs), then solid. Root cause was three interlocking layers, each measured with timestamped traces: 1. The authored footstep volume chain (LocalAcceleration [0,10]->ctl100 + LocalVelocity [0,0.6]->ctl101 through authored N=30/N=15 AudioControlSmoothers, fill 0) hangs off the SOURCE's watcher chain (scale watches smoother watches mixer watches source), and an idle source's chain executes only at Start attempts -- one smoother sample per stride. 2. Each hop is frame-gated (AudioComponent::ExecuteWatchers, DefaultAudioFrameDelay), so any burst collapses to one execution. 3. The transient drop gate (vol < 0.3, AUDREND) rejected every Start while the smoother average crawled up 1/30th per attempt -> ~25 dropped strides before the first audible step, then per-frame execution while playing kept it warm forever ("solid after that"). Fixes (engine-level, each documented in place): - AudioScaleOf::Execute now sends EVERY poll (scales are continuous value-feeders; the base bitwise change-gate -- Motion::operator== is memcmp -- froze on our deterministic gait math, where the original's noisy physics floats never bit-repeated. Triggers/matchers keep the change gate: their semantics are edge-based). - Component/AudioComponent::PrimeWatchers(passes): recursive, GATE-FREE watcher pump; AUDREND runs 30 passes on every transient Start request so the authored smoothers evaluate at their true steady state before the drop gate reads the volume. - localAcceleration derives via the binary's exact structure: 15-sample ring buffers of the raw position derivative + dt (ctor part_012.c:9836, derive :15169-15195), in the PerformAndWatch tail so it runs every frame. - AttributeWatcherOf::GrabCurrentValue private -> protected (the scale override calls it). Verified (30 s walk from cold start): drops 25 -> 3 (the survivors are authentic quiet-stride gating: first gentle strides at vol ~0.28 vs the 0.3 gate), footfalls deliver from the first stride, 43 delivered with live per-stride gain variation. Diag traces added: [accwatch]/[fsscale]/ [smooth]/[smoothcfg]/[motionscalecfg] + timestamps on DROP/volset. Co-Authored-By: Claude Opus 4.8 (1M context) --- engine/MUNGA/AUDCMP.cpp | 13 ++++++ engine/MUNGA/AUDIO.cpp | 23 +++++++++++ engine/MUNGA/AUDIO.h | 8 ++++ engine/MUNGA/AUDREND.cpp | 16 +++++++- engine/MUNGA/AUDWTHR.h | 31 ++++++++++++++ engine/MUNGA/CMPNNT.h | 11 +++++ engine/MUNGA/WATCHER.h | 17 +++++++- game/reconstructed/btstubs.cpp | 1 + game/reconstructed/mech.cpp | 8 ++++ game/reconstructed/mech.hpp | 16 ++++++++ game/reconstructed/mech4.cpp | 75 +++++++++++++++++++++++++++------- 11 files changed, 202 insertions(+), 17 deletions(-) diff --git a/engine/MUNGA/AUDCMP.cpp b/engine/MUNGA/AUDCMP.cpp index 886fb35..9c2c3b9 100644 --- a/engine/MUNGA/AUDCMP.cpp +++ b/engine/MUNGA/AUDCMP.cpp @@ -856,6 +856,11 @@ AudioControlSmoother::AudioControlSmoother( MemoryStream_Read(stream, &initial_fill_value); audioControlAverage.SetSize(number_of_samples, initial_fill_value); + if (getenv("BT_ATTRBIND_LOG")) { static int s_sm=0; if (s_sm++<40) + DEBUG_STREAM << "[smoothcfg] this=" << (void*)this << " ctlID=" << (int)control_ID + << " samples=" << (int)number_of_samples << " fill=" << initial_fill_value + << "\n" << std::flush; } + AudioControlSmootherX( audio_component, entity, @@ -955,6 +960,14 @@ void { audioControlAverage.Add(control_value); + if (getenv("BT_AUDIO_SPATIAL")) { static int s_sa=0; + if ((controlID == 100 || controlID == 101) && s_sa++ < 3000) + DEBUG_STREAM << "[smooth] t=" << (GetTickCount() % 1000000) + << " this=" << (void*)this << " ctl=" << (int)controlID + << " in=" << control_value + << " avg=" << audioControlAverage.CalculateOlympicAverage() + << "\n" << std::flush; } + Check(audioComponentSocket.GetCurrent()); audioComponentSocket.GetCurrent()->ReceiveControl( controlID, diff --git a/engine/MUNGA/AUDIO.cpp b/engine/MUNGA/AUDIO.cpp index 7f671ab..93aa768 100644 --- a/engine/MUNGA/AUDIO.cpp +++ b/engine/MUNGA/AUDIO.cpp @@ -463,6 +463,29 @@ void } } +// +//############################################################################# +//############################################################################# +// +void + AudioComponent::PrimeWatchers(int passes) +{ + Check(this); + for (int pass = 0; pass < passes; ++pass) + { + ChainIteratorOf iterator(&audioWatcherSocket); + Component *component; + while ((component = iterator.ReadAndNext()) != NULL) + { + Check(component); + // recurse gate-free: an AudioComponent child (mixer/smoother/ + // splitter) pumps ITS chain; an attribute watcher re-reads + + // re-sends. One pass per level keeps total work = passes x chain. + component->PrimeWatchers(1); + } + } +} + // //############################################################################# //############################################################################# diff --git a/engine/MUNGA/AUDIO.h b/engine/MUNGA/AUDIO.h index bd74762..9f95c5d 100644 --- a/engine/MUNGA/AUDIO.h +++ b/engine/MUNGA/AUDIO.h @@ -454,6 +454,14 @@ public: void ExecuteWatchers(); + // (task #50, AUDIO_FIDELITY F19) gate-free watcher pump for the transient + // cold-start prime: ExecuteWatchers above is frame-gated + // (DefaultAudioFrameDelay), so N calls in one tick collapse to one. + // Recurses through the watcher CHAIN (source <- mixer <- smoother <- + // scale), each hop gate-free. + virtual void + PrimeWatchers(int passes); + void Execute(); diff --git a/engine/MUNGA/AUDREND.cpp b/engine/MUNGA/AUDREND.cpp index c0b0597..ea5fb94 100644 --- a/engine/MUNGA/AUDREND.cpp +++ b/engine/MUNGA/AUDREND.cpp @@ -194,6 +194,19 @@ void else { audio_source_priority = audio_source->GetAudioSourcePriority(); + // (task #50, AUDIO_FIDELITY F19) COLD-START PRIME: an idle source's own + // watcher socket only executes at Start attempts, so its authored + // AudioControlSmoothers (footstep volume: N=30/15, fill 0) warmed ONE + // sample per attempt -- and the transient drop gate below (vol < 0.3) + // rejected the first ~25 footfalls (~10-20 s of silent steps) before + // the average could cross the gate. On a Start request, pump the + // source's watchers a full smoother window so the volume chain is + // evaluated at its true steady state; the smoother keeps its authored + // smoothing role for live variation once the source is playing. + if (message->controlID == StartAudioControlID) + { + audio_source->PrimeWatchers(30); + } audio_source_volume_scale = audio_source->CalculateSourceVolumeScale(); if (getenv("BT_AUDIO_SPATIAL")) { static int s_vs=0; if ((s_vs++ % 120)==0) DEBUG_STREAM << "[spatial] request src=" << (void*)audio_source @@ -227,7 +240,8 @@ void ) { if (getenv("BT_AUDIO_SPATIAL")) { static int s_dr=0; if (s_dr++<40) - DEBUG_STREAM << "[spatial] DROP transient start src=" << (void*)audio_source + DEBUG_STREAM << "[spatial] DROP transient start t=" << (GetTickCount() % 1000000) + << " src=" << (void*)audio_source << " vol=" << audio_source_volume_scale << " (below threshold " << LowAudioVolumeThreshold << ")\n" << std::flush; } #ifdef LAB_ONLY diff --git a/engine/MUNGA/AUDWTHR.h b/engine/MUNGA/AUDWTHR.h index bf7c63f..52555ab 100644 --- a/engine/MUNGA/AUDWTHR.h +++ b/engine/MUNGA/AUDWTHR.h @@ -445,6 +445,30 @@ public: ); ~AudioScaleOf(); + // + //-------------------------------------------------------------------- + // Execute -- scales send EVERY poll (task #50, AUDIO_FIDELITY F19). + // + // The base watcher gate is a BITWISE compare (Motion::operator== is + // memcmp) that existed to skip truly static values. In the original, + // scale-watched attributes (velocities, accelerations, temperatures) + // were noisy physics floats that practically changed every poll, so + // scales streamed per-poll values into their authored consumers -- the + // footstep AudioControlSmoothers (N=30/15, fill 0) are SIZED for that + // cadence. Our reconstruction's math can be deterministic (the gait + // integrator lands on bit-identical derived values during smooth + // acceleration), which froze the gate and starved the smoothers (the + // 10-20 s footstep warm-up). Sending unconditionally restores the + // original's practical behavior; triggers/matchers keep the change + // gate (their semantics are edge-based). + //-------------------------------------------------------------------- + // + void + Execute() + { + GrabCurrentValue(); + } + // //-------------------------------------------------------------------- // BuildFromPage @@ -648,6 +672,13 @@ template void if (getenv("BT_AUDIO_SPATIAL") && control_value <= 0.0f) { static int s_sc=0; if (s_sc++<400) DEBUG_STREAM << "[spatial] scale->0 attrPtr=" << (void*)attributePointer << " comp=" << (void*)audioComponentSocket.GetCurrent() << " raw=" << current_value << " ctlID=" << (int)controlID << " ctl=" << control_value << " aB=[" << attributeValueBoundary1 << "," << attributeValueBoundary2 << "]" << " cB=[" << controlValueBoundary1 << "," << controlValueBoundary2 << "]\n" << std::flush; } + if (getenv("BT_AUDIO_SPATIAL") && (controlID == 100 || controlID == 101)) { + static int s_fs2=0; if (s_fs2++<2000) + DEBUG_STREAM << "[fsscale] t=" << (GetTickCount() % 1000000) + << " attrPtr=" << (void*)attributePointer + << " comp=" << (void*)audioComponentSocket.GetCurrent() + << " ctl" << (int)controlID << " raw=" << current_value + << " out=" << control_value << "\n" << std::flush; } audioComponentSocket.GetCurrent()->ReceiveControl( controlID, control_value diff --git a/engine/MUNGA/CMPNNT.h b/engine/MUNGA/CMPNNT.h index e760bd1..b475e4c 100644 --- a/engine/MUNGA/CMPNNT.h +++ b/engine/MUNGA/CMPNNT.h @@ -11,6 +11,17 @@ public: virtual void Execute(); + // (task #50, AUDIO_FIDELITY F19) gate-free watcher pump for the audio + // transient cold-start prime. Default: run Execute() N times (attribute + // watchers re-read + re-send each pass). AudioComponent overrides it to + // RECURSE through its watcher chain, bypassing the per-component + // audio-frame gate that otherwise collapses the passes to one. + virtual void PrimeWatchers(int passes) + { + for (int pass = 0; pass < passes; ++pass) + Execute(); + } + static Derivation *GetClassDerivations(); static SharedData DefaultData; diff --git a/engine/MUNGA/WATCHER.h b/engine/MUNGA/WATCHER.h index 256894a..654e465 100644 --- a/engine/MUNGA/WATCHER.h +++ b/engine/MUNGA/WATCHER.h @@ -156,14 +156,18 @@ private: void InitializeCurrentValue(); +protected: // //----------------------------------------------------------------------- - // GrabCurrentValue + // GrabCurrentValue -- protected (task #50): AudioScaleOf's per-poll + // Execute override calls it directly (see AUDWTHR.h). //----------------------------------------------------------------------- // void GrabCurrentValue(); +private: + // //----------------------------------------------------------------------- // DumpValue @@ -273,6 +277,17 @@ template void DEBUG_STREAM << "[fswatch] poll#" << s_fsp << " cur=" << (int)*(int*)¤tValue << " mem=" << *(int*)attributePointer << "\n" << std::flush; } + extern void *g_btAccelAddr; // DIAG: poll-vs-change split on the accel attr + if ((void*)attributePointer == g_btAccelAddr) { + static long s_ap=0, s_ac=0; + int changed = !(currentValue == *(T*)attributePointer); + if (changed) ++s_ac; + if ((++s_ap % 120)==0 || (changed && (s_ac % 30)==0)) + DEBUG_STREAM << "[accwatch] t=" << (GetTickCount() % 1000000) + << " poll#" << s_ap << " changes=" << s_ac + << " memY=" << ((float*)attributePointer)[1] + << " curY=" << ((float*)¤tValue)[1] << "\n" << std::flush; + } } if (!(currentValue == *(T*)attributePointer)) { diff --git a/game/reconstructed/btstubs.cpp b/game/reconstructed/btstubs.cpp index 946a7b2..f4d9daa 100644 --- a/game/reconstructed/btstubs.cpp +++ b/game/reconstructed/btstubs.cpp @@ -402,3 +402,4 @@ void VideoComponent::Execute() // DIAG (audio footstep chain): the live &mech->footStep, exported so the // engine watcher poll can trace THE footstep watcher without per-run pointers. void *g_btFootStepAddr = 0; +void *g_btAccelAddr = 0; // DIAG: watcher-poll tracer on the LocalAcceleration attr diff --git a/game/reconstructed/mech.cpp b/game/reconstructed/mech.cpp index d0525d6..e1ca0d4 100644 --- a/game/reconstructed/mech.cpp +++ b/game/reconstructed/mech.cpp @@ -932,9 +932,17 @@ Mech::Mech( footStep = 0; // FootStep pulse (audio trigger) footStepRootJoint = 0; // (F5) resolved on first contact eval footStepRootResolved = 0; + // (F19) the acceleration-feed rings (binary: size 0xF, fill 0) + for (int vr = 0; vr < 15; ++vr) + velRingFwd[vr] = velRingVert[vr] = velRingDt[vr] = 0.0f; + velRingCursor = 0; + accelPrevFwdMean = 0.0f; + accelPrevVertMean = 0.0f; + accelPrevPos = localOrigin.linearPosition; fwdSpeedFiltered = 0.0f; // smoothed published velocity (see mech4 derive) vertSpeedFiltered = 0.0f; { extern void *g_btFootStepAddr; g_btFootStepAddr = &footStep; } // DIAG: watcher-poll tracer target + { extern void *g_btAccelAddr; g_btAccelAddr = &localAcceleration; } // DIAG: accel poll/change tracer radarRange = 1000.0f; // radar display scale (SetTargetRange is stubbed; // 1km default zoom so contacts within ~500m show on // the radar, vs the config maximum_range=4000 edge) diff --git a/game/reconstructed/mech.hpp b/game/reconstructed/mech.hpp index a6702a9..732d3b0 100644 --- a/game/reconstructed/mech.hpp +++ b/game/reconstructed/mech.hpp @@ -863,6 +863,22 @@ protected: // pulse + decay members are retired. Joint *footStepRootJoint; // cached "jointlocal" (binary mech+0x5C8) int footStepRootResolved; + // (AUDIO_FIDELITY F19, corrected) the binary's localAcceleration feed: + // FIVE 15-sample RING BUFFERS (ctor part_012.c:9836-9840, size 0xF + // fill 0) hold the RAW per-frame velocity components + dt; + // localAcceleration = (ringMean - prevRingMean) / ringMean(dt) + // (part_012.c:15169-15195). A moving-window mean JITTERS every frame + // as samples rotate, so the accel attribute changes every watcher + // poll -- which is what keeps the authored N=30 footstep smoother fed + // (an exponential-filter derivative goes epsilon-flat between strides + // and starved it: the 10-20 s footstep warm-up bug). + Scalar velRingFwd[15]; + Scalar velRingVert[15]; + Scalar velRingDt[15]; + int velRingCursor; + Scalar accelPrevFwdMean; + Scalar accelPrevVertMean; + Point3D accelPrevPos; // raw position memory for the ring feed // Radar/map gauge attributes (binary @0x404/0x408/0x40c/0x3f8). The map // widget reads position/angle as POINTERS into the mech's live origin, so // radarLinearPosition/radarAngularPosition point at localOrigin.{linear, diff --git a/game/reconstructed/mech4.cpp b/game/reconstructed/mech4.cpp index 71290d5..7665728 100644 --- a/game/reconstructed/mech4.cpp +++ b/game/reconstructed/mech4.cpp @@ -3692,23 +3692,26 @@ void // velocity the same way; this filter reconstructs that stage. { Scalar alpha = dt / (dt + 0.25f); - Scalar fwdPrev = fwdSpeedFiltered; - Scalar vertPrev = vertSpeedFiltered; fwdSpeedFiltered += alpha * (fwdSpeed - fwdSpeedFiltered); vertSpeedFiltered += alpha * (worldLinearVelocity.y - vertSpeedFiltered); // (AUDIO_FIDELITY F19) publish localAcceleration EXACTLY as the - // binary does: the derivative of the (averaged) published - // velocity (part_012.c:15186-15195 -- (avgVel - prev)/avgDt into - // localAcceleration.linear). The AUTHORED footstep chain reads - // |localAcceleration.linear| [0,10] -> mixer ctl100 (the - // per-stride kick) on top of |localVelocity| [0,0.6] -> ctl101 - // (the 0.4 moving base); with this member never written the - // kick input read 0 and step volume lost its dynamics. - if (dt > 1.0e-4f) - localAcceleration.linearMotion = Vector3D( - 0.0f, - (vertSpeedFiltered - vertPrev) / dt, - -((fwdSpeedFiltered - fwdPrev) / dt)); + // binary does: FIVE 15-sample RING BUFFERS hold the RAW velocity + // components + dt (ctor part_012.c:9836-9840), and the accel is + // the frame-to-frame derivative of the ring MEAN over the mean + // dt (part_012.c:15169-15195). The ring mean keeps jittering + // as samples rotate, so the accel ATTRIBUTE changes on every + // watcher poll -- feeding the authored N=30 footstep smoother + // continuously (ctl100 |accel| [0,10] -> the per-stride kick on + // top of ctl101's 0.4 moving base). A first cut derived accel + // from the 0.25s-filtered velocity: its derivative goes + // epsilon-flat between strides, the watcher stopped firing, and + // the smoother took 10-20 s to warm from its fill=0 (the + // late-footsteps bug). NOTE: the RAW components feed only the + // rings; the PUBLISHED velocity keeps the 0.25s filter (a [T3] + // accommodation for our ground-snap ripple, see above). + // (the ring push itself lives in the PerformAndWatch tail so it + // provably runs EVERY frame -- this conditional path skips + // frames in some gait states, which starved the accel watcher) } localVelocity.linearMotion = Vector3D(0.0f, vertSpeedFiltered, -fwdSpeedFiltered); localVelocity.angularMotion = Vector3D(0.0f, turn * authTurnRate, 0.0f); @@ -5303,6 +5306,46 @@ void } } + // (AUDIO_FIDELITY F19) the localAcceleration feed, EXACTLY the binary's + // structure: 15-sample RING BUFFERS of the raw per-frame position + // derivative + dt (ctor part_012.c:9836-9840, fill 0); accel = the + // frame-to-frame derivative of the ring MEAN over the mean dt + // (part_012.c:15169-15195). Runs HERE, right before the watcher poll, + // so the accel attribute updates EVERY polled frame -- the ring mean's + // rotation jitter keeps the change-gate open and the authored N=30 + // footstep smoother fed (fed per-stride only, it took 10-20 s to warm + // from fill=0: the late-footsteps bug). + { + Scalar rdx = localOrigin.linearPosition.x - accelPrevPos.x; + Scalar rdy = localOrigin.linearPosition.y - accelPrevPos.y; + Scalar rdz = localOrigin.linearPosition.z - accelPrevPos.z; + accelPrevPos = localOrigin.linearPosition; + if (dt > 1.0e-4f) + { + velRingFwd[velRingCursor] = (Scalar)sqrtf(rdx * rdx + rdz * rdz) / dt; + velRingVert[velRingCursor] = rdy / dt; + velRingDt[velRingCursor] = dt; + velRingCursor = (velRingCursor + 1) % 15; + } + Scalar fwdMean = 0.0f, vertMean = 0.0f, dtMean = 0.0f; + for (int vr = 0; vr < 15; ++vr) + { + fwdMean += velRingFwd[vr]; + vertMean += velRingVert[vr]; + dtMean += velRingDt[vr]; + } + fwdMean *= (1.0f / 15.0f); + vertMean *= (1.0f / 15.0f); + dtMean *= (1.0f / 15.0f); + if (dtMean > 1.0e-4f) // binary: _DAT_004ab9d4 guard + localAcceleration.linearMotion = Vector3D( + 0.0f, + (vertMean - accelPrevVertMean) / dtMean, + -((fwdMean - accelPrevFwdMean) / dtMean)); + accelPrevFwdMean = fwdMean; + accelPrevVertMean = vertMean; + } + // (AUDIO_FIDELITY F7) latch the incoming-missile report accumulated by // Missile::MoveAndCollide since our last frame, then re-arm. The authored // beeper matches incomingLock 1/0 and the tempo scale reads the range -- @@ -5313,7 +5356,9 @@ void distanceToMissileNext = FLT_MAX; if (getenv("BT_AUDIO_LOG")) { static int s_wd=0; if ((s_wd++ % 300)==0) - DEBUG_STREAM << "[audio] mech watcher poll: delayed=" << (int)AreWatchersDelayed() << " audioWatchers=" << DebugAudioWatcherCount() + DEBUG_STREAM << "[audio] mech watcher poll t=" << (GetTickCount() % 1000000) + << " n=" << s_wd + << " delayed=" << (int)AreWatchersDelayed() << " audioWatchers=" << DebugAudioWatcherCount() << " simFlags=0x" << std::hex << (unsigned)simulationFlags << std::dec << "\n" << std::flush; } if (!AreWatchersDelayed())