mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-25 05:34:27 +00:00
ALL: Use CLIP to clip volumes
This commit is contained in:
parent
c4edac23b2
commit
49116b4ae7
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user