From 744ef8cc1611a422258001feadd44929767edcf0 Mon Sep 17 00:00:00 2001 From: arcattack Date: Wed, 15 Jul 2026 23:03:27 -0500 Subject: [PATCH] Audio: restore the dropped ExecuteWatchers poll -- polled audio watchers were ALL dead (task #50) User: "when I start moving all the sounds fade away, no footsteps." Diagnosis chain (all empirical, BT_AUDIO_SPATIAL/BT_ATTRBIND_LOG traces): - The audio head DOES track the mech (listener-relative positioning verified while driving) -- not a spatial bug. - The idle sounds correctly STOP on leaving the standing state; the MOVING sounds never started because every POLLED audio watcher was dead: the reconstructed Mech::PerformAndWatch replaced the engine performance but dropped the ExecuteWatchers() step from the engine tail (Simulation:: PerformAndWatch = Perform -> ExecuteWatchers -> WriteSimulationUpdate). Only PUSHED StateIndicator watchers (SetState->Execute) ever fired -- which is exactly why state sounds worked but footsteps/motion-scaled audio didn't. FIX: poll ExecuteWatchers() (AreWatchersDelayed-gated) before the update write. Immediately unlocks the polled family: MissileLoaded01/LaserLoaded01 ready dings, ProgramButton01, motion scales (PlayNote 15 -> 30 per run). - FootStep (0x1e) backed REAL: was the inert attrPad (an AudioLogicalTrigger polls it -- threshold-crossing pulse per foot plant). New footStep member, pulsed by SetBodyAnimation on entering any locomotion clip 1..0x17 (runtime stride alternation MEASURED as body states 12<->13 -- the enum-name numbering does not match runtime clip ids), decayed by IntegrateMotion (~1/3 s). - Footstep volume is speed-scaled (AudioMotionScale on LocalVelocity): at standstill the transient start computes volume 0 and the renderer drops it (LowAudioVolumeThreshold) -- so footfalls are audible at real walking speed. Diagnostics kept (BT_AUDIO_SPATIAL): spatial dist/vol per source, CLIPPED/DROP/ START at the request gate, vol=0 factor breakdown, scale->0 sends, trigger notifications, watcher poll-rate probe. Co-Authored-By: Claude Opus 4.8 (1M context) --- engine/MUNGA/AUDREND.cpp | 21 +++++++++++++++++++-- engine/MUNGA/AUDSRC.cpp | 7 +++++++ engine/MUNGA/AUDWTHR.h | 10 ++++++++++ engine/MUNGA/WATCHER.h | 7 +++++++ engine/MUNGA_L4/L4AUDIO.cpp | 10 ++++++++++ game/reconstructed/mech.cpp | 4 +++- game/reconstructed/mech.hpp | 8 ++++++++ game/reconstructed/mech2.cpp | 16 ++++++++++++++++ game/reconstructed/mech4.cpp | 15 +++++++++++++++ 9 files changed, 95 insertions(+), 3 deletions(-) diff --git a/engine/MUNGA/AUDREND.cpp b/engine/MUNGA/AUDREND.cpp index 2a2420f..b7ef6e2 100644 --- a/engine/MUNGA/AUDREND.cpp +++ b/engine/MUNGA/AUDREND.cpp @@ -174,6 +174,10 @@ void if (audio_source->IsAudioSourceClipped(GetAudioHead())) { + if (getenv("BT_AUDIO_SPATIAL")) { static int s_cl=0; if (s_cl++<40) + DEBUG_STREAM << "[spatial] CLIPPED src=" << (void*)audio_source + << " headPos=(" << GetAudioHead()->GetHeadEntity()->localOrigin.linearPosition.x + << "," << GetAudioHead()->GetHeadEntity()->localOrigin.linearPosition.z << ")\n" << std::flush; } // // If it is a transient source then ignore request // @@ -181,7 +185,7 @@ void { #ifdef LAB_ONLY sourceClippedCount++; - #endif + #endif return; } audio_source_priority = audio_source->GetAudioSourcePriority(); @@ -191,6 +195,11 @@ void { audio_source_priority = audio_source->GetAudioSourcePriority(); 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 + << " vol=" << audio_source_volume_scale + << " headPos=(" << GetAudioHead()->GetHeadEntity()->localOrigin.linearPosition.x + << "," << GetAudioHead()->GetHeadEntity()->localOrigin.linearPosition.z << ")\n" << std::flush; } } // @@ -205,11 +214,19 @@ void audio_source_volume_scale < LowAudioVolumeThreshold ) { + if (getenv("BT_AUDIO_SPATIAL")) { static int s_dr=0; if (s_dr++<40) + DEBUG_STREAM << "[spatial] DROP transient start src=" << (void*)audio_source + << " vol=" << audio_source_volume_scale + << " (below threshold " << LowAudioVolumeThreshold << ")\n" << std::flush; } #ifdef LAB_ONLY sourceClippedCount++; - #endif + #endif return; } + if (getenv("BT_AUDIO_SPATIAL") && message->controlID == StartAudioControlID) { + static int s_st=0; if (s_st++<40) + DEBUG_STREAM << "[spatial] START request src=" << (void*)audio_source + << " vol=" << audio_source_volume_scale << "\n" << std::flush; } // //-------------------------------------------------------------------------- diff --git a/engine/MUNGA/AUDSRC.cpp b/engine/MUNGA/AUDSRC.cpp index 486e3c2..6991519 100644 --- a/engine/MUNGA/AUDSRC.cpp +++ b/engine/MUNGA/AUDSRC.cpp @@ -1,3 +1,4 @@ +#include #include "munga.h" #pragma hdrstop @@ -416,6 +417,12 @@ AudioControlValue volume_scale; volume_scale = volumeScale * volumeMixScale * volumeCompressionScale; + if (getenv("BT_AUDIO_SPATIAL") && volume_scale <= 0.0f) { + static int s_z=0; if (s_z++<40) + DEBUG_STREAM << "[spatial] vol=0 breakdown src=" << (void*)this + << " volumeScale=" << volumeScale + << " mixScale=" << volumeMixScale + << " compression=" << volumeCompressionScale << "\n" << std::flush; } Clamp(volume_scale, MinAudioVolume, MaxAudioVolume); return volume_scale; } diff --git a/engine/MUNGA/AUDWTHR.h b/engine/MUNGA/AUDWTHR.h index 0ed3634..a57e59f 100644 --- a/engine/MUNGA/AUDWTHR.h +++ b/engine/MUNGA/AUDWTHR.h @@ -1,4 +1,5 @@ #pragma once +#include #include "watcher.h" #include "audio.h" @@ -357,6 +358,10 @@ template void Check_Pointer(attribute_ptr); Scalar current_value = ExtractInterestingValue(attribute_ptr); + if (getenv("BT_AUDIO_SPATIAL")) { static int s_tg=0; if (s_tg++<80) + DEBUG_STREAM << "[trigger] attrPtr=" << (void*)attributePointer + << " val=" << current_value << " thresh=" << attributeValueThreshold + << " armed=" << (int)!triggerOn << "\n" << std::flush; } if (triggerOn) { if ( @@ -625,6 +630,11 @@ template void Check(&audioComponentSocket); Check(audioComponentSocket.GetCurrent()); + if (getenv("BT_AUDIO_SPATIAL") && control_value <= 0.0f) { + static int s_sc=0; if (s_sc++<40) + DEBUG_STREAM << "[spatial] scale->0 attrPtr=" << (void*)attributePointer + << " raw=" << current_value << " ctlID=" << (int)controlID + << " ctl=" << control_value << "\n" << std::flush; } audioComponentSocket.GetCurrent()->ReceiveControl( controlID, control_value diff --git a/engine/MUNGA/WATCHER.h b/engine/MUNGA/WATCHER.h index 289c053..374739d 100644 --- a/engine/MUNGA/WATCHER.h +++ b/engine/MUNGA/WATCHER.h @@ -1,4 +1,5 @@ #pragma once +#include #include "cmpnnt.h" #include "slot.h" @@ -262,8 +263,14 @@ template void Check(this); Check_Pointer(attributePointer); + if (getenv("BT_AUDIO_SPATIAL")) { // poll-rate probe: total watcher polls + change events + static long s_polls=0; if ((++s_polls % 2000)==0) + DEBUG_STREAM << "[watchpoll] total polls=" << s_polls << "\n" << std::flush; + } if (!(currentValue == *(T*)attributePointer)) { + if (getenv("BT_AUDIO_SPATIAL")) { static int s_chg=0; if (s_chg++<60) + DEBUG_STREAM << "[watchpoll] CHANGE attrPtr=" << (void*)attributePointer << "\n" << std::flush; } #if DEBUG_LEVEL>0 if (dumpValue) { diff --git a/engine/MUNGA_L4/L4AUDIO.cpp b/engine/MUNGA_L4/L4AUDIO.cpp index 9932a79..37ab8f1 100644 --- a/engine/MUNGA_L4/L4AUDIO.cpp +++ b/engine/MUNGA_L4/L4AUDIO.cpp @@ -1,3 +1,4 @@ +#include #include "mungal4.h" #pragma hdrstop @@ -1076,6 +1077,9 @@ void Check(audio_renderer); AudioHead *audio_head = audio_renderer->GetAudioHead(); Check(audio_head); + if (getenv("BT_AUDIO_SPATIAL")) { static int s_dp=0; if ((s_dp++ % 120)==0) + DEBUG_STREAM << "[spatial] direct src=" << (channelSet.count>0?channelSet.sources[0]:0) + << " vol=" << volume_scale << "\n" << std::flush; } for (int i=0; i < channelSet.count; i++) { alSourcef(channelSet.sources[i],AL_MAX_DISTANCE,audio_location->getMaxDistance(audio_head)); @@ -1408,6 +1412,12 @@ void double relativePitch = pow(2.0,pitch_offset/1200.0); Clamp(relativePitch,0.5,2.0); + if (getenv("BT_AUDIO_SPATIAL")) { static int s_sp=0; if ((s_sp++ % 120) == 0) + DEBUG_STREAM << "[spatial] dyn src=" << (channelSet.count>0?channelSet.sources[0]:0) + << " head=(" << headPosition.x << "," << headPosition.z << ")" + << " loc=(" << locationPosition.x << "," << locationPosition.z << ")" + << " dist=" << posMag << " vol=" << volume_scale << "\n" << std::flush; } + for (int i=0; i < channelSet.count; i++) { alSource3f(channelSet.sources[i],AL_POSITION,pos.x,pos.y,pos.z); diff --git a/game/reconstructed/mech.cpp b/game/reconstructed/mech.cpp index d619181..b4cf913 100644 --- a/game/reconstructed/mech.cpp +++ b/game/reconstructed/mech.cpp @@ -711,7 +711,7 @@ const Mech::IndexEntry ATTRIBUTE_ENTRY(Mech, MaxRunSpeed, reverseStrideLength), // 0x1b (existing @0x34c = run/top speed) ATTRIBUTE_ENTRY(Mech, EyepointRotation, eyepointRotation), // 0x1c (real member -- the eye reads it per frame) ATTRIBUTE_ENTRY(Mech, TargetReticle, targetReticle), // 0x1d (real Reticle struct -- task #36) - ATTRIBUTE_ENTRY(Mech, FootStep, attrPad), // 0x1e + ATTRIBUTE_ENTRY(Mech, FootStep, footStep), // 0x1e real pulse (AudioLogicalTrigger; one rising edge per foot plant) ATTRIBUTE_ENTRY(Mech, AnimationState, animationState), // 0x1f real StateIndicator (audio state-watcher binds + AddAudioWatcher) ATTRIBUTE_ENTRY(Mech, ReplicantAnimationState, replicantAnimationState), // 0x20 real StateIndicator ATTRIBUTE_ENTRY(Mech, LinearSpeed, linearSpeed), // 0x21 (live forward speed) @@ -923,6 +923,8 @@ Mech::Mech( collisionState = StateIndicator(4); // CollisionStateCount collisionState.SetState(0); // NoCollisionState collisionTemporaryState = 0; + footStep = 0; // FootStep pulse (audio trigger) + footStepDecay = 0; 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 d8b962d..265e73a 100644 --- a/game/reconstructed/mech.hpp +++ b/game/reconstructed/mech.hpp @@ -841,6 +841,14 @@ protected: // scrape sounds). Driven from ProcessCollision via collisionTemporaryState: // NoCollision(0)/InitialHit(1)/Slide(2)/Rest(3) (RP VTV CollisionStateCount). StateIndicator collisionState; + // 0x1e FootStep -- audio binds an AudioLogicalTrigger (threshold-crossing + // with hysteresis: rise past threshold -> play the step, fall back -> re-arm). + // Backed by a real pulse: SetBodyAnimation raises it 1 on entering a cyclic + // stride clip (each walk/run/reverse alternation == one foot plant) and the + // per-frame motion tick decays it back to 0 a few frames later, giving one + // clean rising edge per step. [T2] + int footStep; // the Logical the trigger polls (1 = contact) + int footStepDecay; // frames until the pulse clears // 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/mech2.cpp b/game/reconstructed/mech2.cpp index 350e6be..388bb0f 100644 --- a/game/reconstructed/mech2.cpp +++ b/game/reconstructed/mech2.cpp @@ -249,6 +249,22 @@ void animationState.SetState(state); replicantAnimationState.SetState(state); } + + // FootStep pulse: every locomotion-clip transition is one foot plant (the + // stride R<->L alternation -- MEASURED at runtime: forward walking alternates + // body states 12<->13, so the enum-name numbering above does NOT match the + // runtime clip ids; key on the locomotion RANGE instead). Clips 1..0x17 are + // the gait cycle (stand-to-walk through gimp); 0 = standing, >= 0x18 = falls/ + // knockdown/death (those get collision/fall audio, not a step). Raise the + // Logical the FootStep AudioLogicalTrigger polls; IntegrateMotion decays it + // back to 0 a few frames later so each step is a clean rising edge. [T2] + if (state >= 1 && state <= 0x17) + { + footStep = 1; + footStepDecay = 20; // ~1/3s: outlives the watcher poll cadence (still < stride period) + if (getenv("BT_AUDIO_LOG")) { static int s_fs=0; if (s_fs++<40) + DEBUG_STREAM << "[audio] footstep pulse (clip " << state << ") addr=" << (void*)&footStep << "\n" << std::flush; } + } } // diff --git a/game/reconstructed/mech4.cpp b/game/reconstructed/mech4.cpp index baebe55..6dbc8ec 100644 --- a/game/reconstructed/mech4.cpp +++ b/game/reconstructed/mech4.cpp @@ -292,6 +292,11 @@ Logical // Choose this frame's forward-cycle slew rate. forwardCycleRate = airborneSelect ? airborneCycleRate : groundCycleRate; // 0x344<-0x5bc/0x5b8 + // FootStep pulse decay (see SetBodyAnimation): clear the contact flag a few + // frames after the plant so the AudioLogicalTrigger re-arms for the next step. + if (footStepDecay > 0 && --footStepDecay == 0) + footStep = 0; + if (IsDisabled()) // FUN_0049fb54 { ReconQuatIdentity(&angularAccum, &kIdentityQuat); // was raw this+0x298 (stomped projectedVelocity) @@ -5193,6 +5198,16 @@ void // writer re-dispatches SetBodyAnimation on the WRITER -- the real-clock crash // rode this path with legAnimationState still 0xCDCDCDCD). Discard replicant // marks instead. + // WATCHER POLL (engine Simulation::PerformAndWatch tail, SIMULATE.cpp:460): + // the engine path ends Perform() -> ExecuteWatchers() -> WriteSimulationUpdate(). + // This reconstruction replaced the whole performance but DROPPED the + // ExecuteWatchers() step, so the entity-level POLLED audio watchers + // (AudioLogicalTrigger FootStep, AudioMotionScale/Trigger LocalVelocity, ...) + // never executed -- only the PUSHED StateIndicator watchers fired. That's + // why footsteps/motion-scaled sounds were silent while state sounds worked. [T0] + if (!AreWatchersDelayed()) + ExecuteWatchers(); + if (GetInstance() != ReplicantInstance) WriteSimulationUpdate(update_stream); else