diff options
author | Tobias Gunkel | 2011-12-22 10:53:25 +0100 |
---|---|---|
committer | Tobias Gunkel | 2011-12-22 12:08:30 +0100 |
commit | 8b77f18c9e88ec2cea559578e10b33399f40a82d (patch) | |
tree | d193936e14be5fca1d4ef10f020482d9360079e4 /engines/scumm | |
parent | 12103981b786d81e96ec38cc5ff24c3ce3bd9909 (diff) | |
download | scummvm-rg350-8b77f18c9e88ec2cea559578e10b33399f40a82d.tar.gz scummvm-rg350-8b77f18c9e88ec2cea559578e10b33399f40a82d.tar.bz2 scummvm-rg350-8b77f18c9e88ec2cea559578e10b33399f40a82d.zip |
SCUMM: Revert now obsolete separation of state variables in player_appleII
Diffstat (limited to 'engines/scumm')
-rw-r--r-- | engines/scumm/player_appleII.cpp | 88 | ||||
-rw-r--r-- | engines/scumm/player_appleII.h | 61 |
2 files changed, 73 insertions, 76 deletions
diff --git a/engines/scumm/player_appleII.cpp b/engines/scumm/player_appleII.cpp index 0631bcd055..f250f686e6 100644 --- a/engines/scumm/player_appleII.cpp +++ b/engines/scumm/player_appleII.cpp @@ -187,7 +187,7 @@ public: } virtual bool update() { // D170 - // while (_state.params[0] != 0x01) + // while (_params[0] != 0x01) if (_params[0] != 0x01) { if (_count == 0) // prepare next loop nextLoop(_params[0], _params[1], _params[2]); @@ -355,21 +355,27 @@ const byte AppleII_SoundFunction5_Noise::_noiseTable[256] = { * Apple-II player ************************************/ -Player_AppleII::Player_AppleII(ScummEngine *scumm, Audio::Mixer *mixer) { - _mixer = mixer; - _vm = scumm; - - _state.soundFunc = 0; +Player_AppleII::Player_AppleII(ScummEngine *scumm, Audio::Mixer *mixer) + : _mixer(mixer), _vm(scumm), _soundFunc(0) { resetState(); - setSampleRate(_mixer->getOutputRate()); - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); } Player_AppleII::~Player_AppleII() { _mixer->stopHandle(_soundHandle); - delete _state.soundFunc; + delete _soundFunc; +} + +void Player_AppleII::resetState() { + _soundNr = 0; + _type = 0; + _loop = 0; + _params = NULL; + _speakerState = 0; + delete _soundFunc; + _soundFunc = 0; + _sampleConverter.reset(); } void Player_AppleII::startSound(int nr) { @@ -380,69 +386,57 @@ void Player_AppleII::startSound(int nr) { byte *ptr1 = data + 4; resetState(); - _state.soundNr = nr; - _state.type = ptr1[0]; - _state.loop = ptr1[1]; - _state.params = &ptr1[2]; + _soundNr = nr; + _type = ptr1[0]; + _loop = ptr1[1]; + _params = &ptr1[2]; - switch (_state.type) { + switch (_type) { case 0: // empty (nothing to play) resetState(); return; case 1: - _state.soundFunc = new AppleII_SoundFunction1_FreqUpDown(); + _soundFunc = new AppleII_SoundFunction1_FreqUpDown(); break; case 2: - _state.soundFunc = new AppleII_SoundFunction2_SymmetricWave(); + _soundFunc = new AppleII_SoundFunction2_SymmetricWave(); break; case 3: - _state.soundFunc = new AppleII_SoundFunction3_AsymmetricWave(); + _soundFunc = new AppleII_SoundFunction3_AsymmetricWave(); break; case 4: - _state.soundFunc = new AppleII_SoundFunction4_Polyphone(); + _soundFunc = new AppleII_SoundFunction4_Polyphone(); break; case 5: - _state.soundFunc = new AppleII_SoundFunction5_Noise(); + _soundFunc = new AppleII_SoundFunction5_Noise(); break; } - _state.soundFunc->init(this, _state.params); + _soundFunc->init(this, _params); - assert(_state.loop > 0); + assert(_loop > 0); debug(4, "startSound %d: type %d, loop %d", - nr, _state.type, _state.loop); + nr, _type, _loop); } bool Player_AppleII::updateSound() { - if (!_state.soundFunc) + if (!_soundFunc) return false; - if (_state.soundFunc->update()) { - --_state.loop; - if (_state.loop <= 0) { - delete _state.soundFunc; - _state.soundFunc = 0; + if (_soundFunc->update()) { + --_loop; + if (_loop <= 0) { + delete _soundFunc; + _soundFunc = 0; } else { // reset function state on each loop - _state.soundFunc->init(this, _state.params); + _soundFunc->init(this, _params); } } return true; } -void Player_AppleII::resetState() { - _state.soundNr = 0; - _state.type = 0; - _state.loop = 0; - _state.params = NULL; - _state.speakerState = 0; - delete _state.soundFunc; - _state.soundFunc = 0; - - _sampleConverter.reset(); -} - void Player_AppleII::stopAllSounds() { Common::StackLock lock(_mutex); resetState(); @@ -450,14 +444,14 @@ void Player_AppleII::stopAllSounds() { void Player_AppleII::stopSound(int nr) { Common::StackLock lock(_mutex); - if (_state.soundNr == nr) { + if (_soundNr == nr) { resetState(); } } int Player_AppleII::getSoundStatus(int nr) const { Common::StackLock lock(_mutex); - return (_state.soundNr == nr); + return (_soundNr == nr); } int Player_AppleII::getMusicTimer() { @@ -468,7 +462,7 @@ int Player_AppleII::getMusicTimer() { int Player_AppleII::readBuffer(int16 *buffer, const int numSamples) { Common::StackLock lock(_mutex); - if (!_state.soundNr) + if (!_soundNr) return 0; int samplesLeft = numSamples; @@ -479,7 +473,7 @@ int Player_AppleII::readBuffer(int16 *buffer, const int numSamples) { } while ((samplesLeft > 0) && updateSound()); // reset state if sound is played completely - if (!_state.soundFunc && (_sampleConverter.availableSize() == 0)) + if (!_soundFunc && (_sampleConverter.availableSize() == 0)) resetState(); return numSamples - samplesLeft; @@ -491,11 +485,11 @@ int Player_AppleII::readBuffer(int16 *buffer, const int numSamples) { // toggle speaker on/off void Player_AppleII::speakerToggle() { - _state.speakerState ^= 0x1; + _speakerState ^= 0x1; } void Player_AppleII::generateSamples(int cycles) { - _sampleConverter.addCycles(_state.speakerState, cycles); + _sampleConverter.addCycles(_speakerState, cycles); } void Player_AppleII::wait(int interval, int count /*y*/) { diff --git a/engines/scumm/player_appleII.h b/engines/scumm/player_appleII.h index a44e7b6afe..9e97ab0c89 100644 --- a/engines/scumm/player_appleII.h +++ b/engines/scumm/player_appleII.h @@ -131,6 +131,11 @@ private: // CPU_CLOCK according to AppleWin static const double APPLEII_CPU_CLOCK = 1020484.5; // ~ 1.02 MHz +/* + * Converts the 1-bit speaker state values into audio samples. + * This is done by aggregation of the speaker states at each + * CPU cycle in a sampling period into an audio sample. + */ class SampleConverter { private: void addSampleToBuffer(int sample) { @@ -219,7 +224,18 @@ private: SampleBuffer _buffer; }; -class AppleII_SoundFunction; +class Player_AppleII; + +class AppleII_SoundFunction { +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; +}; class Player_AppleII : public Audio::AudioStream, public MusicEngine { public: @@ -250,21 +266,22 @@ public: void wait(int interval, int count); private: - struct sound_state { - // sound number - int soundNr; - // type of sound - int type; - // number of loops left - int loop; - // global sound param list - const byte *params; - // speaker toggle state (0 / 1) - byte speakerState; - // sound function - AppleII_SoundFunction *soundFunc; - } _state; + // sound number + int _soundNr; + // type of sound + int _type; + // number of loops left + int _loop; + // global sound param list + const byte *_params; + // speaker toggle state (0 / 1) + byte _speakerState; + // sound function + AppleII_SoundFunction *_soundFunc; + // cycle to sample converter + SampleConverter _sampleConverter; +private: ScummEngine *_vm; Audio::Mixer *_mixer; Audio::SoundHandle _soundHandle; @@ -272,24 +289,10 @@ private: Common::Mutex _mutex; private: - SampleConverter _sampleConverter; - -private: void resetState(); bool updateSound(); }; -class AppleII_SoundFunction { -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; -}; - } // End of namespace Scumm #endif |