Files
LlamaCasty/Services/Audio/AudioGainProvider.cs
T

36 lines
1.3 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, 1 = unity).
/// Unity because the slider now drives system volume via PushSystemVolume,
/// so the WASAPI loopback signal is already scaled by the user's volume choice.</summary>
public double LoopbackGain() => _gameMuted() ? 0 : 1.0;
}