Make audio sliders use gain not volume (#21984)
This commit is contained in:
@@ -101,7 +101,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
|
|||||||
_cfg.OnValueChanged(CCVars.AmbientCooldown, SetCooldown, true);
|
_cfg.OnValueChanged(CCVars.AmbientCooldown, SetCooldown, true);
|
||||||
_cfg.OnValueChanged(CCVars.MaxAmbientSources, SetAmbientCount, true);
|
_cfg.OnValueChanged(CCVars.MaxAmbientSources, SetAmbientCount, true);
|
||||||
_cfg.OnValueChanged(CCVars.AmbientRange, SetAmbientRange, true);
|
_cfg.OnValueChanged(CCVars.AmbientRange, SetAmbientRange, true);
|
||||||
_cfg.OnValueChanged(CCVars.AmbienceVolume, SetAmbienceVolume, true);
|
_cfg.OnValueChanged(CCVars.AmbienceVolume, SetAmbienceGain, true);
|
||||||
SubscribeLocalEvent<AmbientSoundComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<AmbientSoundComponent, ComponentShutdown>(OnShutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,9 +116,9 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
|
|||||||
_playingCount.Remove(sound.Path);
|
_playingCount.Remove(sound.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetAmbienceVolume(float value)
|
private void SetAmbienceGain(float value)
|
||||||
{
|
{
|
||||||
_ambienceVolume = value;
|
_ambienceVolume = SharedAudioSystem.GainToVolume(value);
|
||||||
|
|
||||||
foreach (var (comp, values) in _playingSounds)
|
foreach (var (comp, values) in _playingSounds)
|
||||||
{
|
{
|
||||||
@@ -141,7 +141,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
|
|||||||
_cfg.UnsubValueChanged(CCVars.AmbientCooldown, SetCooldown);
|
_cfg.UnsubValueChanged(CCVars.AmbientCooldown, SetCooldown);
|
||||||
_cfg.UnsubValueChanged(CCVars.MaxAmbientSources, SetAmbientCount);
|
_cfg.UnsubValueChanged(CCVars.MaxAmbientSources, SetAmbientCount);
|
||||||
_cfg.UnsubValueChanged(CCVars.AmbientRange, SetAmbientRange);
|
_cfg.UnsubValueChanged(CCVars.AmbientRange, SetAmbientRange);
|
||||||
_cfg.UnsubValueChanged(CCVars.AmbienceVolume, SetAmbienceVolume);
|
_cfg.UnsubValueChanged(CCVars.AmbienceVolume, SetAmbienceGain);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int PlayingCount(string countSound)
|
private int PlayingCount(string countSound)
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public sealed class BackgroundAudioSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
_lobbyStream = _audio.PlayGlobal(file, Filter.Local(), false,
|
_lobbyStream = _audio.PlayGlobal(file, Filter.Local(), false,
|
||||||
_lobbyParams.WithVolume(_lobbyParams.Volume + _configManager.GetCVar(CCVars.LobbyMusicVolume)))?.Entity;
|
_lobbyParams.WithVolume(_lobbyParams.Volume + SharedAudioSystem.GainToVolume(_configManager.GetCVar(CCVars.LobbyMusicVolume))))?.Entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EndLobbyMusic()
|
private void EndLobbyMusic()
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public sealed partial class ContentAudioSystem
|
|||||||
|
|
||||||
private void AmbienceCVarChanged(float obj)
|
private void AmbienceCVarChanged(float obj)
|
||||||
{
|
{
|
||||||
_volumeSlider = obj;
|
_volumeSlider = SharedAudioSystem.GainToVolume(obj);
|
||||||
|
|
||||||
if (_ambientMusicStream != null && _musicProto != null)
|
if (_ambientMusicStream != null && _musicProto != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
|
using Content.Shared.CCVar;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
|
using Robust.Shared;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using AudioComponent = Robust.Shared.Audio.Components.AudioComponent;
|
using AudioComponent = Robust.Shared.Audio.Components.AudioComponent;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Robust.Client.UserInterface;
|
|||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared;
|
using Robust.Shared;
|
||||||
|
using Robust.Shared.Audio.Systems;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
using Range = Robust.Client.UserInterface.Controls.Range;
|
using Range = Robust.Client.UserInterface.Controls.Range;
|
||||||
|
|
||||||
@@ -16,14 +17,14 @@ namespace Content.Client.Options.UI.Tabs
|
|||||||
public sealed partial class AudioTab : Control
|
public sealed partial class AudioTab : Control
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||||
private readonly AudioSystem _audio;
|
private readonly IAudioManager _audio;
|
||||||
|
|
||||||
public AudioTab()
|
public AudioTab()
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
_audio = IoCManager.Resolve<IEntityManager>().System<AudioSystem>();
|
_audio = IoCManager.Resolve<IAudioManager>();
|
||||||
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||||
RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled);
|
RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled);
|
||||||
EventMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.EventMusicEnabled);
|
EventMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.EventMusicEnabled);
|
||||||
@@ -82,7 +83,7 @@ namespace Content.Client.Options.UI.Tabs
|
|||||||
|
|
||||||
private void OnMasterVolumeSliderChanged(Range range)
|
private void OnMasterVolumeSliderChanged(Range range)
|
||||||
{
|
{
|
||||||
_audio.SetMasterVolume(MasterVolumeSlider.Value / 100);
|
_audio.SetMasterGain(MasterVolumeSlider.Value / 100f);
|
||||||
UpdateChanges();
|
UpdateChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,15 +112,16 @@ namespace Content.Client.Options.UI.Tabs
|
|||||||
|
|
||||||
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
|
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
|
||||||
{
|
{
|
||||||
_cfg.SetCVar(CVars.AudioMasterVolume, LV100ToDB(MasterVolumeSlider.Value, CCVars.MasterMultiplier));
|
_cfg.SetCVar(CVars.AudioMasterVolume, MasterVolumeSlider.Value / 100f);
|
||||||
// Want the CVar updated values to have the multiplier applied
|
// Want the CVar updated values to have the multiplier applied
|
||||||
// For the UI we just display 0-100 still elsewhere
|
// For the UI we just display 0-100 still elsewhere
|
||||||
_cfg.SetCVar(CVars.MidiVolume, LV100ToDB(MidiVolumeSlider.Value, CCVars.MidiMultiplier));
|
_cfg.SetCVar(CVars.MidiVolume, MidiVolumeSlider.Value / 100f);
|
||||||
_cfg.SetCVar(CCVars.AmbienceVolume, LV100ToDB(AmbienceVolumeSlider.Value, CCVars.AmbienceMultiplier));
|
_cfg.SetCVar(CCVars.AmbienceVolume, AmbienceVolumeSlider.Value / 100f);
|
||||||
_cfg.SetCVar(CCVars.AmbientMusicVolume, LV100ToDB(AmbientMusicVolumeSlider.Value, CCVars.AmbientMusicMultiplier));
|
_cfg.SetCVar(CCVars.AmbientMusicVolume, AmbientMusicVolumeSlider.Value / 100f);
|
||||||
|
_cfg.SetCVar(CCVars.LobbyMusicVolume, LobbyVolumeSlider.Value / 100f);
|
||||||
|
|
||||||
_cfg.SetCVar(CCVars.LobbyMusicVolume, LV100ToDB(LobbyVolumeSlider.Value));
|
|
||||||
_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
|
_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
|
||||||
|
|
||||||
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
|
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
|
||||||
_cfg.SetCVar(CCVars.RestartSoundsEnabled, RestartSoundsCheckBox.Pressed);
|
_cfg.SetCVar(CCVars.RestartSoundsEnabled, RestartSoundsCheckBox.Pressed);
|
||||||
_cfg.SetCVar(CCVars.EventMusicEnabled, EventMusicCheckBox.Pressed);
|
_cfg.SetCVar(CCVars.EventMusicEnabled, EventMusicCheckBox.Pressed);
|
||||||
@@ -135,13 +137,14 @@ namespace Content.Client.Options.UI.Tabs
|
|||||||
|
|
||||||
private void Reset()
|
private void Reset()
|
||||||
{
|
{
|
||||||
MasterVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CVars.AudioMasterVolume), CCVars.MasterMultiplier);
|
MasterVolumeSlider.Value = _cfg.GetCVar(CVars.AudioMasterVolume) * 100f;
|
||||||
MidiVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CVars.MidiVolume), CCVars.MidiMultiplier);
|
MidiVolumeSlider.Value = _cfg.GetCVar(CVars.MidiVolume) * 100f;
|
||||||
AmbienceVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume), CCVars.AmbienceMultiplier);
|
AmbienceVolumeSlider.Value = _cfg.GetCVar(CCVars.AmbienceVolume) * 100f;
|
||||||
AmbientMusicVolumeSlider.Value =
|
AmbientMusicVolumeSlider.Value = _cfg.GetCVar(CCVars.AmbientMusicVolume) * 100f;
|
||||||
DBToLV100(_cfg.GetCVar(CCVars.AmbientMusicVolume), CCVars.AmbientMusicMultiplier);
|
LobbyVolumeSlider.Value = _cfg.GetCVar(CCVars.LobbyMusicVolume) * 100f;
|
||||||
LobbyVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.LobbyMusicVolume));
|
|
||||||
AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
|
AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||||
|
|
||||||
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||||
RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled);
|
RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled);
|
||||||
EventMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.EventMusicEnabled);
|
EventMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.EventMusicEnabled);
|
||||||
@@ -149,33 +152,25 @@ namespace Content.Client.Options.UI.Tabs
|
|||||||
UpdateChanges();
|
UpdateChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Rather than moving these functions somewhere, instead switch MidiManager to using linear units rather than dB
|
private float GetGain(float value)
|
||||||
// Do be sure to rename the setting though
|
|
||||||
private float DBToLV100(float db, float multiplier = 1f)
|
|
||||||
{
|
{
|
||||||
var beri = (float) (Math.Pow(10, db / 10) * 100 / multiplier);
|
return value;
|
||||||
return beri;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float LV100ToDB(float lv100, float multiplier = 1f)
|
|
||||||
{
|
|
||||||
// Saving negative infinity doesn't work, so use -10000000 instead (MidiManager does it)
|
|
||||||
var weh = MathF.Max(-10000000, (float) (Math.Log(lv100 * multiplier / 100, 10) * 10));
|
|
||||||
return weh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateChanges()
|
private void UpdateChanges()
|
||||||
{
|
{
|
||||||
|
// y'all need jesus.
|
||||||
var isMasterVolumeSame =
|
var isMasterVolumeSame =
|
||||||
Math.Abs(MasterVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CVars.AudioMasterVolume), CCVars.MasterMultiplier)) < 0.01f;
|
Math.Abs(MasterVolumeSlider.Value - _cfg.GetCVar(CVars.AudioMasterVolume) * 100f) < 0.01f;
|
||||||
var isMidiVolumeSame =
|
var isMidiVolumeSame =
|
||||||
Math.Abs(MidiVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CVars.MidiVolume), CCVars.MidiMultiplier)) < 0.01f;
|
Math.Abs(MidiVolumeSlider.Value - _cfg.GetCVar(CVars.MidiVolume) * 100f) < 0.01f;
|
||||||
var isAmbientVolumeSame =
|
var isAmbientVolumeSame =
|
||||||
Math.Abs(AmbienceVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume), CCVars.AmbienceMultiplier)) < 0.01f;
|
Math.Abs(AmbienceVolumeSlider.Value - _cfg.GetCVar(CCVars.AmbienceVolume) * 100f) < 0.01f;
|
||||||
var isAmbientMusicVolumeSame =
|
var isAmbientMusicVolumeSame =
|
||||||
Math.Abs(AmbientMusicVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbientMusicVolume), CCVars.AmbientMusicMultiplier)) < 0.01f;
|
Math.Abs(AmbientMusicVolumeSlider.Value - _cfg.GetCVar(CCVars.AmbientMusicVolume) * 100f) < 0.01f;
|
||||||
var isLobbyVolumeSame =
|
var isLobbyVolumeSame =
|
||||||
Math.Abs(LobbyVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.LobbyMusicVolume))) < 0.01f;
|
Math.Abs(LobbyVolumeSlider.Value - _cfg.GetCVar(CCVars.LobbyMusicVolume) * 100f) < 0.01f;
|
||||||
|
|
||||||
var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
|
var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
|
||||||
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
|
||||||
var isRestartSoundsSame = RestartSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.RestartSoundsEnabled);
|
var isRestartSoundsSame = RestartSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.RestartSoundsEnabled);
|
||||||
|
|||||||
@@ -67,28 +67,19 @@ namespace Content.Shared.CCVar
|
|||||||
/// Ambience volume.
|
/// Ambience volume.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly CVarDef<float> AmbienceVolume =
|
public static readonly CVarDef<float> AmbienceVolume =
|
||||||
CVarDef.Create("ambience.volume", 0.0f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
CVarDef.Create("ambience.volume", 0.50f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||||
|
|
||||||
public const float MasterMultiplier = 2f;
|
|
||||||
|
|
||||||
// Midi is on engine so deal
|
|
||||||
public const float MidiMultiplier = 3f;
|
|
||||||
|
|
||||||
public const float AmbienceMultiplier = 2f;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ambience music volume.
|
/// Ambience music volume.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly CVarDef<float> AmbientMusicVolume =
|
public static readonly CVarDef<float> AmbientMusicVolume =
|
||||||
CVarDef.Create("ambience.music_volume", 0.0f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
CVarDef.Create("ambience.music_volume", 0.50f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||||
|
|
||||||
public const float AmbientMusicMultiplier = 2f;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lobby / round end music volume.
|
/// Lobby / round end music volume.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly CVarDef<float> LobbyMusicVolume =
|
public static readonly CVarDef<float> LobbyMusicVolume =
|
||||||
CVarDef.Create("ambience.lobby_music_volume", 0.0f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
CVarDef.Create("ambience.lobby_music_volume", 0.50f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Status
|
* Status
|
||||||
|
|||||||
Reference in New Issue
Block a user