fix(audio): listening-gate round 1 — tunnel interior sound + ambience in houses (#355 gate)

Two user findings from the Campaign A listening session.

1. The portal tunnel's in-flight sound was silent while its enter/exit
cues played. The tunnel's authored SoundTweakedHook drained into the
world 3-D path at its synthetic owner's origin (0,0,0) — after A2 that
dies twice: the listener is usually beyond the -50 dB no-allocate radius,
and the world pool is suspended for the whole transit hold. The cues the
user COULD hear were on the interface bus, which has neither problem, and
retail's tunnel is gmSmartBoxUI — UI-owned — so that bus is also the
faithful route. UiPresentationHookSink now wraps the shared router for
the tunnel: sound-bearing hooks go from-centre through the interface bus
(AudioHookSink.OnUiHook); every other hook kind still reaches the
particle/lighting/translucency sinks unchanged.

2. Ambience cut dead inside houses; retail keeps the outdoor soundscape
in sky-lit interiors. This is TS-66, now retired: the ambient listener
source resolves the per-cell CEnvCell.seen_outside bit through the
physics cache (the same #107 field AdjustPosition reads) and converts the
envcell-local origin through the cell's WorldTransform into landblock
coordinates before the 3x3 walk centres on it — an outdoor Position's
origin is already landblock-local, an envcell's is cell-local, and
skipping that conversion would centre the walk wrongly by up to a
landblock. A not-yet-resident cell record resolves to silence for that
rebuild rather than a wrong walk. Sealed dungeons stay silent, which is
retail-correct.

The user also reports interiors carrying their own local sound in retail
(hearth-type emitters). Statics already register their sound tables and
route animation hooks, so the expectation is that the seen_outside fix
plus existing emitters covers it; re-listen decides, and anything still
missing becomes a precise follow-up.

Full Release suite: 11,740 passed / 4 skipped / 0 failed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-09 12:56:26 +02:00
parent 78b981cca0
commit e5ade796ac
6 changed files with 159 additions and 14 deletions

View file

@ -290,28 +290,54 @@ public interface IAmbientListenerSource
public sealed class LocalPlayerAmbientListenerSource : IAmbientListenerSource
{
private readonly AcDream.Runtime.Gameplay.RuntimeLocalPlayerMovementState _player;
private readonly Func<uint, Vector3, Vector3?> _indoorLandblockLocal;
public LocalPlayerAmbientListenerSource(
AcDream.Runtime.Gameplay.RuntimeLocalPlayerMovementState player) =>
AcDream.Runtime.Gameplay.RuntimeLocalPlayerMovementState player,
Func<uint, Vector3, Vector3?>? indoorLandblockLocal = null)
{
_player = player ?? throw new ArgumentNullException(nameof(player));
_indoorLandblockLocal = indoorLandblockLocal ?? ((_, _) => null);
}
public bool TryGetListener(out AmbientListenerPose pose)
{
if (_player.Controller is { } controller)
{
AcDream.Core.Physics.Position cell = controller.CellPosition;
uint objCellId = controller.CellId;
Vector3 landblockLocal = cell.Frame.Origin;
bool seenOutside = false;
// Retail's gate is `isOutdoorCell(pos) || curr_cell->seen_outside`
// (TS-66, retired with this wiring): a sky-lit interior — a
// cottage, an open shopfront — keeps the OUTDOOR ambient set,
// while a sealed dungeon stays silent. The flag is the same
// per-cell `CEnvCell.seen_outside` bit the physics cache already
// carries for AdjustPosition (#107).
//
// Frames: an OUTDOOR Position's origin is already landblock-local,
// but an ENVCELL's origin is CELL-local — it must go through the
// cell's own transform (the dat authors cell Positions in
// landblock coordinates) before the 3×3 walk can centre on it.
// The resolver returns null when it cannot answer (cell record
// not yet resident), which keeps the interior silent for that
// rebuild rather than centring the walk on a wrong point.
if ((objCellId & 0xFFFFu) >= 0x0100u)
{
if (_indoorLandblockLocal(objCellId, cell.Frame.Origin)
is { } converted)
{
landblockLocal = converted;
seenOutside = true;
}
}
pose = new AmbientListenerPose(
controller.CellId,
objCellId,
controller.Position,
cell.Frame.Origin,
// Retail's gate is `isOutdoorCell(pos) || curr_cell->seen_outside`,
// so a sky-lit interior keeps the outdoor set. acdream's
// seen_outside lives on the cell's collision record rather than
// its Position, and resolving it here needs a physics-cache
// lookup this source does not own — deferred as TS-66. Until
// then every interior is silent, which is right for a dungeon
// and wrong for a cottage.
SeenOutside: false);
landblockLocal,
seenOutside);
return true;
}

View file

@ -140,6 +140,59 @@ public sealed class AudioHookSink : IAnimationHookSink
priority: entry.Priority);
}
/// <summary>
/// Play a sound-bearing animation hook through the INTERFACE bus — from
/// centre, distance 0, unaffected by the world-audio suspension that
/// covers reveal holds. This is the route for hooks authored on
/// UI-owned presentations: retail's portal tunnel is <c>gmSmartBoxUI</c>,
/// and its in-tunnel <c>SoundTweakedHook</c> accompanies the viewer rather
/// than a world object. Routing it through the world 3-D path instead
/// killed it twice over after Campaign A slice A2 — the hook's synthetic
/// owner sits at the world origin, usually beyond the 50 dB no-allocate
/// radius, and the world pool is suspended for the whole transit hold —
/// which is exactly why the enter/exit cues (already on this bus) were
/// audible while the tunnel interior was silent.
/// </summary>
public void OnUiHook(uint entityId, AnimationHook hook)
{
if (!_engine.IsAvailable) return;
switch (hook)
{
case SoundHook s:
PlayUi((uint)s.Id, volume: 1f);
break;
case SoundTableHook st:
// A UI-owned presentation resolves through the owner's table
// exactly like the world path; the tunnel's synthetic owner
// carries none, so this is inert there but keeps the route
// complete for any UI owner that does.
uint tableId = _entitySoundTables.GetSoundTableId(entityId);
if (tableId == 0) return;
SoundTable? table = _cache.GetSoundTable(tableId);
if (table is null) return;
var entry = SoundCookbook.Select(table, st.SoundType, _rng);
if (entry is null) return;
PlayUi((uint)entry.Id, entry.Volume);
break;
case SoundTweakedHook stw:
PlayUi(
(uint)stw.SoundId,
stw.Volume > 0 ? stw.Volume : 1f);
break;
}
}
private void PlayUi(uint waveId, float volume)
{
if (waveId == 0) return;
WaveData? wave = _cache.GetWave(waveId);
if (wave is null) return;
_engine.PlayUiWave(waveId, wave, volume);
}
private void PlayFromSoundTable(
uint entityId, Vector3 worldPos, DRWSound sound,
float volumeMult = 1f)

View file

@ -0,0 +1,47 @@
using System;
using System.Numerics;
using AcDream.Core.Physics;
using DatReaderWriter.Types;
namespace AcDream.App.Audio;
/// <summary>
/// Hook sink for UI-OWNED presentations (the portal tunnel is retail's
/// <c>gmSmartBoxUI</c>): sound-bearing hooks go to the interface bus — from
/// centre, distance 0, immune to the world-audio suspension that covers
/// reveal holds — while every other hook kind forwards to the shared router
/// unchanged, so particles/lighting/translucency behave exactly as before.
///
/// <para>
/// Without this split the tunnel's authored in-flight <c>SoundTweakedHook</c>
/// went down the world 3-D path at the synthetic owner's origin: usually
/// beyond the 50 dB no-allocate radius AND inside the suspended-transit
/// window, so the tunnel interior was silent while the enter/exit cues (on
/// the interface bus already) played fine.
/// </para>
/// </summary>
public sealed class UiPresentationHookSink : IAnimationHookSink
{
private readonly IAnimationHookSink _router;
private readonly AudioHookSink? _audio;
public UiPresentationHookSink(IAnimationHookSink router, AudioHookSink? audio)
{
_router = router ?? throw new ArgumentNullException(nameof(router));
_audio = audio;
}
public void OnHook(uint entityId, Vector3 entityWorldPosition, AnimationHook hook)
{
if (hook is SoundHook or SoundTableHook or SoundTweakedHook)
{
// With no audio graph (headless/driver-less) the sound hook is
// simply dropped — forwarding it to the router would put it back
// on the world 3-D path this sink exists to bypass.
_audio?.OnUiHook(entityId, hook);
return;
}
_router.OnHook(entityId, entityWorldPosition, hook);
}
}

View file

@ -1092,7 +1092,12 @@ internal sealed class LivePresentationCompositionPhase
host.GpuFrameLifetime,
content.Dats,
content.AnimationLoader,
d.HookRouter,
// The tunnel is UI-owned (retail gmSmartBoxUI): its
// sound hooks route to the interface bus; every other
// hook still reaches the shared router.
new AcDream.App.Audio.UiPresentationHookSink(
d.HookRouter,
content.Audio?.HookSink),
portalDispatcher,
foundation.SceneLighting!,
foundation.MeshAdapter!,

View file

@ -815,7 +815,21 @@ internal sealed class SessionPlayerCompositionPhase
ambient.InstallRegion(region, LoadTerrainWords);
return new AmbientFramePhase(
ambient,
new LocalPlayerAmbientListenerSource(d.PlayerController));
new LocalPlayerAmbientListenerSource(
d.PlayerController,
indoorLandblockLocal: (cellId, cellLocal) =>
{
// seen_outside interiors keep the outdoor ambient set
// (TS-66). The cell's WorldTransform maps its local
// frame into landblock coordinates, which is the frame
// the ambient walk centres on.
var cellStruct = d.PhysicsDataCache.GetCellStruct(cellId);
if (cellStruct is null || !cellStruct.SeenOutside)
return null;
return System.Numerics.Vector3.Transform(
cellLocal,
cellStruct.WorldTransform);
}));
ushort[]? LoadTerrainWords(uint landblockId)
{