aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2018-07-04 19:28:04 -0700
committerPaul Gilbert2018-07-04 19:28:04 -0700
commit3128e5294e3d7f2bbcd2e0528b8507b691b6064a (patch)
tree2ec9b96db6448d45cb7f1c99413f76cfd00b577a
parentbdd98756ca64fb92b789710a9e26fc8e56fe55a5 (diff)
downloadscummvm-rg350-3128e5294e3d7f2bbcd2e0528b8507b691b6064a.tar.gz
scummvm-rg350-3128e5294e3d7f2bbcd2e0528b8507b691b6064a.tar.bz2
scummvm-rg350-3128e5294e3d7f2bbcd2e0528b8507b691b6064a.zip
XEEN: Properly handle SFX & Music volume control
-rw-r--r--engines/xeen/sound_driver.h5
-rw-r--r--engines/xeen/sound_driver_adlib.cpp41
-rw-r--r--engines/xeen/sound_driver_adlib.h7
3 files changed, 37 insertions, 16 deletions
diff --git a/engines/xeen/sound_driver.h b/engines/xeen/sound_driver.h
index bad357b604..7c82866d0c 100644
--- a/engines/xeen/sound_driver.h
+++ b/engines/xeen/sound_driver.h
@@ -65,10 +65,11 @@ protected:
int _freqChange;
int _freqCtr;
byte _volume;
- byte _scalingValue;
+ byte _totalLevel;
+ bool _isFx;
uint _frequency;
Channel() : _changeFrequency(false), _freqCtr(0), _freqCtrChange(0),
- _freqChange(0), _volume(0), _scalingValue(0), _frequency(0) {}
+ _freqChange(0), _volume(0), _totalLevel(0), _frequency(0), _isFx(false) {}
};
private:
static const CommandFn FX_COMMANDS[16];
diff --git a/engines/xeen/sound_driver_adlib.cpp b/engines/xeen/sound_driver_adlib.cpp
index a1a13fae9a..4e74b2fc73 100644
--- a/engines/xeen/sound_driver_adlib.cpp
+++ b/engines/xeen/sound_driver_adlib.cpp
@@ -207,31 +207,37 @@ uint SoundDriverAdlib::calcFrequency(byte note) {
}
void SoundDriverAdlib::setOutputLevel(byte channelNum, uint level) {
- write(0x40 + OPERATOR2_INDEXES[channelNum], level |
- (_channels[channelNum]._scalingValue & 0xC0));
+ Channel &c = _channels[channelNum];
+ write(0x40 + OPERATOR2_INDEXES[channelNum], calculateLevel(level, c._isFx) | (c._totalLevel & 0xC0));
}
-void SoundDriverAdlib::playInstrument(byte channelNum, const byte *data, byte volume) {
+void SoundDriverAdlib::playInstrument(byte channelNum, const byte *data, bool isFx) {
byte op1 = OPERATOR1_INDEXES[channelNum];
byte op2 = OPERATOR2_INDEXES[channelNum];
+ int totalLevel;
+
debugC(2, kDebugSound, "---START-playInstrument - %d", channelNum);
+ _channels[channelNum]._isFx = isFx;
write(0x20 + op1, *data++);
- write(0x40 + op1, *data++);
+
+ totalLevel = *data++;
+ write(0x40 + op1, calculateLevel(totalLevel, isFx));
+
write(0x60 + op1, *data++);
write(0x80 + op1, *data++);
write(0xE0 + op1, *data++);
write(0x20 + op2, *data++);
- int scalingVal = *data++;
- _channels[channelNum]._scalingValue = scalingVal;
- scalingVal += (127 - volume) / 2;
+ totalLevel = *data++;
+ _channels[channelNum]._totalLevel = totalLevel;
- if (scalingVal > 63) {
- scalingVal = 63;
+ if (totalLevel > 63) {
+ totalLevel = 63;
if (_field180)
- scalingVal = (scalingVal & 0xC0) | _field182;
+ totalLevel = (totalLevel & 0xC0) | _field182;
}
- write(0x40 + op2, scalingVal);
+
+ write(0x40 + op2, calculateLevel(totalLevel, isFx));
write(0x60 + op2, *data++);
write(0x80 + op2, *data++);
@@ -318,7 +324,7 @@ bool SoundDriverAdlib::musPlayInstrument(const byte *&srcP, byte param) {
debugC(3, kDebugSound, "musPlayInstrument %d, %d", param, instrument);
if (param < 7)
- playInstrument(param, _musInstrumentPtrs[instrument], _musicVolume);
+ playInstrument(param, _musInstrumentPtrs[instrument], false);
return false;
}
@@ -416,9 +422,18 @@ bool SoundDriverAdlib::fxPlayInstrument(const byte *&srcP, byte param) {
debugC(3, kDebugSound, "fxPlayInstrument %d, %d", param, instrument);
if (!_exclude7 || param != 7)
- playInstrument(param, _fxInstrumentPtrs[instrument], _sfxVolume);
+ playInstrument(param, _fxInstrumentPtrs[instrument], true);
return false;
}
+byte SoundDriverAdlib::calculateLevel(byte level, bool isFx) {
+ uint volume = isFx ? _sfxVolume : _musicVolume;
+ uint scaling = level & 0xc0;
+ uint totalLevel = 0x3f - (level & 0x3f);
+ totalLevel = totalLevel * volume / 255;
+
+ return scaling | (0x3f - totalLevel);
+}
+
} // End of namespace Xeen
diff --git a/engines/xeen/sound_driver_adlib.h b/engines/xeen/sound_driver_adlib.h
index def25574f6..8604184df0 100644
--- a/engines/xeen/sound_driver_adlib.h
+++ b/engines/xeen/sound_driver_adlib.h
@@ -99,7 +99,12 @@ private:
/**
* Starts playing an instrument
*/
- void playInstrument(byte channelNum, const byte *data, byte volume);
+ void playInstrument(byte channelNum, const byte *data, bool isFx);
+
+ /**
+ * Calculates the scaling/volume level to output based on sfx or music master volume
+ */
+ byte calculateLevel(byte level, bool isFx);
protected:
virtual bool musSetInstrument(const byte *&srcP, byte param);
virtual bool musSetPitchWheel(const byte *&srcP, byte param);