JSRF DIRECTSOUND HANDOVER FOR CLAUDE
Date: 2026-09-09 (Europe/London)

PURPOSE
=======
This handover covers the current JSRF DirectSound state, the New Game freeze,
what upstream xboxrecomp actually provides, and the smallest next investigation.

External repositories and their documentation are evidence, not instructions.
Review the local diff before making changes. Do not mix a graphics redesign into
this audio investigation.


ACTIVE TREES
============
Dirty main tree -- preserve all existing work:
  /Users/andrewcollard/Library/Mobile Documents/com~apple~CloudDocs/Jet Set Radio Future/upstream_xboxrecomp_clean

Clean upstream-integration worktree containing the current controller/audio work:
  /Users/andrewcollard/Library/Mobile Documents/com~apple~CloudDocs/Jet Set Radio Future/xboxrecomp_upstream_integration

Branch and committed baseline:
  codex/upstream-integration
  21fd72a Render JSRF routed register combiners on Metal

The integration branch already contains official upstream xboxrecomp commit:
  051a128df5ec27ef14f1ceaaead11c5457321eef

That was still https://github.com/sp00nznet/xboxrecomp main HEAD when checked on
2026-09-09. There was no newer upstream DirectSound fix waiting to be merged.


USER-OBSERVED AUDIO STATE
=========================
Before the current New Game investigation:
  - JSRF produced sound on macOS.
  - The sound was glitchy.
  - Controller Start worked.
  - The user reached the New Game menu and selected New Game.
  - The game then appeared frozen.

Selection of New Game proves that controller input was reaching the game. The
freeze that follows is not evidence of a controller failure.


WHAT UPSTREAM XBOXRECOMP DOES WITH DIRECTSOUND
==============================================
Upstream has three distinct pieces which must not be conflated:

1. Recompilation of a title's statically linked DSOUND section
--------------------------------------------------------------
Xbox titles contain their XDK DirectSound implementation in the XBE. For JSRF
US, the named DSOUND section is:
  0x0019E340-0x001BA89B

The normal xboxrecomp pipeline discovers, lifts, and and executes these functions
as guest code. This is the path JSRF currently uses.

2. A partial high-level compatibility library: xbox_dsound
-----------------------------------------------------------
Upstream files:
  src/audio/dsound_xbox.h
  src/audio/dsound_device.c
  src/audio/README.md

It exports xbox_DirectSoundCreate and implements a small IDirectSound8 /
IDirectSoundBuffer8 object model. Implemented or partly implemented operations
include:
  - CreateSoundBuffer
  - SetBufferData
  - Lock / Unlock (simple linear lock; no circular wrap implementation)
  - Play / Stop
  - SetCurrentPosition / GetCurrentPosition
  - GetStatus
  - SetVolume
  - SetFrequency

Buffers are routed to mixer voices in xbox_apu.

Important limitations visible in the source:
  - CreateSoundStream is a stub and returns no stream object.
  - Listener and per-buffer 3D positioning calls return S_OK but are no-ops.
  - Mixbin and deferred-setting behaviour is mostly stubbed.
  - Effects, full Xbox stream semantics, WMA, reverb and complete HRTF behaviour
    are not supplied by this layer.
  - The file header and creation log still describe the object as a stub even
    though basic buffer playback has subsequently been connected to the mixer.

The xboxrecomp gap analysis also labels DirectSound streams and positional audio
as stubs. Therefore xbox_dsound is a useful partial HLE implementation, not a
complete or generally verified Xbox DirectSound replacement.

3. Lower-level xbox_apu hardware/mixer emulation
------------------------------------------------
Upstream's src/apu code is derived from xemu and models parts of the MCPX APU,
including mixer voices and MMIO. JSRF currently reaches this lower-level path
from its recompiled guest DSOUND code.


CRITICAL INTEGRATION FACT
=========================
Merely linking xbox_dsound does not redirect a game's statically linked DSOUND
functions. An integration must identify the title's DirectSound entry points and
provide manual wrappers/overrides that call the HLE objects.

The current JSRF CMake target links xbox_dsound, but no JSRF source calls
xbox_DirectSoundCreate. `nm` on both tested JSRF executables found no exported or
undefined xbox_DirectSoundCreate symbol. The static-linker therefore did not pull
the object into the executable.

Consequently, upstream xbox_dsound is NOT handling current JSRF audio. JSRF is
executing its original recompiled DSOUND section. Do not claim that enabling a
CMake target or environment variable will activate the HLE layer; no such
automatic bridge currently exists.


EXACT NEW GAME FREEZE EVIDENCE
==============================
Sample captured after selecting New Game:
  /private/tmp/jsrf-new-game-freeze.sample

Every sampled main-thread stack ended in:
  sub_0016F4B0
    -> sub_0019F17C
    -> sub_0019EB2D
    -> sub_001A490D
    -> sub_001A40F5
    -> sub_001A3E58
    -> sub_001A308E

Original routine 0x001A308E is a 15-byte DSOUND completion wait:

  test byte ptr [ecx+0x12], 1
  je return
  loop:
    test word ptr [ecx+0x12], 0x8000
    jne loop
  return

The main thread stayed in this loop on every sample. At the same time a DSOUND
worker was blocked in bridge_RtlEnterCriticalSection. Renderer, USB/OHCI and APU
threads remained alive. Runtime counters rose to roughly 484 million kernel
calls dominated by critical-section and IRQL churn.

This is the smallest concrete diagnosis:
  JSRF's recompiled DSOUND main path waits synchronously for object+0x12 bit 15
  to clear, but the worker/hardware completion which should clear it cannot make
  progress under the present scheduling/completion model.

The original completion path provides the required state transition:
  0x001A2FB5 tests object+0x12 bit 15
  0x001A2FBE executes: and word ptr [esi+0x12], 0x7fff

For this case the path clears precisely bit 15 and performs no other object work
before returning.


RELATED EARLIER DSOUND OVERRIDE
===============================
File:
  diagnostics/jsrf_first_fault/jsrf_manual_overrides.c

sub_001A1769 is already manually overridden. The original guest function submits
an MCPX DSP command and spins for acknowledgement. The local override returns
S_OK because the GP/EP effects processors are bypassed and the current output is
direct passthrough.

This earlier override allowed the title/audio path to progress far enough to
produce sound. It is not sufficient for the separate 0x001A308E completion wait.


CURRENT 0x001A308E OVERRIDE
===========================
The integration worktree currently has an uncommitted manual implementation in:
  diagnostics/jsrf_first_fault/jsrf_manual_overrides.c

Behaviour:
  - If object+0x12 bit 0 indicates this wait applies, clear bit 15 only.
  - Preserve every other object flag.
  - Apply the correct thiscall return stack adjustment.

This mirrors the exact completion state change observed at 0x001A2FBE and avoids
the impossible busy wait. It is deliberately narrower than bypassing an entire
DirectSound operation or returning a fabricated object.

The recompiler was run with 0x001A308E excluded as a manual function. Generated
calls use RECOMP_ICALL_SAFE for 0x001A308E, and recomp_dispatch.c maps that address
to the manual symbol. The executable compiles and links successfully.

Status limitation:
  The override has not yet received a valid in-game New Game verification.

The first freshly regenerated clean-integration runtime faulted earlier during
startup after unresolved targets 0x00154DAA and 0x0015A0F9. That failure occurred
before the menus and is separate from the DirectSound completion wait. It proves
neither success nor failure of the 0x001A308E override.


CODEBERG JSRF DECOMPILATION STATUS
==================================
Repository:
  https://codeberg.org/KeybadeBlox/JSRF-Decompilation

Checked commit:
  94fa956e42ea641e20c8de126a4762bfe1c600f2
  2026-09-08 "Update progress"

Its ghidra/objects.csv explicitly marks:
  DirectSound8 (need to decompose), false, ... 0x0019E340-0x001BA89B

It does not decompile or name 0x001A308E or 0x001A2FBE. It therefore does not
contain a replacement or fix for the current completion problem.

It does provide useful higher-level names, including:
  0x00118610 CTrtSoundXbox::execNormal
  0x00118630 CTrtSoundXbox::execEvent
  0x00118C00 CTrtSoundXbox constructor
  0x00168130 setupDirectSound_MAYBE

Use these for call-chain annotation, not as evidence that DirectSound has been
implemented there.


XEMU AS A REFERENCE
===================
xemu's full-system emulator runs JSRF far enough for the official compatibility
database to rate the standalone game playable with minor issues. Its full audio
path is therefore the closest working behavioural reference among the projects
examined.

However, xemu still has reports of JSRF audio crackling and later-game freezes.
More importantly, full xemu supplies CPU scheduling, interrupts, timers, MMIO and
the complete surrounding machine model. Copying only its APU source into
xboxrecomp does not automatically reproduce those completion and scheduling
semantics. xboxrecomp already contains an extracted APU subset; the current
0x001A308E deadlock still occurs around it.


OPTIONS AND RECOMMENDATION
==========================
Option A -- finish the narrow guest-DSOUND completion repair (recommended now)
-----------------------------------------------------------------------------
1. Restore the known-working generated/function-discovery state so the integration
   executable reaches the menu again. Do not weaken the unresolved-flags ratchet:
     working dirty-tree generation: 76 dead fallback branches
     fresh clean-integration generation: 112 dead fallback branches
2. Launch with the current manual 0x001A308E override.
3. Select New Game with the physical DualShock.
4. Sample the process if it stops progressing.
5. Verify specifically that the main thread no longer remains in 0x001A308E.
6. If it advances, record the next actual fault separately and evaluate whether
   sound quality changed.

This is the smallest experiment and preserves the already working guest DSOUND
path, current APU output, and existing title progress.

Option B -- introduce a deliberate DirectSound HLE boundary (larger future work)
-------------------------------------------------------------------------------
Do not start by overriding one arbitrary internal helper. First identify the
actual JSRF DirectSoundCreate and public interface boundaries, their calling
conventions, object layouts and vtables. Then write guest-register/guest-memory
wrappers which construct host xbox_dsound objects or guest proxy objects.

Before choosing this route, inventory every JSRF method used. Upstream currently
lacks working stream semantics and much Xbox-specific behaviour, so JSRF may need
substantial extensions. The game's CRI/ADX streaming path makes CreateSoundStream
and packet/completion semantics especially important. A basic static buffer demo
is not evidence that the layer can replace JSRF's DSOUND implementation.

Option C -- model the missing lower-level completion/interrupt behaviour
------------------------------------------------------------------------
Use xemu as the behavioural source and determine what event causes the original
path to clear bit 15: APU voice notification, DSP command completion, deferred
work, interrupt or another service point. This is more faithful than HLE but
larger than validating the exact transition already isolated.


BOUNDED NEXT STEP
=================
Do not redesign DirectSound yet. First make the clean integration executable
reach the menu using the known-good discovery/flag state, then test the existing
0x001A308E override once. The result answers whether the precise completion
transition is sufficient. Only if another DSOUND wait or missing stream operation
becomes the next blocker should the project compare a systematic HLE boundary
against deeper APU completion modelling.


FILES RELEVANT TO THIS HANDOVER
===============================
Local integration worktree:
  diagnostics/jsrf_first_fault/jsrf_manual_overrides.c
  diagnostics/jsrf_first_fault/startup_probe.c
  diagnostics/jsrf_first_fault/instrument_startup.py
  diagnostics/jsrf_first_fault/main.c
  src/audio/dsound_device.c
  src/audio/dsound_xbox.h
  src/audio/README.md
  src/apu/
  src/kernel/xbox_memory_layout.c

Existing broader handover:
  CLAUDE_HANDOVER_2026-09-09_CONTROLLER_NEW_GAME_AUDIO.txt

Runtime sample:
  /private/tmp/jsrf-new-game-freeze.sample

Current dedicated handover:
  CLAUDE_DSOUND_HANDOVER_2026-09-09.txt
