Ramp a changed volume across the audio frame instead of applying it at once.

The mixer applied each voice's mix volume and each splitter destination's
volume to a whole 5 ms frame as one constant, so the level jumped at the
frame's first sample whenever the game moved a volume, which is heard as a
click. It now keeps what each voice and each splitter destination was mixed
with in the frame before and goes from there to the new value in equal steps
across the frame's samples, as the console's renderer does. An unchanged
volume stays on the constant path.

A voice that has just started, one that was silent in the frame before or was
moved to another mix or splitter, a destination that is new or was moved, and
the first frame after the renderer starts take the new volume at once.

NX2NAVI_AUDIO_RAMP=0 turns the ramps off. The audio statistics line counts the
render passes that ramped a volume. tests/audio_mixer_check.py builds the
mixer with the rest of the runtime stubbed and checks the ramps and the cases
that must not ramp.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 15:10:29 -05:00
parent 202fd47ceb
commit 42d16e7f0b
8 changed files with 476 additions and 10 deletions

View File

@@ -147,6 +147,15 @@ typedef struct {
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
// Volume ramps (audio_mixer.c audio_mixer_render): what the voice was mixed with in its last render pass. The pass
// after it starts every gain there and reaches the new volumes at its end; voice_reset (audren.c) forgets it.
uint64_t ramp_pass; // 1 + the render pass the voice was last mixed in, 0 when it has none to ramp from
int32_t ramp_mix; // the mix and
uint32_t ramp_splitter; // the splitter it went to then, and
uint32_t ramp_channels; // its channel count: a pass with another of these starts at the new volumes
int32_t ramp_buffers; // into a mix: how many of the mix's buffers ramp_gain holds
float ramp_volume; // into a splitter: the voice's volume then (the destinations keep their own)
float ramp_gain[6][24]; // into a mix: the gain channel c went into buffer b with (NaN: nothing went in)
} ServerVoice;
enum { SV_STOPPED, SV_STARTED, SV_PAUSED, SV_STOPPING };
@@ -191,6 +200,9 @@ int64_t audio_mixer_pace_ns(AudioRenderer *r, uint64_t now);
// 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);
// NX2NAVI_AUDIO_STATS: the render passes in which at least one volume was ramped (NX2NAVI_AUDIO_RAMP), and the ramps (one
// source channel into one mix buffer), since the mixer opened.
void audio_mixer_ramp_stats(const AudioRenderer *r, uint64_t *passes, uint64_t *ramps);
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