Added a master volume setting.

This commit is contained in:
nashmuhandes 2019-02-27 04:57:28 +08:00 committed by Rachael Alexanderson
parent baf5ebd1ce
commit 407983749a
7 changed files with 25 additions and 3 deletions

View file

@ -98,6 +98,7 @@ extern int SinglePlayerClass[/*MAXPLAYERS*/];
// ------------------------- // -------------------------
// Internal parameters for sound rendering. // Internal parameters for sound rendering.
EXTERN_CVAR (Float, snd_mastervolume) // maximum master volume
EXTERN_CVAR (Float, snd_sfxvolume) // maximum volume for sound EXTERN_CVAR (Float, snd_sfxvolume) // maximum volume for sound
EXTERN_CVAR (Float, snd_musicvolume) // maximum volume for music EXTERN_CVAR (Float, snd_musicvolume) // maximum volume for music

View file

@ -104,7 +104,7 @@ CUSTOM_CVAR (Float, snd_musicvolume, 0.5f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
// Set general music volume. // Set general music volume.
if (GSnd != nullptr) if (GSnd != nullptr)
{ {
GSnd->SetMusicVolume(clamp<float>(self * relative_volume, 0, 1)); GSnd->SetMusicVolume(clamp<float>(self * relative_volume * snd_mastervolume, 0, 1));
} }
// For music not implemented through the digital sound system, // For music not implemented through the digital sound system,
// let them know about the change. // let them know about the change.

View file

@ -543,4 +543,5 @@ MusInfo *SndFile_OpenSong(FileReader &fr);
extern MusInfo *currSong; extern MusInfo *currSong;
void MIDIDeviceChanged(int newdev, bool force = false); void MIDIDeviceChanged(int newdev, bool force = false);
EXTERN_CVAR (Float, snd_mastervolume)
EXTERN_CVAR (Float, snd_musicvolume) EXTERN_CVAR (Float, snd_musicvolume)

View file

@ -50,6 +50,7 @@
#include "stats.h" #include "stats.h"
EXTERN_CVAR (Float, snd_sfxvolume) EXTERN_CVAR (Float, snd_sfxvolume)
EXTERN_CVAR (Float, snd_musicvolume)
CVAR (Int, snd_samplerate, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Int, snd_samplerate, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Int, snd_buffersize, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Int, snd_buffersize, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Int, snd_hrtf, -1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Int, snd_hrtf, -1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
@ -76,6 +77,23 @@ void I_CloseSound ();
// SFX API // SFX API
// //
//==========================================================================
//
// CVAR snd_mastervolume
//
// Maximum volume of all audio
//==========================================================================
CUSTOM_CVAR(Float, snd_mastervolume, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
if (self < 0.f)
self = 0.f;
else if (self > 1.f)
self = 1.f;
snd_sfxvolume.Callback();
snd_musicvolume.Callback();
}
//========================================================================== //==========================================================================
// //
// CVAR snd_sfxvolume // CVAR snd_sfxvolume
@ -91,7 +109,7 @@ CUSTOM_CVAR (Float, snd_sfxvolume, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOIN
self = 1.f; self = 1.f;
else if (GSnd != NULL) else if (GSnd != NULL)
{ {
GSnd->SetSfxVolume (self); GSnd->SetSfxVolume (self * snd_mastervolume);
} }
} }

View file

@ -546,7 +546,7 @@ void MIDIStreamer::MusicVolumeChanged()
{ {
if (MIDI != NULL && MIDI->FakeVolume()) if (MIDI != NULL && MIDI->FakeVolume())
{ {
float realvolume = clamp<float>(snd_musicvolume * relative_volume, 0.f, 1.f); float realvolume = clamp<float>(snd_musicvolume * relative_volume * snd_mastervolume, 0.f, 1.f);
Volume = clamp<uint32_t>((uint32_t)(realvolume * 65535.f), 0, 65535); Volume = clamp<uint32_t>((uint32_t)(realvolume * 65535.f), 0, 65535);
} }
else else

View file

@ -2201,6 +2201,7 @@ CMPTMNU_CHECKSWITCHRANGE = "Enable buggy CheckSwitchRange behavior";
// Sound Options // Sound Options
SNDMNU_TITLE = "Sound Options"; SNDMNU_TITLE = "Sound Options";
SNDMNU_MASTERVOLUME = "Master volume";
SNDMNU_SFXVOLUME = "Sounds volume"; SNDMNU_SFXVOLUME = "Sounds volume";
SNDMNU_MENUVOLUME = "Menu volume"; SNDMNU_MENUVOLUME = "Menu volume";
SNDMNU_MUSICVOLUME = "Music volume"; SNDMNU_MUSICVOLUME = "Music volume";

View file

@ -1741,6 +1741,7 @@ OptionValue MidiDevices
OptionMenu SoundOptions protected OptionMenu SoundOptions protected
{ {
Title "$SNDMNU_TITLE" Title "$SNDMNU_TITLE"
Slider "$SNDMNU_MASTERVOLUME", "snd_mastervolume", 0, 1, 0.05, 2
Slider "$SNDMNU_SFXVOLUME", "snd_sfxvolume", 0, 1, 0.05, 2 Slider "$SNDMNU_SFXVOLUME", "snd_sfxvolume", 0, 1, 0.05, 2
Slider "$SNDMNU_MENUVOLUME", "snd_menuvolume", 0, 1, 0.05, 2 Slider "$SNDMNU_MENUVOLUME", "snd_menuvolume", 0, 1, 0.05, 2
Slider "$SNDMNU_MUSICVOLUME", "snd_musicvolume", 0, 1, 0.05, 2 Slider "$SNDMNU_MUSICVOLUME", "snd_musicvolume", 0, 1, 0.05, 2