aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm
diff options
context:
space:
mode:
authorTobias Gunkel2011-12-20 12:07:50 +0100
committerTobias Gunkel2011-12-22 12:08:27 +0100
commit7d551c9e6e8c5a46086f9da5e601561c434bafe0 (patch)
tree83d6ce0358770f10e0f514c101b88cf595cf32d6 /engines/scumm
parentffc88c5ceda344d5d5166ecbd712c6714e7af738 (diff)
downloadscummvm-rg350-7d551c9e6e8c5a46086f9da5e601561c434bafe0.tar.gz
scummvm-rg350-7d551c9e6e8c5a46086f9da5e601561c434bafe0.tar.bz2
scummvm-rg350-7d551c9e6e8c5a46086f9da5e601561c434bafe0.zip
SCUMM: Wrap player_appleII sound generation functions in classes
Diffstat (limited to 'engines/scumm')
-rw-r--r--engines/scumm/player_appleII.cpp623
-rw-r--r--engines/scumm/player_appleII.h52
2 files changed, 364 insertions, 311 deletions
diff --git a/engines/scumm/player_appleII.cpp b/engines/scumm/player_appleII.cpp
index a4111c5109..a027b522b5 100644
--- a/engines/scumm/player_appleII.cpp
+++ b/engines/scumm/player_appleII.cpp
@@ -27,10 +27,322 @@
namespace Scumm {
+/************************************
+ * Apple-II sound-resource parsers
+ ************************************/
+
+/*
+ * SoundFunction1: frequency up/down
+ */
+class AppleII_SoundFunction1_FreqUpDown : public AppleII_SoundFunction {
+public:
+ virtual void init(Player_AppleII *player, const byte *params) {
+ _player = player;
+ _delta = params[0];
+ _count = params[1];
+ _interval = params[2];
+ _limit = params[3];
+ _decInterval = (params[4] >= 0x40);
+ }
+
+ virtual bool update() { // D085
+ if (_decInterval) {
+ do {
+ _update(_interval, _count);
+ _interval -= _delta;
+ } while (_interval >= _limit);
+ } else {
+ do {
+ _update(_interval, _count);
+ _interval += _delta;
+ } while (_interval < _limit);
+ }
+ return true;
+ }
+
+private:
+ void _update(int interval /*a*/, int count /*y*/) { // D076
+ assert(interval > 0); // 0 == 256?
+ assert(count > 0); // 0 == 256?
+
+ for (; count >= 0; --count) {
+ _player->speakerToggle();
+ _player->generateSamples(17 + 5 * interval);
+ }
+ }
+
+protected:
+ int _delta;
+ int _count;
+ byte _interval; // must be unsigned byte ("interval < delta" possible)
+ int _limit;
+ bool _decInterval;
+};
+
+/*
+ * SoundFunction2: symmetric wave (~)
+ */
+class AppleII_SoundFunction2_SymmetricWave : public AppleII_SoundFunction {
+public:
+ virtual void init(Player_AppleII *player, const byte *params) {
+ _player = player;
+ _params = params;
+ _pos = 1;
+ }
+
+ virtual bool update() { // D0D6
+ // while (pos = 1; pos < 256; ++pos)
+ if (_pos < 256) {
+ byte interval = _params[_pos];
+ if (interval == 0xFF)
+ return true;
+ _update(interval, _params[0] /*, LD12F=interval*/);
+
+ ++_pos;
+ return false;
+ }
+ return true;
+ }
+
+private:
+ void _update(int interval /*a*/, int count) { // D0EF
+ if (interval == 0xFE) {
+ _player->wait(interval, 10);
+ } else {
+ assert(count > 0); // 0 == 256?
+ assert(interval > 0); // 0 == 256?
+
+ int a = (interval >> 3) + count;
+ for (int y = a; y > 0; --y) {
+ _player->generateSamples(1292 - 5*interval);
+ _player->speakerToggle();
+
+ _player->generateSamples(1287 - 5*interval);
+ _player->speakerToggle();
+ }
+ }
+ }
+
+protected:
+ const byte *_params;
+ int _pos;
+};
+
+/*
+ * SoundFunction3: asymmetric wave (__-)
+ */
+class AppleII_SoundFunction3_AsymmetricWave : public AppleII_SoundFunction {
+public:
+ virtual void init(Player_AppleII *player, const byte *params) {
+ _player = player;
+ _params = params;
+ _pos = 1;
+ }
+
+ virtual bool update() { // D132
+ // while (pos = 1; pos < 256; ++pos)
+ if (_pos < 256) {
+ byte interval = _params[_pos];
+ if (interval == 0xFF)
+ return true;
+ _update(interval, _params[0]);
+
+ ++_pos;
+ return false;
+ }
+ return true;
+ }
+
+private:
+ void _update(int interval /*a*/, int count /*LD12D*/) { // D14B
+ if (interval == 0xFE) {
+ _player->wait(interval, 70);
+ } else {
+ assert(interval > 0); // 0 == 256?
+ assert(count > 0); // 0 == 256?
+
+ for (int y = count; y > 0; --y) {
+ _player->generateSamples(1289 - 5*interval);
+ _player->speakerToggle();
+ }
+ }
+ }
+
+protected:
+ const byte *_params;
+ int _pos;
+};
+
+/*
+ * SoundFunction4: polyphone (2 voices)
+ */
+class AppleII_SoundFunction4_Polyphone : public AppleII_SoundFunction {
+public:
+ virtual void init(Player_AppleII *player, const byte *params) {
+ _player = player;
+ _params = params;
+ _updateRemain1 = 80;
+ _updateRemain2 = 10;
+ }
+
+ virtual bool update() { // D170
+ // while (_state.params[0] != 0x01)
+ if (_params[0] != 0x01) {
+ _update(_params[0], _params[1], _params[2]);
+ _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;
+
+ 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;
+ }
+ }
+
+ byte speakerShiftReg = 0;
+
+ while (true) {
+ --_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 (speakerShiftReg & 0x1)
+ _player->speakerToggle();
+ speakerShiftReg >>= 1;
+ _player->generateSamples(42); /* actually 42.5 */
+
+ ++count;
+ if (count == 0) {
+ return;
+ }
+ }
+ }
+
+protected:
+ const byte *_params;
+ byte _updateRemain1;
+ byte _updateRemain2;
+};
+
+/*
+ * SoundFunction5: periodic noise
+ */
+class AppleII_SoundFunction5_Noise : public AppleII_SoundFunction {
+public:
+ virtual void init(Player_AppleII *player, const byte *params) {
+ _player = player;
+ _index = 0;
+ _param0 = params[0];
+ assert(_param0 > 0);
+ }
+
+ virtual bool update() { // D222
+ const byte noiseMask[] = {
+ 0x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F
+ };
+
+ // while (i = 0; i < 10; ++i)
+ if (_index < 10) {
+ int count = _param0;
+ do {
+ _update(noise() & noiseMask[_index], 1);
+ --count;
+ } while (count > 0);
+
+ ++_index;
+ return false;
+ }
+
+ return true;
+ }
+
+private:
+ void _update(int interval /*a*/, int count) { // D270
+ assert(count > 0); // 0 == 256?
+ if (interval == 0)
+ interval = 256;
+
+ for (int i = count; i > 0; --i) {
+ _player->generateSamples(10 + 5*interval);
+ _player->speakerToggle();
+
+ _player->generateSamples(5 + 5*interval);
+ _player->speakerToggle();
+ }
+ }
+
+ byte /*a*/ noise() { // D261
+ static int pos = 0; // initial value?
+ byte result = _noiseTable[pos];
+ pos = (pos + 1) % 256;
+ return result;
+ }
+
+protected:
+ int _index;
+ int _param0;
+
+private:
+ static const byte _noiseTable[256];
+};
+
+// LD000[loc] ^ LD00A[loc]
+const byte AppleII_SoundFunction5_Noise::_noiseTable[256] = {
+ 0x65, 0x1b, 0xda, 0x11, 0x61, 0xe5, 0x77, 0x57, 0x92, 0xc8, 0x51, 0x1c, 0xd4, 0x91, 0x62, 0x63,
+ 0x00, 0x38, 0x57, 0xd5, 0x18, 0xd8, 0xdc, 0x40, 0x03, 0x86, 0xd3, 0x2f, 0x10, 0x11, 0xd8, 0x3c,
+ 0xbe, 0x00, 0x19, 0xc5, 0xd2, 0xc3, 0xca, 0x34, 0x00, 0x28, 0xbf, 0xb9, 0x18, 0x20, 0x01, 0xcc,
+ 0xda, 0x08, 0xbc, 0x75, 0x7c, 0xb0, 0x8d, 0xe0, 0x09, 0x18, 0xbf, 0x5d, 0xe9, 0x8c, 0x75, 0x64,
+ 0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, 0x18, 0xd2, 0x9e, 0x2a, 0x5a, 0x4b, 0x2a, 0xb6, 0x87, 0x30, 0x6c
+};
+
+/************************************
+ * Apple-II player
+ ************************************/
+
Player_AppleII::Player_AppleII(ScummEngine *scumm, Audio::Mixer *mixer) {
_mixer = mixer;
_vm = scumm;
+ _state.soundFunc = 0;
resetState();
setSampleRate(_mixer->getOutputRate());
@@ -40,6 +352,7 @@ Player_AppleII::Player_AppleII(ScummEngine *scumm, Audio::Mixer *mixer) {
Player_AppleII::~Player_AppleII() {
_mixer->stopHandle(_soundHandle);
+ delete _state.soundFunc;
}
/*
@@ -69,77 +382,56 @@ void logSounds() {
void Player_AppleII::startSound(int nr) {
Common::StackLock lock(_mutex);
- resetState();
-
byte *data = _vm->getResourceAddress(rtSound, nr);
assert(data);
byte *ptr1 = data + 4;
+ resetState();
+ _state.soundNr = nr;
_state.type = ptr1[0];
- if (_state.type == 0) {
- // nothing to play
+ _state.loop = ptr1[1];
+ _state.params = &ptr1[2];
+
+ switch (_state.type) {
+ case 0: // empty (nothing to play)
resetState();
return;
+ case 1:
+ _state.soundFunc = new AppleII_SoundFunction1_FreqUpDown();
+ break;
+ case 2:
+ _state.soundFunc = new AppleII_SoundFunction2_SymmetricWave();
+ break;
+ case 3:
+ _state.soundFunc = new AppleII_SoundFunction3_AsymmetricWave();
+ break;
+ case 4:
+ _state.soundFunc = new AppleII_SoundFunction4_Polyphone();
+ break;
+ case 5:
+ _state.soundFunc = new AppleII_SoundFunction5_Noise();
+ break;
}
+ _state.soundFunc->init(this, _state.params);
- _state.soundNr = nr;
- _state.finished = false;
- initFuncState();
-
- _state.loop = ptr1[1];
assert(_state.loop > 0);
- _state.params = &ptr1[2];
-
debug(4, "startSound %d: type %d, loop %d",
nr, _state.type, _state.loop);
}
-void Player_AppleII::initFuncState() {
- switch (_state.type) {
- case 2: case 3:
- _state.func23.pos = 1;
- break;
- case 4:
- _state.func4.updateRemain1 = 80;
- _state.func4.updateRemain2 = 10;
- break;
- case 5:
- _state.func5.index = 0;
- break;
- }
-}
-
bool Player_AppleII::updateSound() {
- if (!_state.soundNr || _state.finished)
+ if (!_state.soundFunc)
return false;
- bool done = false;
- switch (_state.type) {
- case 1: // freq up/down
- done = soundFunc1();
- break;
- case 2: // symmetric wave (~)
- done = soundFunc2();
- break;
- case 3: // asymmetric wave (__-)
- done = soundFunc3();
- break;
- case 4: // polyphone (2 voices)
- done = soundFunc4();
- break;
- case 5: // periodic noise
- done = soundFunc5();
- break;
- }
-
- if (done) {
+ if (_state.soundFunc->update()) {
--_state.loop;
if (_state.loop <= 0) {
- _state.finished = true;
+ delete _state.soundFunc;
+ _state.soundFunc = 0;
} else {
// reset function state on each loop
- initFuncState();
+ _state.soundFunc->init(this, _state.params);
}
}
@@ -151,9 +443,9 @@ void Player_AppleII::resetState() {
_state.type = 0;
_state.loop = 0;
_state.params = NULL;
- _state.localParams = NULL;
_state.speakerState = 0;
- _state.finished = true;
+ delete _state.soundFunc;
+ _state.soundFunc = 0;
_sampleConverter.reset();
}
@@ -194,14 +486,14 @@ int Player_AppleII::readBuffer(int16 *buffer, const int numSamples) {
} while ((samplesLeft > 0) && updateSound());
// reset state if sound is played completely
- if (_state.finished && (_sampleConverter.availableSize() == 0))
+ if (!_state.soundFunc && (_sampleConverter.availableSize() == 0))
resetState();
return numSamples - samplesLeft;
}
/************************************
- * Apple-II sound-resource parser
+ * Apple-II sound-resource helpers
************************************/
// toggle speaker on/off
@@ -219,229 +511,4 @@ void Player_AppleII::wait(int interval, int count /*y*/) {
generateSamples(11 + count*(8 + 5 * interval));
}
-void Player_AppleII::_soundFunc1(int interval /*a*/, int count /*y*/) { // D076
- assert(interval > 0); // 0 == 256?
- assert(count > 0); // 0 == 256?
-
- for (; count >= 0; --count) {
- speakerToggle();
- generateSamples(17 + 5 * interval);
- }
-}
-
-bool Player_AppleII::soundFunc1() { // D085
- const int delta = _state.params[0];
- const int count = _state.params[1];
- byte interval = _state.params[2]; // must be byte ("interval < delta" possible)
- const int limit = _state.params[3];
- const bool decInterval = (_state.params[4] >= 0x40);
-
- if (decInterval) {
- do {
- _soundFunc1(interval, count);
- interval -= delta;
- } while (interval >= limit);
- } else {
- do {
- _soundFunc1(interval, count);
- interval += delta;
- } while (interval < limit);
- }
-
- return true;
-}
-
-void Player_AppleII::_soundFunc2(int interval /*a*/, int count) { // D0EF
- if (interval == 0xFE) {
- wait(interval, 10);
- } else {
- assert(count > 0); // 0 == 256?
- assert(interval > 0); // 0 == 256?
-
- int a = (interval >> 3) + count;
- for (int y = a; y > 0; --y) {
- generateSamples(1292 - 5*interval);
- speakerToggle();
-
- generateSamples(1287 - 5*interval);
- speakerToggle();
- }
- }
-}
-
-bool Player_AppleII::soundFunc2() { // D0D6
- // while (pos = 1; pos < 256; ++pos)
- if (_state.func23.pos < 256) {
- byte interval = _state.params[_state.func23.pos];
- if (interval == 0xFF)
- return true;
- _soundFunc2(interval, _state.params[0] /*, LD12F=interval*/);
-
- ++_state.func23.pos;
- return false;
- }
- return true;
-}
-
-void Player_AppleII::_soundFunc3(int interval /*a*/, int count /*LD12D*/) { // D14B
- if (interval == 0xFE) {
- wait(interval, 70);
- } else {
- assert(interval > 0); // 0 == 256?
- assert(count > 0); // 0 == 256?
-
- for (int y = count; y > 0; --y) {
- generateSamples(1289 - 5*interval);
- speakerToggle();
- }
- }
-}
-
-bool Player_AppleII::soundFunc3() { // D132
- // while (pos = 1; pos < 256; ++pos)
- if (_state.func23.pos < 256) {
- byte interval = _state.params[_state.func23.pos];
- if (interval == 0xFF)
- return true;
- _soundFunc3(interval, _state.params[0]);
-
- ++_state.func23.pos;
- return false;
- }
- return true;
-}
-
-void Player_AppleII::_soundFunc4(byte param0, byte param1, byte param2) { // D1A2
- uint16 count = (-param2 << 8) | 0x3;
- byte bitmask1 = 0x3;
- byte 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;
- }
- }
-
- byte speakerShiftReg = 0;
- byte updateRemain1 = _state.func4.updateRemain1;
- byte updateRemain2 = _state.func4.updateRemain2;
-
- while (true) {
- --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 (speakerShiftReg & 0x1)
- speakerToggle();
- speakerShiftReg >>= 1;
- generateSamples(42); /* actually 42.5 */
-
- ++count;
- if (count == 0) {
- _state.func4.updateRemain1 = updateRemain1;
- _state.func4.updateRemain2 = updateRemain2;
- return;
- }
- }
-}
-
-bool Player_AppleII::soundFunc4() { // D170
- if (!_state.localParams)
- _state.localParams = _state.params;
-
- // while (_state.params[0] != 0x01)
- if (_state.localParams[0] != 0x01) {
- _soundFunc4(_state.localParams[0], _state.localParams[1], _state.localParams[2]);
- _state.localParams += 3;
- return false;
- }
-
- _state.localParams = NULL;
- return true;
-}
-
-void Player_AppleII::_soundFunc5(int interval /*a*/, int count) { // D270
- assert(count > 0); // 0 == 256?
- if (interval == 0)
- interval = 256;
-
- for (int i = count; i > 0; --i) {
- generateSamples(10 + 5*interval);
- speakerToggle();
-
- generateSamples(5 + 5*interval);
- speakerToggle();
- }
-}
-
-// LD000[loc] ^ LD00A[loc]
-static const byte noiseTable[256] = {
- 0x65, 0x1b, 0xda, 0x11, 0x61, 0xe5, 0x77, 0x57, 0x92, 0xc8, 0x51, 0x1c, 0xd4, 0x91, 0x62, 0x63,
- 0x00, 0x38, 0x57, 0xd5, 0x18, 0xd8, 0xdc, 0x40, 0x03, 0x86, 0xd3, 0x2f, 0x10, 0x11, 0xd8, 0x3c,
- 0xbe, 0x00,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, 0x61, 0xd9, 0xed, 0xa0, 0xfe, 0x19, 0x91, 0x37,
- 0x19, 0x37, 0x00, 0xf1, 0x00, 0x01, 0x1f, 0x00, 0xad, 0xc1, 0x01, 0x01, 0x2e, 0x00, 0x40, 0xc6,
- 0x7a, 0x9b, 0x95, 0x43, 0xfc, 0x18, 0xd2, 0x9e, 0x2a, 0x5a, 0x4b, 0x2a, 0xb6, 0x87, 0x30, 0x6c
-};
-
-byte /*a*/ Player_AppleII::noise() { // D261
- static int pos = 0; // initial value?
- byte result = noiseTable[pos];
- pos = (pos + 1) % 256;
- return result;
-}
-
-bool Player_AppleII::soundFunc5() { // D222
- const byte noiseMask[] = {
- 0x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0x0F, 0x0F
- };
-
- int param0 = _state.params[0];
- assert(param0 > 0);
-
- // while (i = 0; i < 10; ++i)
- if (_state.func5.index < 10) {
- int count = param0;
- do {
- _soundFunc5(noise() & noiseMask[_state.func5.index], 1);
- --count;
- } while (count > 0);
-
- ++_state.func5.index;
- return false;
- }
-
- return true;
-}
-
} // End of namespace Scumm
diff --git a/engines/scumm/player_appleII.h b/engines/scumm/player_appleII.h
index eb4a99c4bd..91c7935f76 100644
--- a/engines/scumm/player_appleII.h
+++ b/engines/scumm/player_appleII.h
@@ -217,6 +217,8 @@ private:
DynamicMemoryStream _buffer;
};
+class AppleII_SoundFunction;
+
class Player_AppleII : public Audio::AudioStream, public MusicEngine {
public:
Player_AppleII(ScummEngine *scumm, Audio::Mixer *mixer);
@@ -240,6 +242,11 @@ public:
bool endOfData() const { return false; }
int getRate() const { return _sampleRate; }
+public:
+ void speakerToggle();
+ void generateSamples(int cycles);
+ void wait(int interval, int count);
+
private:
struct sound_state {
// sound number
@@ -250,25 +257,10 @@ private:
int loop;
// global sound param list
const byte *params;
- // local sound param list
- const byte *localParams;
// speaker toggle state (0 / 1)
byte speakerState;
- // processing complete
- bool finished;
- // sound type specific data
- union {
- struct {
- byte updateRemain1;
- byte updateRemain2;
- } func4;
- struct {
- int pos;
- } func23;
- struct {
- int index;
- } func5;
- };
+ // sound function
+ AppleII_SoundFunction *soundFunc;
} _state;
ScummEngine *_vm;
@@ -282,23 +274,17 @@ private:
private:
void resetState();
- void initFuncState();
bool updateSound();
- void speakerToggle();
- void generateSamples(int cycles);
- void wait(int interval, int count);
- byte noise();
-
- bool soundFunc1();
- void _soundFunc1(int interval, int count);
- bool soundFunc2();
- void _soundFunc2(int interval, int count);
- bool soundFunc3();
- void _soundFunc3(int interval, int count);
- bool soundFunc4();
- void _soundFunc4(byte param0, byte param1, byte param2);
- bool soundFunc5();
- void _soundFunc5(int interval, int count);
+};
+
+class AppleII_SoundFunction {
+public:
+ AppleII_SoundFunction() {}
+ virtual ~AppleII_SoundFunction() {}
+ virtual void init(Player_AppleII *player, const byte *params) = 0;
+ virtual bool update() = 0;
+protected:
+ Player_AppleII *_player;
};
} // End of namespace Scumm