1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 12:03:07 +01:00

Merge pull request #2077 from zsilencer/bugfixes

fix #2076
This commit is contained in:
Ted John
2015-10-17 19:18:55 +01:00
6 changed files with 45 additions and 18 deletions

View File

@@ -41,6 +41,7 @@ rct_ride_music_params gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
rct_ride_music_params *gRideMusicParamsListEnd;
void *gCrowdSoundChannel = 0;
void *gTitleMusicChannel = 0;
void *gRainSoundChannel = 0;
bool gGameSoundsOff = false;
void audio_init(int i)
@@ -232,6 +233,14 @@ void stop_title_music()
}
}
void stop_rain_sound()
{
if (gRainSoundChannel) {
Mixer_Stop_Channel(gRainSoundChannel);
gRainSoundChannel = 0;
}
}
/**
*
* rct2: 0x006BA8E0
@@ -285,6 +294,7 @@ void audio_close()
stop_crowd_sound();
stop_title_music();
stop_ride_music();
stop_rain_sound();
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = -1;
}
@@ -309,6 +319,7 @@ void pause_sounds()
stop_vehicle_sounds();
stop_ride_music();
stop_crowd_sound();
stop_rain_sound();
}
/**

View File

@@ -97,6 +97,7 @@ extern rct_ride_music_params gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
extern rct_ride_music_params *gRideMusicParamsListEnd;
extern void *gCrowdSoundChannel;
extern void *gTitleMusicChannel;
extern void *gRainSoundChannel;
extern bool gGameSoundsOff;
int sound_play_panned(int sound_id, int ebx, sint16 x, sint16 y, sint16 z);

View File

@@ -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);
}

View File

@@ -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<Channel*> 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; };

View File

@@ -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;

View File

@@ -62,7 +62,6 @@ static const rct_weather_transition* climate_transitions[4];
// Sound data
static int _rainVolume = 1;
static void* _rainSoundChannel = 0;
static unsigned int _lightningTimer, _thunderTimer;
static void* _thunderSoundChannels[MAX_THUNDER_INSTANCES];
static int _thunderStatus[MAX_THUNDER_INSTANCES] = { THUNDER_STATUS_NULL, THUNDER_STATUS_NULL };
@@ -108,9 +107,9 @@ void climate_reset(int climate)
_lightningTimer = 0;
_thunderTimer = 0;
if (_rainVolume != 1){
if (_rainSoundChannel) {
Mixer_Stop_Channel(_rainSoundChannel);
_rainSoundChannel = 0;
if (gRainSoundChannel) {
Mixer_Stop_Channel(gRainSoundChannel);
gRainSoundChannel = 0;
}
_rainVolume = 1;
}
@@ -251,30 +250,30 @@ void climate_update_sound()
static void climate_update_rain_sound()
{
if (_climateCurrentWeatherEffect == 1 || _climateCurrentWeatherEffect == 2) {
// Start playing the rain sound
if (!gRainSoundChannel) {
gRainSoundChannel = Mixer_Play_Effect(SOUND_RAIN_1, MIXER_LOOP_INFINITE, DStoMixerVolume(-4000), 0.5f, 1, 0);
}
if (_rainVolume == 1) {
// Start playing the rain sound
if (!_rainSoundChannel) {
_rainSoundChannel = Mixer_Play_Effect(SOUND_RAIN_1, MIXER_LOOP_INFINITE, DStoMixerVolume(-4000), 0.5f, 1, 0);
}
_rainVolume = -4000;
} else {
// Increase rain sound
_rainVolume = min(-1400, _rainVolume + 80);
if (_rainSoundChannel) {
Mixer_Channel_Volume(_rainSoundChannel, DStoMixerVolume(_rainVolume));
if (gRainSoundChannel) {
Mixer_Channel_Volume(gRainSoundChannel, DStoMixerVolume(_rainVolume));
}
}
} else if (_rainVolume != 1) {
// Decrease rain sound
_rainVolume -= 80;
if (_rainVolume > -4000) {
if (_rainSoundChannel) {
Mixer_Channel_Volume(_rainSoundChannel, DStoMixerVolume(_rainVolume));
if (gRainSoundChannel) {
Mixer_Channel_Volume(gRainSoundChannel, DStoMixerVolume(_rainVolume));
}
} else {
if (_rainSoundChannel) {
Mixer_Stop_Channel(_rainSoundChannel);
_rainSoundChannel = 0;
if (gRainSoundChannel) {
Mixer_Stop_Channel(gRainSoundChannel);
gRainSoundChannel = 0;
}
_rainVolume = 1;
}