JURASSIC WAR NATIVE WINDOWS PORT 1.10H - AUDIO AUDIT
13 September 2026

Scope: native/audio.c and audio.h, retained-engine audio hooks, host/menu
lifecycle, resource parsing, opening audio, music playback, PCM mixing,
multiplayer spectator routing, replay transport and regression tools.
This is the original game's native Windows port, not the Unreal remake.

HOW THE SYSTEM WORKS

The retained game selects numbered effects and module music through patched
audio hooks. The native layer loads 110 effects from _PWAR06.TRW and 20 music
modules from _PWAR07.TRC. Opening audio uses a separate PCM stream. Local
resources are validated before use. No original audio archive was modified.

Output is stereo 16-bit PCM at 44,100 Hz. Four 512-frame waveOut buffers hold
about 46 milliseconds of submitted audio. A worker maintains output while
the game thread submits commands. A lifecycle gate, shared/exclusive locking
and the mixer critical section protect shutdown, resources and voice state.

The mixer supports 24 PCM voices alongside MOD music and the opening stream.
Voice priorities and a short crossfade handle replacement. Positional effects
use camera-relative pan, visibility filtering and attenuation. A limiter bounds
mixed output. Muted settings suppress output without duplicating game events.
MOD music uses tracker rows/ticks, channel effect state, sample loops and
fractional sample positions. The code supports the effects needed by shipped
tracks; it is not a complete implementation of every tracker extension.

Device handling includes a stalled-output watchdog, bounded reopen attempts
and catch-up that advances audio state instead of accumulating stale buffers.
These existing paths were reviewed alongside callback lifetime and resource
cleanup. Their bounded behavior was retained.

Spectator audio uses a sequence-numbered event ring (32,768 entries) and at
most 64 events per captured frame. Its music state includes resource, order,
row and generation. Replay recording consumes the same positional event feed
without sending recording traffic to other players. The host treats a recorded
mission as a live map audio source to avoid emitting the same local effect
again through a camera-specific fallback.

REPAIRS AND OPTIMIZATION APPLIED

1. Cache the MOD channel sample step at tracker ticks.
   Pitch and effects change at tracker tick boundaries. Previously the sample
   mixer recalculated transposition and division for every output sample.
   Each channel now caches its step at process_mod_tick and mix_mod uses it.
   Whole-track output for all 20 retail modules is bit-for-bit unchanged in
   the raw mixer comparison: identical sample counts and checksums.

2. Correct tone-portamento plus volume-slide (5xy).
   5xy now uses the preceding 3xx speed; xy controls volume slide. Previously
   it could incorrectly become the new pitch slide speed. Nonzero 3xx updates
   the remembered speed at row start, including a row with only one tick.

3. Correct sample-offset memory (9xx/900).
   Nonzero 9xx is remembered per channel; a later note with 900 reuses that
   offset. Previously 900 restarted at offset zero.

4. Correct zero-parameter pitch/volume slides.
   100, 200 and A00 use their zero amount rather than reviving an earlier
   amount. This follows the ProTracker behavior used as the audit reference.

5. Guard pitch after arpeggio transposition.
   An invalid tiny period can truncate to zero during transposition. Clamping
   after that operation prevents division by zero and a nonfinite sample step.

6. Reconstruct mid-song playback state when joining/seeking.
   Loading a module at a later order/row now advances its tracker and sample
   positions from the start to restore tempo, sustained notes and effect
   memory. Merely assigning the row loses that state. Work is bounded; an
   unreachable position uses a safe reset fallback. Existing spectator joins
   benefit from the same repair.

7. Couple replay pause/seek to audio transport.
   Pause emits silence and freezes both regular mixing and device-recovery
   catch-up. Seeking clears old PCM voices and sequence acknowledgements,
   then restores the target music state. Leaving playback restores menu music.
   Already-started short effects are not reconstructed partway through their
   waveform after a seek. Ordinary forward playback uses captured events.

FORMAT REFERENCE

Effect behavior was checked against the ProTracker 2.3D replayer implementation:
https://github.com/8bitbubsy/pt2-clone
https://raw.githubusercontent.com/8bitbubsy/pt2-clone/master/src/pt2_replayer.c
Relevant routines: tonePlusVolSlide, tonePortamento, sampleOffset, portaUp,
portaDown and volumeSlide. No third-party source was copied into the game.

VALIDATION AND EVIDENCE

win11_port/analysis/replay_audio_20260912/audio_baseline_final.log
win11_port/analysis/replay_audio_20260912/audio_current_final.log
  Whole-track render comparison against the backed-up 1.10G audio.c: all 20
  tracks identical over 134,412,558 stereo sample frames (about 50.8 minutes).
  Current audit: 57 checks passed. Synthetic checks include 5xy, 900, zero
  slides, tiny arpeggio periods, sustained-note/tempo reconstruction and pause
  during normal output and a simulated device outage.

  One sequential benchmark measured 3813.85 ms before and 2765.08 ms after.
  This is a local CPU measurement under varying machine load, not a promised
  FPS increase or a hardware-independent percentage improvement. The durable
  optimization is removal of repeated per-sample pitch calculations.

win11_port/analysis/replay_audio_20260912/music_effect_census.json
  All 20 shipped modules were inspected. Their used effects are 1, 2, 4, 9,
  A, C, D, E1 and F. The corrected 5xy/zero-memory cases were latent format
  errors rather than differences heard in these shipped tracks.

win11_port/analysis/replay_audio_matrix_20260912.log
  Existing audio matrix passed all 10 cases from five freshly built variants:
  110-effect catalog, player mixes/overload/mute, spectator mixes/overlap/mute,
  music-only routing and all 20 music resources.

win11_port/analysis/replay_audio_20260912/runtime_final.log
win11_port/analysis/replay_audio_20260912/eight_player_final.log
win11_port/analysis/replay_audio_20260912/coop_transitions_final.log
  Runtime recording/playback transport and multiplayer simulation continued
  successfully with audio and replay capture enabled. Frame-file verification
  also validates recorded audio-event bounds and full-world snapshots.

Compiler /W4 /WX builds pass. MSVC /analyze on audio.c and the new replay.c
passes with no project findings (audio has two existing Windows SDK
waveOutOpen annotation diagnostics). A broader native analysis also reports
existing findings outside audio/replay, including localization cleanup pointer
analysis, a constant catalog comparison and spectator self-test stack usage;
this report does not claim that the entire native tree is analyzer-clean.

LIMITS

The audit validates resource integrity, mixer behavior, event routing and
transport numerically and through the game. It does not certify perceptual
quality on every sound device, Bluetooth latency, physical device unplugging
on multiple drivers, or Internet multiplayer on two separate machines. No
audible-device listening result is inferred from a checksum or a screenshot.

FOLLOW-UP: OUTPUT ORDER AND THUNDER (14 September 2026, version unchanged)

After an audio-worker scheduling delay, several completed output buffers could
straddle the end of the four-buffer queue. Refilling by array index reordered
the sound chunks (for example, 0,2,3 instead of 2,3,0), producing discontinuities.
The worker now tracks submission order and refills only the next completed
buffer. Device reopening initializes the queue position again. Failure and
endpoint-recovery handling are retained.

Thunder uses independent noise, a deeper filtered layer, a smooth rolling
envelope, and a longer decay. The generated preview measured 7.36 seconds of
audible-level samples, peak 11580 and RMS 1712 at High volume. The maximum-volume
combined rain/thunder test remained below 16-bit clipping. These are numerical
measurements, not a listening test on the user's speakers.

Evidence: win11_port/analysis/reported_bugs_20260914
- The actual output worker passed a wrapped 2,3,0 completion-order regression.
- Rain/thunder tests passed independent volumes, five frequencies, Off/Random,
  legacy timing, spectator ownership, mute, pause, seek and exit checks.
- Five freshly built audio harnesses passed the ten-case audio matrix,
  including every shipped sound effect, all 20 music resources, player and
  spectator overload/mute checks, endpoint recovery, and stream playback.
  Log: win11_port/analysis/reported_bugs_audio_matrix_20260914.log
