From c764c4d8b7cd66ae98e593629c603ea715c457ef Mon Sep 17 00:00:00 2001 From: onpon4 Date: Mon, 11 Jan 2016 00:10:55 -0500 Subject: [PATCH] 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. --- src/audio.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 6be9e0e..cfc4d15 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -46,6 +46,7 @@ void audio_playSound(int sid, float x, float y) { int channel = -1; 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 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)); @@ -84,11 +85,20 @@ void audio_playSound(int sid, float x, float y) break; } - if(channel == -1) { + if (channel == -1) + { channel = freechannel++; - if(freechannel >= 8) + if (freechannel >= 8) 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; if (angle < 0)