Add audio underrun and late-update counters, and a knob for the priority of the game's audio thread.

NX2NAVI_AUDIO_STATS=1 logs output underruns, late passes of the audio render thread, waits for the renderer lock,
late audio updates from the game and voices that ran out of queued sound, each with the game frame, to find where
a crackle comes from. NX2NAVI_AUDIO_GAME_PRIO raises the thread that sends RequestUpdate while its update is read
(1) or also keeps it above normal (2). Both are off by default, so the audio path behaves as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tangerineturtle1
2026-11-09 06:09:18 -05:00
committed by chrg6
parent fe3cca739b
commit 762bd3f934
5 changed files with 215 additions and 2 deletions

View File

@@ -145,6 +145,8 @@ typedef struct {
uint32_t consumed, drops;
struct { int16_t history[2]; int32_t buffer; uint64_t at; } adpcm; // DSP-ADPCM decode cursor (buffer slot, next sample) and history
float biquad_state[2][6][2]; // filter, channel: transposed direct-form II delays
uint64_t dry_pass; // NX2NAVI_AUDIO_STATS: 1 + the render pass in which the voice ran out of queued
// buffers before its end of stream (audren.c advance_voice), 0 otherwise
} ServerVoice;
enum { SV_STOPPED, SV_STARTED, SV_PAUSED, SV_STOPPING };
@@ -157,6 +159,7 @@ typedef struct AudioRenderer {
int logged;
uint64_t behavior_flags, elapsed_frames;
uint64_t stop_released, empty_played, flushed, logged_released;
struct AudrenStats *stats; // NX2NAVI_AUDIO_STATS (audren.c), NULL when off
ServerVoice *voices;
AudrenPoolIn *pools;
AudrenMixIn *mixes;
@@ -184,6 +187,10 @@ void audio_mixer_render(AudioRenderer *r, double seconds); // after audio_voic
// many ns (the ring is at its target), -1 leaves the pace to the render thread's timer (no device, renderer stopped,
// device stalled).
int64_t audio_mixer_pace_ns(AudioRenderer *r, uint64_t now);
// NX2NAVI_AUDIO_STATS: the output's counters since it opened, and the longest gap between two device requests since
// the last call (which starts that measure again). False without a device.
typedef struct { uint64_t underruns, missing_frames, skipped_frames, overruns, queued_frames, pull_gap_max_ns; } AudioOutStats;
int audio_mixer_out_stats(AudioRenderer *r, AudioOutStats *o);
uint64_t audio_voice_consumed(const AudioRenderer *r, ServerVoice *v, int frames); // source samples over one frame; advances v->fraction
int audio_buffer_empty(const AudrenWaveBuffer *b); // no samples to decode: played as soon as it is reached
void audio_device_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs); // IAudioDevice