diff options
author | Matthew Hoops | 2015-04-04 20:01:15 -0400 |
---|---|---|
committer | Matthew Hoops | 2015-07-07 20:19:44 -0400 |
commit | 5024ae136a73d90b1d5a450aed0f990f226e3056 (patch) | |
tree | b4c9f391b4931e8b03ba37bf4f25b08b2f8105ce /engines/tsage | |
parent | 4a4ad97fd3747f2bca749960e3e894cfc90c5f68 (diff) | |
download | scummvm-rg350-5024ae136a73d90b1d5a450aed0f990f226e3056.tar.gz scummvm-rg350-5024ae136a73d90b1d5a450aed0f990f226e3056.tar.bz2 scummvm-rg350-5024ae136a73d90b1d5a450aed0f990f226e3056.zip |
TSAGE: Use the built-in OPL timer
Diffstat (limited to 'engines/tsage')
-rw-r--r-- | engines/tsage/sound.cpp | 41 | ||||
-rw-r--r-- | engines/tsage/sound.h | 9 |
2 files changed, 13 insertions, 37 deletions
diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp index 6ff983eef6..ddfaa0a769 100644 --- a/engines/tsage/sound.cpp +++ b/engines/tsage/sound.cpp @@ -2748,13 +2748,6 @@ AdlibSoundDriver::AdlibSoundDriver(): SoundDriver() { assert(_opl); _opl->init(); - _samplesTillCallback = 0; - _samplesTillCallbackRemainder = 0; - _samplesPerCallback = getRate() / CALLBACKS_PER_SECOND; - _samplesPerCallbackRemainder = getRate() % CALLBACKS_PER_SECOND; - - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); - Common::fill(_channelVoiced, _channelVoiced + ADLIB_CHANNEL_COUNT, false); memset(_channelVolume, 0, ADLIB_CHANNEL_COUNT * sizeof(int)); memset(_v4405E, 0, ADLIB_CHANNEL_COUNT * sizeof(int)); @@ -2772,6 +2765,9 @@ AdlibSoundDriver::AdlibSoundDriver(): SoundDriver() { _channelVoiced[i] = false; _pitchBlend[i] = 0; } + + _opl->start(new Common::Functor0Mem<void, AdlibSoundDriver>(this, &AdlibSoundDriver::onTimer), CALLBACKS_PER_SECOND); + _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); } AdlibSoundDriver::~AdlibSoundDriver() { @@ -3019,33 +3015,16 @@ void AdlibSoundDriver::setFrequency(int channel) { ((dataWord >> 8) & 3) | (var2 << 2)); } -int AdlibSoundDriver::readBuffer(int16 *buffer, const int numSamples) { +int AdlibSoundDriver::readBuffer(int16 *data, const int numSamples) { + return _opl->readBuffer(data, numSamples); +} + +void AdlibSoundDriver::onTimer() { Common::StackLock slock1(SoundManager::sfManager()._serverDisabledMutex); Common::StackLock slock2(SoundManager::sfManager()._serverSuspendedMutex); - int32 samplesLeft = numSamples; - memset(buffer, 0, sizeof(int16) * numSamples); - while (samplesLeft) { - if (!_samplesTillCallback) { - SoundManager::sfUpdateCallback(NULL); - 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; - - _opl->readBuffer(buffer, render); - buffer += render; - } - return numSamples; + SoundManager::sfUpdateCallback(NULL); + flush(); } /*--------------------------------------------------------------------------*/ diff --git a/engines/tsage/sound.h b/engines/tsage/sound.h index c222a6e7c6..7ea1e6595e 100644 --- a/engines/tsage/sound.h +++ b/engines/tsage/sound.h @@ -460,10 +460,6 @@ private: const byte *_patchData; int _masterVolume; Common::Queue<RegisterValue> _queue; - int _samplesTillCallback; - int _samplesTillCallbackRemainder; - int _samplesPerCallback; - int _samplesPerCallbackRemainder; bool _channelVoiced[ADLIB_CHANNEL_COUNT]; int _channelVolume[ADLIB_CHANNEL_COUNT]; @@ -499,12 +495,13 @@ public: virtual void setPitch(int channel, int pitchBlend); // AudioStream interface - virtual int readBuffer(int16 *buffer, const int numSamples); + virtual int readBuffer(int16 *data, const int numSamples); virtual bool isStereo() const { return false; } virtual bool endOfData() const { return false; } virtual int getRate() const { return _sampleRate; } - void update(int16 *buf, int len); +private: + void onTimer(); }; class SoundBlasterDriver: public SoundDriver { |