diff options
author | Paul Gilbert | 2011-05-04 23:13:15 +1000 |
---|---|---|
committer | Paul Gilbert | 2011-05-04 23:13:15 +1000 |
commit | c470d1e6d2977622530ae53f1620e813849720c9 (patch) | |
tree | a1f5498066a8ac9f4df277369a795d1febbd759f /engines/tsage/sound.cpp | |
parent | 765a82dd9699bb952803c9941b5f942a82c16c7c (diff) | |
download | scummvm-rg350-c470d1e6d2977622530ae53f1620e813849720c9.tar.gz scummvm-rg350-c470d1e6d2977622530ae53f1620e813849720c9.tar.bz2 scummvm-rg350-c470d1e6d2977622530ae53f1620e813849720c9.zip |
TSAGE: Implemented more SoundManager methods
Diffstat (limited to 'engines/tsage/sound.cpp')
-rw-r--r-- | engines/tsage/sound.cpp | 216 |
1 files changed, 174 insertions, 42 deletions
diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp index a8dcb5cd07..2b7a2c686d 100644 --- a/engines/tsage/sound.cpp +++ b/engines/tsage/sound.cpp @@ -50,15 +50,18 @@ SoundManager::SoundManager() { _suspendCtr = 0; _disableCtr = 0; _field153 = 0; - _field16D = 0; + _driversDetected = false; } SoundManager::~SoundManager() { if (__sndmgrReady) { for (Common::List<Sound *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) (*i)->stop(); - for (Common::List<SoundDriver *>::iterator i = _installedDrivers.begin(); i != _installedDrivers.end(); ++i) - unInstallDriver(*i); + for (Common::List<SoundDriver *>::iterator i = _installedDrivers.begin(); i != _installedDrivers.end(); ) { + int driverNum = (*i)->_driverNum; + ++i; + unInstallDriver(driverNum); + } _sfTerminate(); } } @@ -72,70 +75,154 @@ void SoundManager::postInit() { } } -void SoundManager::saveNotifier(bool postFlag) { - _globals->_soundManager.saveNotifierProc(postFlag); -} +Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool detectFlag) { + assert(__sndmgrReady); + _availableDrivers.clear(); -void SoundManager::saveNotifierProc(bool postFlag) { - warning("TODO: SoundManager::saveNotifierProc"); -} + // Build up a list of available drivers. Currently we only implement an Adlib driver + SoundDriverEntry sd; + sd.driverNum = ADLIB_DRIVER_NUM; + sd.status = detectFlag ? SNDSTATUS_DETECTED : SNDSTATUS_SKIPPED; + sd.field2 = 0; + sd.field6 = 15000; + sd.shortDescription = "Adlib or SoundBlaster"; + sd.longDescription = "3812fm"; + _availableDrivers.push_back(sd); -void SoundManager::loadNotifier(bool postFlag) { - _globals->_soundManager.loadNotifierProc(postFlag); + _driversDetected = true; + return _availableDrivers; } -void SoundManager::loadNotifierProc(bool postFlag) { - warning("TODO: SoundManager::loadNotifierProc"); +void SoundManager::installConfigDrivers() { + } -void SoundManager::listenerSynchronise(Serialiser &s) { - s.validate("SoundManager"); - warning("TODO: SoundManager listenerSynchronise"); +Common::List<SoundDriverEntry> &SoundManager::getDriverList(bool detectFlag) { + if (detectFlag) + return _availableDrivers; + else + return buildDriverList(false); } -void SoundManager::checkResVersion(const byte *soundData) { - int maxVersion = READ_LE_UINT16(soundData + 4); - int minVersion = READ_LE_UINT16(soundData + 6); +void SoundManager::dumpDriverList() { + _availableDrivers.clear(); +} - if (_globals->_soundManager._minVersion < minVersion) - error("Attempt to play/prime sound resource that is too new"); - if (_globals->_soundManager._minVersion > maxVersion) - error("Attempt to play/prime sound resource that is too old"); +void SoundManager::disableSoundServer() { + ++_disableCtr; } -/*--------------------------------------------------------------------------*/ +void SoundManager::enableSoundServer() { + if (_disableCtr > 0) + --_disableCtr; +} void SoundManager::suspendSoundServer() { - ++_globals->_soundManager._suspendCtr; + ++_suspendCtr; } - void SoundManager::restartSoundServer() { - if (_globals->_soundManager._suspendCtr > 0) - --_globals->_soundManager._suspendCtr; + if (_suspendCtr > 0) + --_suspendCtr; } -void SoundManager::unInstallDriver(SoundDriver *driver) { +/** + * Install the specified driver number + */ +void SoundManager::installDriver(int driverNum) { + // If driver is already installed, no need to install it + if (isInstalled(driverNum)) + return; + + // Instantiate the sound driver + SoundDriver *driver = instantiateDriver(driverNum); + if (!driver) + return; + + assert((_maxVersion >= driver->_minVersion) && (_maxVersion <= driver->_maxVersion)); + + // Mute any loaded sounds + disableSoundServer(); + for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i) + (*i)->mute(true); + + // Install the driver + if (!_sfInstallDriver(driver)) + error("Sound driver initialization failed"); + + switch (driverNum) { + case ROLAND_DRIVER_NUM: + case ADLIB_DRIVER_NUM: { + // Handle loading bank infomation + byte *bankData = _resourceManager->getResource(RES_BANK, ROLAND_DRIVER_NUM, 0, true); + if (bankData) { + // Install the patch bank data + _sfInstallPatchBank(bankData); + DEALLOCATE(bankData); + } else { + // Could not locate patch bank data, so unload the driver + _sfUnInstallDriver(driver); + + // Unmute currently active sounds + for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i) + (*i)->mute(false); + enableSoundServer(); + } + break; + } + } } -Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool flag) { - assert(__sndmgrReady); - _driverList.clear(); - - warning("TODO: SoundManager::buildDriverList"); - return _driverList; +/** + * Instantiate a driver class for the specified driver number + */ +SoundDriver *SoundManager::instantiateDriver(int driverNum) { + assert(driverNum == ADLIB_DRIVER_NUM); + return new AdlibSoundDriver(); } -Common::List<SoundDriverEntry> &SoundManager::getDriverList(bool flag) { - if (flag) - return _driverList; - else - return buildDriverList(false); +/** + * Uninstall the specified driver + */ +void SoundManager::unInstallDriver(int driverNum) { + Common::List<SoundDriver *>::const_iterator i; + for (i = _installedDrivers.begin(); i != _installedDrivers.end(); ++i) { + if ((*i)->_driverNum == driverNum) { + // Found driver to remove + + // Mute any loaded sounds + disableSoundServer(); + for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i) + (*i)->mute(true); + + // Uninstall the driver + _sfUnInstallDriver(*i); + + // Re-orient all the loaded sounds + for (Common::List<Sound *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) + (*i)->orientAfterDriverChange(); + + // Unmute currently active sounds + for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i) + (*i)->mute(false); + + enableSoundServer(); + } + } } -void SoundManager::dumpDriverList() { - _driverList.clear(); +/** + * Returns true if a specified driver number is currently installed + */ +bool SoundManager::isInstalled(int driverNum) const { + Common::List<SoundDriver *>::const_iterator i; + for (i = _installedDrivers.begin(); i != _installedDrivers.end(); ++i) { + if ((*i)->_driverNum == driverNum) + return true; + } + + return false; } void SoundManager::setMasterVol(int volume) { @@ -158,6 +245,16 @@ int SoundManager::determineGroup(const byte *soundData) { return _sfDetermineGroup(soundData); } +void SoundManager::checkResVersion(const byte *soundData) { + int maxVersion = READ_LE_UINT16(soundData + 4); + int minVersion = READ_LE_UINT16(soundData + 6); + + if (_globals->_soundManager._minVersion < minVersion) + error("Attempt to play/prime sound resource that is too new"); + if (_globals->_soundManager._minVersion > maxVersion) + error("Attempt to play/prime sound resource that is too old"); +} + int SoundManager::extractPriority(const byte *soundData) { return READ_LE_UINT16(soundData + 12); } @@ -209,6 +306,29 @@ void SoundManager::rethinkVoiceTypes() { /*--------------------------------------------------------------------------*/ +void SoundManager::saveNotifier(bool postFlag) { + _globals->_soundManager.saveNotifierProc(postFlag); +} + +void SoundManager::saveNotifierProc(bool postFlag) { + warning("TODO: SoundManager::saveNotifierProc"); +} + +void SoundManager::loadNotifier(bool postFlag) { + _globals->_soundManager.loadNotifierProc(postFlag); +} + +void SoundManager::loadNotifierProc(bool postFlag) { + warning("TODO: SoundManager::loadNotifierProc"); +} + +void SoundManager::listenerSynchronise(Serialiser &s) { + s.validate("SoundManager"); + warning("TODO: SoundManager listenerSynchronise"); +} + +/*--------------------------------------------------------------------------*/ + void SoundManager::_soSetTimeIndex(int timeIndex) { warning("TODO: _soSetTimeIndex"); } @@ -320,6 +440,18 @@ void SoundManager::_sfExtractGroupMask() { _globals->_soundManager._groupMask = mask; } +bool SoundManager::_sfInstallDriver(SoundDriver *driver) { + return false; +} + +void SoundManager::_sfUnInstallDriver(SoundDriver *driver) { + +} + +void SoundManager::_sfInstallPatchBank(const byte *bankData) { + +} + /*--------------------------------------------------------------------------*/ Sound::Sound() { |