diff options
Diffstat (limited to 'engines/mads/nebular')
-rw-r--r-- | engines/mads/nebular/sound_nebular.cpp | 45 | ||||
-rw-r--r-- | engines/mads/nebular/sound_nebular.h | 9 |
2 files changed, 16 insertions, 38 deletions
diff --git a/engines/mads/nebular/sound_nebular.cpp b/engines/mads/nebular/sound_nebular.cpp index 10cbc73bf2..0a1c1ea288 100644 --- a/engines/mads/nebular/sound_nebular.cpp +++ b/engines/mads/nebular/sound_nebular.cpp @@ -189,11 +189,6 @@ ASound::ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::String &filenam _randomSeed = 1234; _amDep = _vibDep = _splitPoint = true; - _samplesTillCallback = 0; - _samplesTillCallbackRemainder = 0; - _samplesPerCallback = getRate() / CALLBACKS_PER_SECOND; - _samplesPerCallbackRemainder = getRate() % CALLBACKS_PER_SECOND; - for (int i = 0; i < 11; ++i) { _channelData[i]._field0 = 0; _channelData[i]._freqMask = 0; @@ -211,15 +206,15 @@ ASound::ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::String &filenam _mixer = mixer; _opl = opl; - _opl->init(); - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, - Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); - // Initialize the Adlib adlibInit(); // Reset the adlib command0(); + + _opl->start(new Common::Functor0Mem<void, ASound>(this, &ASound::onTimer), CALLBACKS_PER_SECOND); + _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, + Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); } ASound::~ASound() { @@ -833,32 +828,14 @@ void ASound::updateFNumber() { write2(8, hiReg, val2); } -int ASound::readBuffer(int16 *buffer, const int numSamples) { - Common::StackLock slock(_driverMutex); - - int32 samplesLeft = numSamples; - memset(buffer, 0, sizeof(int16) * numSamples); - while (samplesLeft) { - if (!_samplesTillCallback) { - poll(); - flush(); - - _samplesTillCallback = _samplesPerCallback; - _samplesTillCallbackRemainder += _samplesPerCallbackRemainder; - if (_samplesTillCallbackRemainder >= CALLBACKS_PER_SECOND) { - _samplesTillCallback++; - _samplesTillCallbackRemainder -= CALLBACKS_PER_SECOND; - } - } - - int32 render = MIN<int>(samplesLeft, _samplesTillCallback); - samplesLeft -= render; - _samplesTillCallback -= render; +int ASound::readBuffer(int16 *data, const int numSamples) { + return _opl->readBuffer(data, numSamples); +} - _opl->readBuffer(buffer, render); - buffer += render; - } - return numSamples; +void ASound::onTimer() { + Common::StackLock slock(_driverMutex); + poll(); + flush(); } int ASound::getRate() const { diff --git a/engines/mads/nebular/sound_nebular.h b/engines/mads/nebular/sound_nebular.h index 8c1d7f8021..1267914e35 100644 --- a/engines/mads/nebular/sound_nebular.h +++ b/engines/mads/nebular/sound_nebular.h @@ -195,6 +195,11 @@ private: void processSample(); void updateFNumber(); + + /** + * Timer function for OPL + */ + void onTimer(); protected: int _commandParam; @@ -309,10 +314,6 @@ public: int _activeChannelReg; int _v11; bool _amDep, _vibDep, _splitPoint; - int _samplesPerCallback; - int _samplesPerCallbackRemainder; - int _samplesTillCallback; - int _samplesTillCallbackRemainder; public: /** * Constructor |