From 407983749aebce737228f58a6f8cecc108ca43ab Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Wed, 27 Feb 2019 04:57:28 +0800 Subject: [PATCH] Added a master volume setting. --- src/doomstat.h | 1 + src/sound/i_music.cpp | 2 +- src/sound/i_musicinterns.h | 1 + src/sound/i_sound.cpp | 20 +++++++++++++++++++- src/sound/musicformats/music_midistream.cpp | 2 +- wadsrc/static/language.enu | 1 + wadsrc/static/menudef.txt | 1 + 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/doomstat.h b/src/doomstat.h index 23356b25f..9f057894f 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -98,6 +98,7 @@ extern int SinglePlayerClass[/*MAXPLAYERS*/]; // ------------------------- // 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_musicvolume) // maximum volume for music diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index 877c03e39..f4b932695 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -104,7 +104,7 @@ CUSTOM_CVAR (Float, snd_musicvolume, 0.5f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // Set general music volume. if (GSnd != nullptr) { - GSnd->SetMusicVolume(clamp(self * relative_volume, 0, 1)); + GSnd->SetMusicVolume(clamp(self * relative_volume * snd_mastervolume, 0, 1)); } // For music not implemented through the digital sound system, // let them know about the change. diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 0143fcb25..22cbcf3af 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -543,4 +543,5 @@ MusInfo *SndFile_OpenSong(FileReader &fr); extern MusInfo *currSong; void MIDIDeviceChanged(int newdev, bool force = false); +EXTERN_CVAR (Float, snd_mastervolume) EXTERN_CVAR (Float, snd_musicvolume) diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index de9c9a6a9..7820d5734 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -50,6 +50,7 @@ #include "stats.h" EXTERN_CVAR (Float, snd_sfxvolume) +EXTERN_CVAR (Float, snd_musicvolume) CVAR (Int, snd_samplerate, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Int, snd_buffersize, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Int, snd_hrtf, -1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) @@ -76,6 +77,23 @@ void I_CloseSound (); // 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 @@ -91,7 +109,7 @@ CUSTOM_CVAR (Float, snd_sfxvolume, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOIN self = 1.f; else if (GSnd != NULL) { - GSnd->SetSfxVolume (self); + GSnd->SetSfxVolume (self * snd_mastervolume); } } diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index 60061b264..ce0c82684 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -546,7 +546,7 @@ void MIDIStreamer::MusicVolumeChanged() { if (MIDI != NULL && MIDI->FakeVolume()) { - float realvolume = clamp(snd_musicvolume * relative_volume, 0.f, 1.f); + float realvolume = clamp(snd_musicvolume * relative_volume * snd_mastervolume, 0.f, 1.f); Volume = clamp((uint32_t)(realvolume * 65535.f), 0, 65535); } else diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index a43247c25..0c76ada36 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2201,6 +2201,7 @@ CMPTMNU_CHECKSWITCHRANGE = "Enable buggy CheckSwitchRange behavior"; // Sound Options SNDMNU_TITLE = "Sound Options"; +SNDMNU_MASTERVOLUME = "Master volume"; SNDMNU_SFXVOLUME = "Sounds volume"; SNDMNU_MENUVOLUME = "Menu volume"; SNDMNU_MUSICVOLUME = "Music volume"; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index ae0d1def1..3d5330c16 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -1741,6 +1741,7 @@ OptionValue MidiDevices OptionMenu SoundOptions protected { 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_MENUVOLUME", "snd_menuvolume", 0, 1, 0.05, 2 Slider "$SNDMNU_MUSICVOLUME", "snd_musicvolume", 0, 1, 0.05, 2