aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorAdrian Frühwirth2018-05-03 21:54:58 +0200
committerAdrian Frühwirth2018-05-05 17:57:31 +0200
commit49116b4ae7dd31fd736a33913a2969c0653a06cb (patch)
tree5bce268f0d8227d5a4767da23cb321aedc554063 /engines
parentc4edac23b2bd8c4024785e8701b61fe1fad13724 (diff)
downloadscummvm-rg350-49116b4ae7dd31fd736a33913a2969c0653a06cb.tar.gz
scummvm-rg350-49116b4ae7dd31fd736a33913a2969c0653a06cb.tar.bz2
scummvm-rg350-49116b4ae7dd31fd736a33913a2969c0653a06cb.zip
ALL: Use CLIP to clip volumes
Diffstat (limited to 'engines')
-rw-r--r--engines/agos/midi.cpp12
-rw-r--r--engines/cine/sound.cpp6
-rw-r--r--engines/cruise/sound.cpp6
-rw-r--r--engines/kyra/sound_digital.cpp8
-rw-r--r--engines/lure/sound.cpp5
-rw-r--r--engines/queen/music.cpp5
-rw-r--r--engines/scumm/players/player_nes.cpp6
-rw-r--r--engines/tony/sound.cpp6
8 files changed, 12 insertions, 42 deletions
diff --git a/engines/agos/midi.cpp b/engines/agos/midi.cpp
index 3a7158a203..5e28654c41 100644
--- a/engines/agos/midi.cpp
+++ b/engines/agos/midi.cpp
@@ -482,20 +482,14 @@ void MidiPlayer::pause(bool b) {
}
void MidiPlayer::setVolume(int musicVol, int sfxVol) {
- if (musicVol < 0)
- musicVol = 0;
- else if (musicVol > 255)
- musicVol = 255;
- if (sfxVol < 0)
- sfxVol = 0;
- else if (sfxVol > 255)
- sfxVol = 255;
+ musicVol = CLIP(musicVol, 0, 255);
+ sfxVol = CLIP(sfxVol, 0, 255);
if (_musicVolume == musicVol && _sfxVolume == sfxVol)
return;
_musicVolume = musicVol;
- _sfxVolume = sfxVol;
+ _sfxVolume = sfxVol;
// Now tell all the channels this.
Common::StackLock lock(_mutex);
diff --git a/engines/cine/sound.cpp b/engines/cine/sound.cpp
index a8b4c085ff..70ce8fec98 100644
--- a/engines/cine/sound.cpp
+++ b/engines/cine/sound.cpp
@@ -299,11 +299,7 @@ void AdLibSoundDriver::setUpdateCallback(UpdateCallback upCb, void *ref) {
void AdLibSoundDriver::setupChannel(int channel, const byte *data, int instrument, int volume) {
assert(channel < 4);
if (data) {
- if (volume > 80) {
- volume = 80;
- } else if (volume < 0) {
- volume = 0;
- }
+ volume = CLIP(volume, 0, 80);
volume += volume / 4;
_channelsVolumeTable[channel] = volume;
diff --git a/engines/cruise/sound.cpp b/engines/cruise/sound.cpp
index 57dcfcea8f..8d6ca571d1 100644
--- a/engines/cruise/sound.cpp
+++ b/engines/cruise/sound.cpp
@@ -334,11 +334,7 @@ void AdLibSoundDriver::syncSounds() {
void AdLibSoundDriver::adjustVolume(int channel, int volume) {
_channelsVolumeTable[channel].original = volume;
- if (volume > 80) {
- volume = 80;
- } else if (volume < 0) {
- volume = 0;
- }
+ volume = CLIP(volume, 0, 80);
volume += volume / 4;
// The higher possible value for volume is 100
diff --git a/engines/kyra/sound_digital.cpp b/engines/kyra/sound_digital.cpp
index a1600f6464..551d79cc55 100644
--- a/engines/kyra/sound_digital.cpp
+++ b/engines/kyra/sound_digital.cpp
@@ -30,6 +30,8 @@
#include "audio/decoders/vorbis.h"
#include "audio/decoders/flac.h"
+#include "common/util.h"
+
namespace Kyra {
class KyraAudioStream : public Audio::SeekableAudioStream {
@@ -203,11 +205,7 @@ int AUDStream::readBuffer(int16 *buffer, const int numSamples) {
}
inline int16 clip8BitSample(int16 sample) {
- if (sample > 255)
- return 255;
- if (sample < 0)
- return 0;
- return sample;
+ return CLIP<int16>(sample, 0, 255);
}
int AUDStream::readChunk(int16 *buffer, const int maxSamples) {
diff --git a/engines/lure/sound.cpp b/engines/lure/sound.cpp
index 25d68c762d..5acd6d81a0 100644
--- a/engines/lure/sound.cpp
+++ b/engines/lure/sound.cpp
@@ -649,10 +649,7 @@ MidiMusic::~MidiMusic() {
}
void MidiMusic::setVolume(int volume) {
- if (volume < 0)
- volume = 0;
- else if (volume > 255)
- volume = 255;
+ volume = CLIP(volume, 0, 255);
if (_volume == volume)
return;
diff --git a/engines/queen/music.cpp b/engines/queen/music.cpp
index 9f74aab915..c65f2de5ef 100644
--- a/engines/queen/music.cpp
+++ b/engines/queen/music.cpp
@@ -102,10 +102,7 @@ MidiMusic::~MidiMusic() {
}
void MidiMusic::setVolume(int volume) {
- if (volume < 0)
- volume = 0;
- else if (volume > 255)
- volume = 255;
+ volume = CLIP(volume, 0, 255);
if (_masterVolume == volume)
return;
diff --git a/engines/scumm/players/player_nes.cpp b/engines/scumm/players/player_nes.cpp
index 3b5adc4550..b2f6eb0d40 100644
--- a/engines/scumm/players/player_nes.cpp
+++ b/engines/scumm/players/player_nes.cpp
@@ -1029,11 +1029,7 @@ top:
}
_mchan[x].volume += _mchan[x].voldelta;
-
- if (_mchan[x].volume < 0)
- _mchan[x].volume = 0;
- if (_mchan[x].volume > MAXVOLUME)
- _mchan[x].volume = MAXVOLUME;
+ _mchan[x].volume = CLIP(_mchan[x].volume, 0, MAXVOLUME);
APU_writeChannel(x, 0, (_mchan[x].volume >> 3) | _mchan[x].envflags);
}
diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp
index fed51dacf4..07d15e71c9 100644
--- a/engines/tony/sound.cpp
+++ b/engines/tony/sound.cpp
@@ -412,11 +412,7 @@ void FPSfx::setPause(bool pause) {
*
*/
void FPSfx::setVolume(int volume) {
- if (volume > 63)
- volume = 63;
-
- if (volume < 0)
- volume = 0;
+ volume = CLIP(volume, 0, 63);
_lastVolume = volume;