mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Merge branch 'independent-master-gain' into 'master'
Make master volume an independent gain control See merge request KartKrew/Kart!1835
This commit is contained in:
commit
0464f46cd3
6 changed files with 47 additions and 67 deletions
|
|
@ -324,12 +324,9 @@ consvar_t cv_controlperkey = Player("controlperkey", "One").values({{1, "One"},
|
|||
// actual general (maximum) sound & music volume, saved into the config
|
||||
// Volume scale is 0-100 in new mixer. 100 is treated as -0dB or 100% gain. No more weirdness to work around SDL_mixer
|
||||
// problems
|
||||
void MasterVolume_OnChange(void);
|
||||
void DigMusicVolume_OnChange(void);
|
||||
void SoundVolume_OnChange(void);
|
||||
consvar_t cv_mastervolume = Player("volume", "80").min_max(0, 100).onchange_noinit(MasterVolume_OnChange);
|
||||
consvar_t cv_digmusicvolume = Player("musicvolume", "80").min_max(0, 100).onchange_noinit(DigMusicVolume_OnChange);
|
||||
consvar_t cv_soundvolume = Player("soundvolume", "80").min_max(0, 100).onchange_noinit(SoundVolume_OnChange);
|
||||
consvar_t cv_mastervolume = Player("volume", "80").min_max(0, 100);
|
||||
consvar_t cv_digmusicvolume = Player("musicvolume", "80").min_max(0, 100);
|
||||
consvar_t cv_soundvolume = Player("soundvolume", "80").min_max(0, 100);
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
void DRPC_UpdatePresence(void);
|
||||
|
|
|
|||
|
|
@ -232,6 +232,8 @@ void I_SetCurrentSongVolume(int volume);
|
|||
|
||||
boolean I_SetSongTrack(INT32 track);
|
||||
|
||||
void I_SetMasterVolume(int volume);
|
||||
|
||||
/// ------------------------
|
||||
/// MUSIC FADING
|
||||
/// ------------------------
|
||||
|
|
|
|||
|
|
@ -97,19 +97,11 @@ struct Slider
|
|||
|
||||
void input(INT32 c)
|
||||
{
|
||||
if (c == -1 && &volume_ == &cv_mastervolume)
|
||||
M_ChangeCvarDirect(c, &volume_);
|
||||
|
||||
if (!toggle_(false))
|
||||
{
|
||||
// Master volume does not necessarily change when
|
||||
// music or sound volumes change separately. So
|
||||
// cv_mastervolume could still have its default
|
||||
// value, and M_ChangeCvarDirect would do
|
||||
// nothing.
|
||||
CV_Set(&cv_digmusicvolume, cv_mastervolume.defaultvalue);
|
||||
CV_Set(&cv_soundvolume, cv_mastervolume.defaultvalue);
|
||||
}
|
||||
else
|
||||
{
|
||||
M_ChangeCvarDirect(c, &volume_);
|
||||
toggle_(true);
|
||||
}
|
||||
|
||||
shake_ = !shake_;
|
||||
|
|
@ -186,7 +178,7 @@ void draw_routine()
|
|||
sliders.at(it.mvar2).draw(
|
||||
x,
|
||||
y,
|
||||
it.mvar2 == Slider::kMasterVolume,
|
||||
false,
|
||||
i == itemOn
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -660,6 +660,7 @@ void S_StopSound(void *origin)
|
|||
//
|
||||
static INT32 actualsfxvolume; // check for change through console
|
||||
static INT32 actualdigmusicvolume;
|
||||
static INT32 actualmastervolume;
|
||||
|
||||
void S_UpdateSounds(void)
|
||||
{
|
||||
|
|
@ -676,6 +677,8 @@ void S_UpdateSounds(void)
|
|||
S_SetSfxVolume();
|
||||
if (actualdigmusicvolume != cv_digmusicvolume.value)
|
||||
S_SetMusicVolume();
|
||||
if (actualmastervolume != cv_mastervolume.value)
|
||||
S_SetMasterVolume();
|
||||
|
||||
// We're done now, if we're not in a level.
|
||||
if (gamestate != GS_LEVEL)
|
||||
|
|
@ -869,6 +872,13 @@ void S_SetSfxVolume(void)
|
|||
I_SetSfxVolume(actualsfxvolume);
|
||||
}
|
||||
|
||||
void S_SetMasterVolume(void)
|
||||
{
|
||||
actualmastervolume = cv_mastervolume.value;
|
||||
|
||||
I_SetMasterVolume(actualmastervolume);
|
||||
}
|
||||
|
||||
void S_ClearSfx(void)
|
||||
{
|
||||
size_t i;
|
||||
|
|
@ -2325,6 +2335,7 @@ static void Command_RestartAudio_f(void)
|
|||
|
||||
S_SetSfxVolume();
|
||||
S_SetMusicVolume();
|
||||
S_SetMasterVolume();
|
||||
|
||||
S_StartSound(NULL, sfx_strpst);
|
||||
|
||||
|
|
@ -2492,6 +2503,9 @@ void GameSounds_OnChange(void)
|
|||
if (M_CheckParm("-nosound") || M_CheckParm("-noaudio"))
|
||||
return;
|
||||
|
||||
if (cv_gamesounds.value != sound_disabled)
|
||||
return;
|
||||
|
||||
if (sound_disabled)
|
||||
{
|
||||
sound_disabled = false;
|
||||
|
|
@ -2514,6 +2528,9 @@ void GameDigiMusic_OnChange(void)
|
|||
else if (M_CheckParm("-nodigmusic"))
|
||||
return;
|
||||
|
||||
if (cv_gamedigimusic.value != digital_disabled)
|
||||
return;
|
||||
|
||||
if (digital_disabled)
|
||||
{
|
||||
digital_disabled = false;
|
||||
|
|
@ -2528,49 +2545,6 @@ void GameDigiMusic_OnChange(void)
|
|||
}
|
||||
}
|
||||
|
||||
void MasterVolume_OnChange(void);
|
||||
void MasterVolume_OnChange(void)
|
||||
{
|
||||
INT32 adj = cv_mastervolume.value - max(cv_digmusicvolume.value, cv_soundvolume.value);
|
||||
|
||||
if (adj < 0)
|
||||
{
|
||||
INT32 under = min(cv_digmusicvolume.value, cv_soundvolume.value) + adj;
|
||||
|
||||
if (under < 0)
|
||||
{
|
||||
// Ensure balance between music/sound volume does
|
||||
// not change at lower bound. (This is already
|
||||
// guaranteed at upper bound.)
|
||||
adj -= under;
|
||||
CV_StealthSetValue(&cv_mastervolume, cv_mastervolume.value - under);
|
||||
}
|
||||
}
|
||||
|
||||
CV_SetValue(&cv_digmusicvolume, cv_digmusicvolume.value + adj);
|
||||
CV_SetValue(&cv_soundvolume, cv_soundvolume.value + adj);
|
||||
}
|
||||
|
||||
void DigMusicVolume_OnChange(void);
|
||||
void DigMusicVolume_OnChange(void)
|
||||
{
|
||||
if (!cv_gamedigimusic.value && !con_startup)
|
||||
{
|
||||
CV_SetValue(&cv_gamedigimusic, 1);
|
||||
}
|
||||
CV_StealthSetValue(&cv_mastervolume, max(cv_digmusicvolume.value, cv_soundvolume.value));
|
||||
}
|
||||
|
||||
void SoundVolume_OnChange(void);
|
||||
void SoundVolume_OnChange(void)
|
||||
{
|
||||
if (!cv_gamesounds.value && !con_startup)
|
||||
{
|
||||
CV_SetValue(&cv_gamesounds, 1);
|
||||
}
|
||||
CV_StealthSetValue(&cv_mastervolume, max(cv_digmusicvolume.value, cv_soundvolume.value));
|
||||
}
|
||||
|
||||
void BGAudio_OnChange(void);
|
||||
void BGAudio_OnChange(void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ extern "C" {
|
|||
#define DEFAULT_MUSICDEF_VOLUME 100
|
||||
|
||||
extern consvar_t stereoreverse;
|
||||
extern consvar_t cv_soundvolume, cv_closedcaptioning, cv_digmusicvolume;
|
||||
extern consvar_t cv_soundvolume, cv_closedcaptioning, cv_digmusicvolume;
|
||||
|
||||
extern consvar_t surround;
|
||||
extern consvar_t cv_numChannels;
|
||||
|
|
@ -246,6 +246,7 @@ INT32 S_GetSoundVolume(sfxinfo_t *sfx, INT32 volume);
|
|||
|
||||
void S_SetSfxVolume(void);
|
||||
void S_SetMusicVolume(void);
|
||||
void S_SetMasterVolume(void);
|
||||
|
||||
INT32 S_OriginPlaying(void *origin);
|
||||
INT32 S_IdPlaying(sfxenum_t id);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ using namespace srb2::io;
|
|||
// extern in i_sound.h
|
||||
UINT8 sound_started = false;
|
||||
|
||||
static unique_ptr<Mixer<2>> master;
|
||||
static unique_ptr<Gain<2>> master_gain;
|
||||
static shared_ptr<Mixer<2>> master;
|
||||
static shared_ptr<Mixer<2>> mixer_sound_effects;
|
||||
static shared_ptr<Mixer<2>> mixer_music;
|
||||
static shared_ptr<MusicPlayer> music_player;
|
||||
|
|
@ -144,10 +145,10 @@ void audio_callback(void* userdata, Uint8* buffer, int len)
|
|||
float_buffer[i] = Sample<2> {0.f, 0.f};
|
||||
}
|
||||
|
||||
if (!master)
|
||||
if (!master_gain)
|
||||
return;
|
||||
|
||||
master->generate(tcb::span {float_buffer, float_len});
|
||||
master_gain->generate(tcb::span {float_buffer, float_len});
|
||||
|
||||
for (size_t i = 0; i < float_len; i++)
|
||||
{
|
||||
|
|
@ -197,7 +198,9 @@ void initialize_sound()
|
|||
{
|
||||
SdlAudioLockHandle _;
|
||||
|
||||
master = make_unique<Mixer<2>>();
|
||||
master_gain = make_unique<Gain<2>>();
|
||||
master = make_shared<Mixer<2>>();
|
||||
master_gain->bind(master);
|
||||
mixer_sound_effects = make_shared<Mixer<2>>();
|
||||
mixer_music = make_shared<Mixer<2>>();
|
||||
music_player = make_shared<MusicPlayer>();
|
||||
|
|
@ -378,6 +381,17 @@ void I_SetSfxVolume(int volume)
|
|||
}
|
||||
}
|
||||
|
||||
void I_SetMasterVolume(int volume)
|
||||
{
|
||||
SdlAudioLockHandle _;
|
||||
float vol = static_cast<float>(volume) / 100.f;
|
||||
|
||||
if (master_gain)
|
||||
{
|
||||
master_gain->gain(std::clamp(vol * vol * vol, 0.f, 1.f));
|
||||
}
|
||||
}
|
||||
|
||||
/// ------------------------
|
||||
// MUSIC SYSTEM
|
||||
/// ------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue