diff options
Diffstat (limited to 'engines/tsage/sound.cpp')
-rw-r--r-- | engines/tsage/sound.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp index 0c0d93be03..24c64bda3c 100644 --- a/engines/tsage/sound.cpp +++ b/engines/tsage/sound.cpp @@ -51,6 +51,8 @@ SoundManager::SoundManager() { _needToRethink = false; _soTimeIndexFlag = false; + _updateTicksCounter = 0; + _eventsDelay = GAME_FRAME_TIME; } SoundManager::~SoundManager() { @@ -114,6 +116,14 @@ void SoundManager::syncSounds() { this->setMasterVol(musicVolume / 2); } +void SoundManager::update() { + ++_updateTicksCounter; + if (_updateTicksCounter > _eventsDelay) { + _sfSoundServer(); + _updateTicksCounter = 0; + } +} + Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool detectFlag) { assert(__sndmgrReady); _availableDrivers.clear(); @@ -482,6 +492,10 @@ void SoundManager::_sfUpdateVoiceStructs2() { } } +void SoundManager::_sfUpdateCallback(void *ref) { + ((SoundManager *)ref)->update(); +} + /*--------------------------------------------------------------------------*/ void SoundManager::saveNotifier(bool postFlag) { @@ -1293,7 +1307,8 @@ void SoundManager::_sfExtractGroupMask() { bool SoundManager::_sfInstallDriver(SoundDriver *driver) { if (!driver->open()) return false; - + + driver->setUpdateCallback(_sfUpdateCallback, (void *)&sfManager()); sfManager()._installedDrivers.push_back(driver); driver->_groupOffset = driver->getGroupData(); driver->_groupMask = READ_LE_UINT32(driver->_groupOffset); @@ -2376,6 +2391,8 @@ const int v440D4[48] = { }; AdlibSoundDriver::AdlibSoundDriver(): SoundDriver() { + _upCb = NULL; + _upRef = NULL; _minVersion = 0x102; _maxVersion = 0x10A; _masterVolume = 0; @@ -2388,6 +2405,7 @@ AdlibSoundDriver::AdlibSoundDriver(): SoundDriver() { _mixer = _vm->_mixer; _sampleRate = _mixer->getOutputRate(); _opl = makeAdLibOPL(_sampleRate); + _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); Common::set_to(_channelVoiced, _channelVoiced + ADLIB_CHANNEL_COUNT, false); memset(_channelVolume, 0, ADLIB_CHANNEL_COUNT * sizeof(int)); @@ -2404,6 +2422,7 @@ AdlibSoundDriver::AdlibSoundDriver(): SoundDriver() { AdlibSoundDriver::~AdlibSoundDriver() { DEALLOCATE(_patchData); + _mixer->stopHandle(_soundHandle); OPLDestroy(_opl); } @@ -2640,4 +2659,34 @@ void AdlibSoundDriver::setFrequency(int channel) { ((dataWord >> 8) & 3) | (var2 << 2)); } +int AdlibSoundDriver::readBuffer(int16 *buffer, const int numSamples) { + update(buffer, numSamples); + return numSamples; +} + +void AdlibSoundDriver::update(int16 *buf, int len) { + static int samplesLeft = 0; + while (len != 0) { + int count = samplesLeft; + if (count > len) { + count = len; + } + samplesLeft -= count; + len -= count; + YM3812UpdateOne(_opl, buf, count); + if (samplesLeft == 0) { + if (_upCb) { + (*_upCb)(_upRef); + } + samplesLeft = _sampleRate / 50; + } + buf += count; + } +} + +void AdlibSoundDriver::setUpdateCallback(UpdateCallback upCb, void *ref) { + _upCb = upCb; + _upRef = ref; +} + } // End of namespace tSage |