[Scummvm-git-logs] scummvm master -> 49116b4ae7dd31fd736a33913a2969c0653a06cb

bonki bonki at users.noreply.github.com
Sat May 5 17:57:35 CEST 2018


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
49116b4ae7 ALL: Use CLIP to clip volumes


Commit: 49116b4ae7dd31fd736a33913a2969c0653a06cb
    https://github.com/scummvm/scummvm/commit/49116b4ae7dd31fd736a33913a2969c0653a06cb
Author: Adrian Frühwirth (bonki at users.noreply.github.com)
Date: 2018-05-05T17:57:31+02:00

Commit Message:
ALL: Use CLIP to clip volumes

Changed paths:
    audio/mixer.cpp
    engines/agos/midi.cpp
    engines/cine/sound.cpp
    engines/cruise/sound.cpp
    engines/kyra/sound_digital.cpp
    engines/lure/sound.cpp
    engines/queen/music.cpp
    engines/scumm/players/player_nes.cpp
    engines/tony/sound.cpp


diff --git a/audio/mixer.cpp b/audio/mixer.cpp
index 16cf564..274f8e9 100644
--- a/audio/mixer.cpp
+++ b/audio/mixer.cpp
@@ -471,10 +471,7 @@ void MixerImpl::setVolumeForSoundType(SoundType type, int volume) {
 	assert(0 <= (int)type && (int)type < ARRAYSIZE(_soundTypeSettings));
 
 	// Check range
-	if (volume > kMaxMixerVolume)
-		volume = kMaxMixerVolume;
-	else if (volume < 0)
-		volume = 0;
+	volume = CLIP<int>(volume, 0, kMaxMixerVolume);
 
 	// TODO: Maybe we should do logarithmic (not linear) volume
 	// scaling? See also Player_V2::setMasterVolume
diff --git a/engines/agos/midi.cpp b/engines/agos/midi.cpp
index 3a7158a..5e28654 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 a8b4c08..70ce8fe 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 57dcfce..8d6ca57 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 a1600f6..551d79c 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 25d68c7..5acd6d8 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 9f74aab..c65f2de 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 3b5adc4..b2f6eb0 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 fed51da..07d15e7 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;
 





More information about the Scummvm-git-logs mailing list