Closed HomelessMage closed 1 year ago
public void UpdateVoipSound() {
if (VoipSound == null || !VoipSound.IsPlaying) {
radioNoiseChannel?.Dispose();
radioNoiseChannel = null;
if (VoipSound != null) {
DebugConsole.Log("Destroying voipsound");
VoipSound.Dispose();
}
VoipSound = null;
return;
}
if (Screen.Selected is ModDownloadScreen) {
VoipSound.Gain = 0.0 f;
}
float gain = 1.0 f;
float noiseGain = 0.0 f;
Vector3 ? position = null;
if (character != null) {
if (GameSettings.CurrentConfig.Audio.UseDirectionalVoiceChat) {
position = new Vector3(character.WorldPosition.X, character.WorldPosition.Y, 0.0 f);
} else {
float dist = Vector3.Distance(new Vector3(character.WorldPosition, 0.0 f), GameMain.SoundManager.ListenerPosition);
gain = 1.0 f - MathUtils.InverseLerp(VoipSound.Near, VoipSound.Far, dist);
}
if (RadioNoise > 0.0 f) {
noiseGain = gain * RadioNoise;
gain *= 1.0 f - RadioNoise;
}
}
VoipSound.SetPosition(position);
VoipSound.Gain = gain;
if (noiseGain > 0.0 f) {
if (radioNoiseChannel == null || !radioNoiseChannel.IsPlaying) {
radioNoiseChannel = SoundPlayer.PlaySound("radiostatic");
radioNoiseChannel.Category = "voip";
radioNoiseChannel.Looping = true;
}
radioNoiseChannel.Near = VoipSound.Near;
radioNoiseChannel.Far = VoipSound.Far;
radioNoiseChannel.Position = position;
radioNoiseChannel.Gain = noiseGain;
} else if (radioNoiseChannel != null) {
radioNoiseChannel.Gain = 0.0 f;
}
}