aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm
diff options
context:
space:
mode:
authorTobias Gunkel2011-12-20 13:18:27 +0100
committerTobias Gunkel2011-12-22 12:08:28 +0100
commit3a9f2c5f5bb817b4acbe279aedae938679634257 (patch)
treea510d3c1afa2a613e65fcd96d65698f4347c3903 /engines/scumm
parent7d551c9e6e8c5a46086f9da5e601561c434bafe0 (diff)
downloadscummvm-rg350-3a9f2c5f5bb817b4acbe279aedae938679634257.tar.gz
scummvm-rg350-3a9f2c5f5bb817b4acbe279aedae938679634257.tar.bz2
scummvm-rg350-3a9f2c5f5bb817b4acbe279aedae938679634257.zip
SCUMM: Use finer grained sound updates for player_appleII
This reduces the needed buffer size for the biggest type4 sound from 170kB to only 2 bytes
Diffstat (limited to 'engines/scumm')
-rw-r--r--engines/scumm/player_appleII.cpp99
-rw-r--r--engines/scumm/player_appleII.h1
2 files changed, 59 insertions, 41 deletions
diff --git a/engines/scumm/player_appleII.cpp b/engines/scumm/player_appleII.cpp
index a027b522b5..b566012d73 100644
--- a/engines/scumm/player_appleII.cpp
+++ b/engines/scumm/player_appleII.cpp
@@ -183,73 +183,90 @@ public:
_params = params;
_updateRemain1 = 80;
_updateRemain2 = 10;
+ _count = 0;
}
virtual bool update() { // D170
// while (_state.params[0] != 0x01)
if (_params[0] != 0x01) {
- _update(_params[0], _params[1], _params[2]);
- _params += 3;
+ if (_count == 0) // prepare next loop
+ nextLoop(_params[0], _params[1], _params[2]);
+ if (loopIteration()) // loop finished -> fetch next parameter set
+ _params += 3;
return false;
}
return true;
}
private:
- void _update(byte param0, byte param1, byte param2) { // D1A2
- uint16 count = (-param2 << 8) | 0x3;
- byte bitmask1 = 0x3;
- byte bitmask2 = 0x3;
+ /*
+ * prepare for next parameter set loop
+ */
+ void nextLoop(byte param0, byte param1, byte param2) { // LD182
+ _count = (-param2 << 8) | 0x3;
+
+ _bitmask1 = 0x3;
+ _bitmask2 = 0x3;
- byte updateInterval2 = param0;
- if (updateInterval2 == 0)
- bitmask2 = 0x0;
-
- byte updateInterval1 = param1;
- if (updateInterval1 == 0) {
- bitmask1 = 0x0;
- if (bitmask2 != 0) {
- bitmask1 = bitmask2;
- bitmask2 = 0;
- updateInterval1 = updateInterval2;
+ _updateInterval2 = param0;
+ if (_updateInterval2 == 0)
+ _bitmask2 = 0x0;
+
+ _updateInterval1 = param1;
+ if (_updateInterval1 == 0) {
+ _bitmask1 = 0x0;
+ if (_bitmask2 != 0) {
+ _bitmask1 = _bitmask2;
+ _bitmask2 = 0;
+ _updateInterval1 = _updateInterval2;
}
}
- byte speakerShiftReg = 0;
-
- while (true) {
- --_updateRemain1;
- --_updateRemain2;
+ _speakerShiftReg = 0;
+ }
- if (_updateRemain2 == 0) {
- _updateRemain2 = updateInterval2;
- // use only first voice's data (bitmask1) if both voices are triggered
- if (_updateRemain1 != 0) {
- speakerShiftReg ^= bitmask2;
- }
+ /*
+ * perform one loop iteration
+ * Returns true if loop finished
+ */
+ bool loopIteration() { // D1A2
+ --_updateRemain1;
+ --_updateRemain2;
+
+ if (_updateRemain2 == 0) {
+ _updateRemain2 = _updateInterval2;
+ // use only first voice's data (bitmask1) if both voices are triggered
+ if (_updateRemain1 != 0) {
+ _speakerShiftReg ^= _bitmask2;
}
+ }
- if (_updateRemain1 == 0) {
- _updateRemain1 = updateInterval1;
- speakerShiftReg ^= bitmask1;
- }
+ if (_updateRemain1 == 0) {
+ _updateRemain1 = _updateInterval1;
+ _speakerShiftReg ^= _bitmask1;
+ }
- if (speakerShiftReg & 0x1)
- _player->speakerToggle();
- speakerShiftReg >>= 1;
- _player->generateSamples(42); /* actually 42.5 */
+ if (_speakerShiftReg & 0x1)
+ _player->speakerToggle();
+ _speakerShiftReg >>= 1;
+ _player->generateSamples(42); /* actually 42.5 */
- ++count;
- if (count == 0) {
- return;
- }
- }
+ ++_count;
+ return (_count == 0);
}
protected:
const byte *_params;
+
byte _updateRemain1;
byte _updateRemain2;
+
+ uint16 _count;
+ byte _bitmask1;
+ byte _bitmask2;
+ byte _updateInterval1;
+ byte _updateInterval2;
+ byte _speakerShiftReg;
};
/*
diff --git a/engines/scumm/player_appleII.h b/engines/scumm/player_appleII.h
index 91c7935f76..f0b148ef86 100644
--- a/engines/scumm/player_appleII.h
+++ b/engines/scumm/player_appleII.h
@@ -282,6 +282,7 @@ public:
AppleII_SoundFunction() {}
virtual ~AppleII_SoundFunction() {}
virtual void init(Player_AppleII *player, const byte *params) = 0;
+ /* returns true if finished */
virtual bool update() = 0;
protected:
Player_AppleII *_player;