From cf78d76bdfceb74c1682f5f792c4a0c4b14dc0c6 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Sat, 17 Oct 2015 11:46:40 -0600 Subject: [PATCH] make disable volume on focus lost not reset title music --- src/audio/audio.h | 1 - src/audio/mixer.cpp | 14 +++++++++++++- src/audio/mixer.h | 3 +++ src/platform/shared.c | 5 +++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/audio/audio.h b/src/audio/audio.h index 880f2b4853..d22a26442a 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -105,7 +105,6 @@ void start_title_music(); void stop_ride_music(); void stop_crowd_sound(); void stop_title_music(); -void stop_raid_sound(); void audio_init1(); void audio_init2(int device); void audio_close(); diff --git a/src/audio/mixer.cpp b/src/audio/mixer.cpp index 210d90407d..75685e5209 100644 --- a/src/audio/mixer.cpp +++ b/src/audio/mixer.cpp @@ -448,6 +448,7 @@ void Channel::SetGroup(int group) Mixer::Mixer() { effectbuffer = 0; + volume = 1; for (int i = 0; i < countof(css1sources); i++) { css1sources[i] = 0; } @@ -565,6 +566,11 @@ bool Mixer::LoadMusic(int pathid) } } +void Mixer::SetVolume(float volume) +{ + Mixer::volume = volume; +} + void SDLCALL Mixer::Callback(void* arg, uint8* stream, int length) { Mixer* mixer = (Mixer*)arg; @@ -671,7 +677,8 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length) mixlength = length - loaded; } - float volumeadjust = (gConfigSound.master_volume / 100.0f); + float volumeadjust = volume; + volumeadjust *= (gConfigSound.master_volume / 100.0f); if (channel.group == MIXER_GROUP_MUSIC) { volumeadjust *= (gConfigSound.music_volume / 100.0f); } @@ -897,3 +904,8 @@ void* Mixer_Play_Music(int pathid, int loop, int streaming) } return 0; } + +void Mixer_SetVolume(float volume) +{ + gMixer.SetVolume(volume); +} diff --git a/src/audio/mixer.h b/src/audio/mixer.h index 6f68e1177d..35fa5b92e1 100644 --- a/src/audio/mixer.h +++ b/src/audio/mixer.h @@ -167,6 +167,7 @@ public: Channel* Play(Source& source, int loop, bool deleteondone, bool deletesourceondone); void Stop(Channel& channel); bool LoadMusic(int pathid); + void SetVolume(float volume); Source* css1sources[SOUND_MAXID]; Source* musicsources[PATH_ID_END]; @@ -185,6 +186,7 @@ private: uint8* effectbuffer; std::list channels; Source_Null source_null; + float volume; }; extern "C" @@ -209,6 +211,7 @@ unsigned long Mixer_Channel_GetOffset(void* channel); int Mixer_Channel_SetOffset(void* channel, unsigned long offset); void Mixer_Channel_SetGroup(void* channel, int group); void* Mixer_Play_Music(int pathid, int loop, int streaming); +void Mixer_SetVolume(float volume); static int DStoMixerVolume(int volume) { return (int)(SDL_MIX_MAXVOLUME * (SDL_pow(10, (float)volume / 2000))); }; static float DStoMixerPan(int pan) { return (((float)pan + -DSBPAN_LEFT) / DSBPAN_RIGHT) / 2; }; diff --git a/src/platform/shared.c b/src/platform/shared.c index cdf9ecf854..de47d4caf6 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -20,6 +20,7 @@ #include "../addresses.h" #include "../audio/audio.h" +#include "../audio/mixer.h" #include "../config.h" #include "../cursors.h" #include "../drawing/drawing.h" @@ -406,10 +407,10 @@ void platform_process_messages() platform_resize(e.window.data1, e.window.data2); if (gConfigSound.audio_focus && gConfigSound.sound) { if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { - unpause_sounds(); + Mixer_SetVolume(1); } if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { - pause_sounds(); + Mixer_SetVolume(0); } } break;