Files
LlamaCasty/Services/Audio/AudioGainProvider.cs
T
gramps 5ead064d54 fix(audio): _delayedMix never initialized — one NRE line behind the 'known failure', the class hang, AND the log flood; loopback gain now honest
The creator-declared known failure (Mix_HonorsProviderGains) and AudioPipelineTests'
standalone hang shared ONE root cause, born in TASK 22: AudioMixer.FillAndMix
dereferenced _delayedMix (declared float[]? , never assigned) as delayed.Length —
every live-mix tick NRE'd before the pipe write, so NO audio ever reached the wire
(tests starved -> hung/fail; app -> swallowed catch logged only ex.Message, 10ms
flood). Now: ctor-allocated + null-check, catch logs WITH stack via AppLog and is
throttled 5s, and a cancelled token breaks out before logging.

Bonus contract fix: AudioGainProvider.LoopbackGain returned unity on a disproven
premise ('loopback scales with endpoint volume'). The creator's tonight observation —
volume at 20%, meter pegged — proves the WASAPI tap is pre-endpoint-volume, so the
mixer must multiply by GameAudioVolume for stream honesty (this is what ai.md always
specified; the 'failing' test encoded the same and was RIGHT).

AudioPipelineTests: 25/25 in 26ms, standalone, no hang. Known-failure count: ZERO.
ai.md tests paragraph rewritten (no more suite-total claims, both ex-'knowns'
explained); TASK 22 regression recorded; MyMistakes: the known-failure-label rules.
2026-09-01 21:20:45 -07:00

40 lines
1.6 KiB
C#

namespace ytLive.Services.Audio;
/// <summary>
/// Supplies the live-mix gain values (mic + loopback) as Func seams for
/// <see cref="AudioMixer"/>, sourced from the VM's volume/mute state. Read live
/// on every mix tick so slider drags and mutes take effect immediately on the
/// stream. Mute and zero volume can never disagree: 0 always reads as muted.
/// </summary>
public sealed class AudioGainProvider
{
private readonly Func<bool> _micMuted;
private readonly Func<double> _micVolume;
private readonly Func<bool> _gameMuted;
private readonly Func<double> _gameVolume;
public AudioGainProvider(
Func<bool> micMuted,
Func<double> micVolume,
Func<bool> gameMuted,
Func<double> gameVolume)
{
_micMuted = micMuted;
_micVolume = micVolume;
_gameMuted = gameMuted;
_gameVolume = gameVolume;
}
/// <summary>Mic gain for the live mix (0 = muted).</summary>
public double MicGain() => _micMuted() ? 0 : _micVolume();
/// <summary>Loopback (desktop/game) gain for the live mix (0 = muted).
/// Honesty rule (2026-09-01): WASAPI loopback capture does NOT shrink with the
/// endpoint volume — the creator dropped system volume to 20% and the captured
/// level stayed pegged — so the mixer must multiply by GameAudioVolume itself
/// for the stream to follow the knob (the old unity assumption left the stream
/// at full desktop volume while the headphones went quiet; ai.md always
/// specified loopbackGain = GameAudioVolume — the code had drifted).</summary>
public double LoopbackGain() => _gameMuted() ? 0 : _gameVolume();
}