Added code to prevent loud sounds from being overtaken by quiet sounds.

This prevents the weird effect where you hear a bunch of sounds of
majorly different volumes starting and stopping. If, for example, you
have several mines exploding nearby as well as several mines exploding
far away at the same time, you will hear the near ones and not the far
ones.
This commit is contained in:
onpon4 2016-01-11 00:10:55 -05:00
parent 0929abf3a3
commit c764c4d8b7
1 changed files with 12 additions and 2 deletions

View File

@ -46,6 +46,7 @@ void audio_playSound(int sid, float x, float y)
{ {
int channel = -1; int channel = -1;
static int freechannel = 4; static int freechannel = 4;
static int channelVolume[4] = {0, 0, 0, 0};
int angle = atanf((x - (screen->w / 2)) / (screen->w / 2)) * 180 / M_PI; int angle = atanf((x - (screen->w / 2)) / (screen->w / 2)) * 180 / M_PI;
int attenuation = fabsf(x - (screen->w / 2)) / (screen->w / 20); int attenuation = fabsf(x - (screen->w / 2)) / (screen->w / 20);
float distance = sqrtf(powf(fabsf(x - (screen->w / 2)), 2) + powf(fabsf(y - (screen->h / 2)), 2)); float distance = sqrtf(powf(fabsf(x - (screen->w / 2)), 2) + powf(fabsf(y - (screen->h / 2)), 2));
@ -84,11 +85,20 @@ void audio_playSound(int sid, float x, float y)
break; break;
} }
if(channel == -1) { if (channel == -1)
{
channel = freechannel++; channel = freechannel++;
if(freechannel >= 8) if (freechannel >= 8)
freechannel = 4; freechannel = 4;
} }
else
{
if (Mix_Playing(channel) && (volume <= MIX_MAX_VOLUME / 4) &&
(channelVolume[channel] >= MIX_MAX_VOLUME * 3 / 4))
return;
else
channelVolume[channel] = volume;
}
angle %= 360; angle %= 360;
if (angle < 0) if (angle < 0)