From 47e6f1d139bb31c49148d9ca0ada43fb5f5d1b32 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 10 Jun 2017 16:39:12 +0100 Subject: [PATCH] Rename our version of SDL_MIX_MAXVOLUME to MIXER_VOLUME_MAX Keep an assert to make sure its the same as SDL in the mixer. If SDL changes it, we can either change ours or convert the number proportionally. --- src/openrct2-ui/audio/AudioChannel.cpp | 4 ++-- src/openrct2-ui/audio/AudioMixer.cpp | 6 +++++- src/openrct2/audio/AudioMixer.cpp | 2 +- src/openrct2/audio/AudioMixer.h | 3 +-- src/openrct2/interface/chat.c | 2 +- src/openrct2/intro.c | 6 +++--- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/openrct2-ui/audio/AudioChannel.cpp b/src/openrct2-ui/audio/AudioChannel.cpp index b11aae2845..50a63cdb65 100644 --- a/src/openrct2-ui/audio/AudioChannel.cpp +++ b/src/openrct2-ui/audio/AudioChannel.cpp @@ -54,7 +54,7 @@ namespace OpenRCT2 { namespace Audio AudioChannelImpl() { SetRate(1); - SetVolume(SDL_MIX_MAXVOLUME); + SetVolume(MIXER_VOLUME_MAX); SetPan(0.5f); } @@ -165,7 +165,7 @@ namespace OpenRCT2 { namespace Audio void SetVolume(sint32 volume) override { - _volume = Math::Clamp(0, volume, SDL_MIX_MAXVOLUME); + _volume = Math::Clamp(0, volume, MIXER_VOLUME_MAX); } float GetPan() const override diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index 41a773e5f1..88abe8293f 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -444,7 +444,7 @@ namespace OpenRCT2 { namespace Audio if (startVolume != endVolume) { // Set to max since we are adjusting the volume ourselves - mixVolume = SDL_MIX_MAXVOLUME; + mixVolume = MIXER_VOLUME_MAX; // Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes sint32 fadeLength = (sint32)len / _format.BytesPerSample(); @@ -494,6 +494,8 @@ namespace OpenRCT2 { namespace Audio static void EffectFadeS16(sint16 * data, sint32 length, sint32 startvolume, sint32 endvolume) { + static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2"); + float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME; float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME; for (sint32 i = 0; i < length; i++) @@ -505,6 +507,8 @@ namespace OpenRCT2 { namespace Audio static void EffectFadeU8(uint8* data, sint32 length, sint32 startvolume, sint32 endvolume) { + static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2"); + float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME; float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME; for (sint32 i = 0; i < length; i++) diff --git a/src/openrct2/audio/AudioMixer.cpp b/src/openrct2/audio/AudioMixer.cpp index e71eb64780..4883a677d3 100644 --- a/src/openrct2/audio/AudioMixer.cpp +++ b/src/openrct2/audio/AudioMixer.cpp @@ -167,7 +167,7 @@ void Mixer_SetVolume(float volume) sint32 DStoMixerVolume(sint32 volume) { - return (sint32)(SDL_MIX_MAXVOLUME * (std::pow(10.0f, (float)volume / 2000))); + return (sint32)(MIXER_VOLUME_MAX * (std::pow(10.0f, (float)volume / 2000))); } float DStoMixerPan(sint32 pan) diff --git a/src/openrct2/audio/AudioMixer.h b/src/openrct2/audio/AudioMixer.h index 233e78533f..7a280ac091 100644 --- a/src/openrct2/audio/AudioMixer.h +++ b/src/openrct2/audio/AudioMixer.h @@ -18,8 +18,7 @@ #include "../common.h" -#define SDL_MIX_MAXVOLUME 128 - +#define MIXER_VOLUME_MAX 128 #define MIXER_LOOP_NONE 0 #define MIXER_LOOP_INFINITE -1 diff --git a/src/openrct2/interface/chat.c b/src/openrct2/interface/chat.c index f98906e165..3ea756e6f0 100644 --- a/src/openrct2/interface/chat.c +++ b/src/openrct2/interface/chat.c @@ -212,7 +212,7 @@ void chat_history_add(const char * src) free(buffer); - Mixer_Play_Effect(SOUND_NEWS_ITEM, 0, SDL_MIX_MAXVOLUME, 0, 1.5f, true); + Mixer_Play_Effect(SOUND_NEWS_ITEM, 0, MIXER_VOLUME_MAX, 0, 1.5f, true); } void chat_input(CHAT_INPUT input) diff --git a/src/openrct2/intro.c b/src/openrct2/intro.c index 0106ba8656..350a4e9f3c 100644 --- a/src/openrct2/intro.c +++ b/src/openrct2/intro.c @@ -60,7 +60,7 @@ void intro_update() _introStateCounter = -580; // Play the chain lift sound - _soundChannel = Mixer_Play_Effect(SOUND_LIFT_7, MIXER_LOOP_INFINITE, SDL_MIX_MAXVOLUME, 0.5f, 1, true); + _soundChannel = Mixer_Play_Effect(SOUND_LIFT_7, MIXER_LOOP_INFINITE, MIXER_VOLUME_MAX, 0.5f, 1, true); _chainLiftFinished = false; gIntroState++; break; @@ -95,7 +95,7 @@ void intro_update() } // Play the track friction sound - _soundChannel = Mixer_Play_Effect(SOUND_TRACK_FRICTION_3, MIXER_LOOP_INFINITE, SDL_MIX_MAXVOLUME, 0.25f, 0.75, true); + _soundChannel = Mixer_Play_Effect(SOUND_TRACK_FRICTION_3, MIXER_LOOP_INFINITE, MIXER_VOLUME_MAX, 0.25f, 0.75, true); } // Check if logo is off the screen...ish @@ -107,7 +107,7 @@ void intro_update() } // Play long peep scream sound - _soundChannel = Mixer_Play_Effect(SOUND_SCREAM_1, MIXER_LOOP_NONE, SDL_MIX_MAXVOLUME, 0.5f, 1, false); + _soundChannel = Mixer_Play_Effect(SOUND_SCREAM_1, MIXER_LOOP_NONE, MIXER_VOLUME_MAX, 0.5f, 1, false); gIntroState++; _introStateCounter = 0;