diff options
-rw-r--r-- | engines/tsage/sound.cpp | 168 | ||||
-rw-r--r-- | engines/tsage/sound.h | 60 |
2 files changed, 187 insertions, 41 deletions
diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp index 0db43506ea..834395e7da 100644 --- a/engines/tsage/sound.cpp +++ b/engines/tsage/sound.cpp @@ -33,10 +33,39 @@ namespace tSage { +SoundManager::SoundManager() { + __sndmgrReady = false; + _minVersion = 0x102; + _maxVersion = 0x10A; + + for (int i = 0; i < 16; ++i) + _field109[i] = 0; + + _groupMask = 0; + _volume = 127; + _suspendCtr = 0; + _disableCtr = 0; + _field153 = 0; + _field16D = 0; +} + +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); + _sfTerminate(); + } +} + void SoundManager::postInit() { - _saver->addSaveNotifier(&SoundManager::saveNotifier); - _saver->addLoadNotifier(&SoundManager::loadNotifier); - _saver->addListener(this); + if (!__sndmgrReady) { + _saver->addSaveNotifier(&SoundManager::saveNotifier); + _saver->addLoadNotifier(&SoundManager::loadNotifier); + _saver->addListener(this); + __sndmgrReady = true; + } } void SoundManager::saveNotifier(bool postFlag) { @@ -60,8 +89,6 @@ void SoundManager::listenerSynchronise(Serialiser &s) { warning("TODO: SoundManager listenerSynchronise"); } -/*--------------------------------------------------------------------------*/ - void SoundManager::checkResVersion(const byte *soundData) { int minVersion = READ_LE_UINT16(soundData + 4); int maxVersion = READ_LE_UINT16(soundData + 6); @@ -72,6 +99,57 @@ void SoundManager::checkResVersion(const byte *soundData) { error("Attempt to play/prime sound resource that is too old"); } +/*--------------------------------------------------------------------------*/ + +void SoundManager::suspendSoundServer() { + ++_globals->_soundManager._suspendCtr; +} + + +void SoundManager::restartSoundServer() { + if (_globals->_soundManager._suspendCtr > 0) + --_globals->_soundManager._suspendCtr; +} + +void SoundManager::unInstallDriver(SoundDriver *driver) { + +} + +Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool flag) { + assert(__sndmgrReady); + _driverList.clear(); + + warning("TODO: SoundManager::buildDriverList"); + return _driverList; +} + +Common::List<SoundDriverEntry> &SoundManager::getDriverList(bool flag) { + if (flag) + return _driverList; + else + return buildDriverList(false); +} + +void SoundManager::dumpDriverList() { + _driverList.clear(); +} + +void SoundManager::setMasterVol(int volume) { + _sfSetMasterVol(volume); +} + +int SoundManager::getMasterVol() const { + return _volume; +} + +void SoundManager::loadSound(int soundNum, bool showErrors) { + // This method preloaded the data associated with a given sound, so is now redundant +} + +void SoundManager::unloadSound(int soundNum) { + // This method signalled the resource manager to unload the data for a sound, and is now redundant +} + int SoundManager::determineGroup(const byte *soundData) { return _sfDetermineGroup(soundData); } @@ -84,6 +162,10 @@ int SoundManager::extractLoop(const byte *soundData) { return READ_LE_UINT16(soundData + 14); } +void SoundManager::extractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum) { + _sfExtractTrackInfo(trackInfo, soundData, groupNum); +} + void SoundManager::addToSoundList(Sound *sound) { if (!contains(_soundList, sound)) _soundList.push_back(sound); @@ -105,23 +187,6 @@ bool SoundManager::isOnPlayList(Sound *sound) { return _sfIsOnPlayList(sound); } -void SoundManager::extractTrackInfo(trackInfoStruct *data, const byte *soundData, int groupNum) { - -} - -void SoundManager::suspendSoundServer() { - ++_globals->_soundManager._suspendCtr; -} - -void SoundManager::rethinkVoiceTypes() { - _sfRethinkVoiceTypes(); -} - -void SoundManager::restartSoundServer() { - if (_globals->_soundManager._suspendCtr > 0) - --_globals->_soundManager._suspendCtr; -} - void SoundManager::updateSoundVol(Sound *sound) { _sfUpdateVolume(sound); } @@ -134,6 +199,10 @@ void SoundManager::updateSoundLoop(Sound *sound) { _sfUpdateLoop(sound); } +void SoundManager::rethinkVoiceTypes() { + _sfRethinkVoiceTypes(); +} + /*--------------------------------------------------------------------------*/ void SoundManager::_soSetTimeIndex(int timeIndex) { @@ -194,6 +263,51 @@ void SoundManager::_sfUpdateLoop(Sound *sound) { } +void SoundManager::_sfSetMasterVol(int volume) { + if (volume > 127) + volume = 127; + + if (volume != _globals->_soundManager._volume) { + _globals->_soundManager._volume = volume; + + for (Common::List<SoundDriver *>::iterator i = _globals->_soundManager._installedDrivers.begin(); + i != _globals->_soundManager._installedDrivers.end(); ++i) { + (*i)->setVolume(volume); + } + } +} + +void SoundManager::_sfExtractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum) { + trackInfo->count = 0; + + const byte *p = soundData + READ_LE_UINT16(soundData + 8); + uint32 v; + while ((v = READ_LE_UINT32(p)) != 0) { + while ((v == 0x80000000) || (v == (uint)groupNum)) { + int count = READ_LE_UINT16(p + 4); + p += 6; + + for (int idx = 0; idx < count; ++idx) { + if (trackInfo->count == 16) { + trackInfo->count = -1; + return; + } + + trackInfo->rlbList[trackInfo->count] = READ_LE_UINT16(p); + trackInfo->arr2[trackInfo->count] = READ_LE_UINT16(p + 2); + ++trackInfo->count; + p += 4; + } + } + + p = soundData + 6 + (READ_LE_UINT16(p + 4) * 4); + } +} + +void SoundManager::_sfTerminate() { + +} + /*--------------------------------------------------------------------------*/ Sound::Sound() { @@ -260,7 +374,7 @@ void Sound::_prime(int soundNum, bool queFlag) { _globals->_soundManager.extractTrackInfo(&_trackInfo, soundData, _groupNum); for (int idx = 0; idx < _trackInfo.count; ++idx) { - _trackInfo.handleList[idx] = _resourceManager->getResource(RES_SOUND, soundNum, _trackInfo.rlbList[idx]); + _handleList[idx] = _resourceManager->getResource(RES_SOUND, soundNum, _trackInfo.rlbList[idx]); } DEALLOCATE(soundData); @@ -270,7 +384,7 @@ void Sound::_prime(int soundNum, bool queFlag) { _soundPriority = 0; _loop = 0; _trackInfo.count = 0; - _trackInfo.handleList[0] = ALLOCATE(200); + _handleList[0] = ALLOCATE(200); _field26E = ALLOCATE(200); } @@ -283,12 +397,12 @@ void Sound::_prime(int soundNum, bool queFlag) { void Sound::_unPrime() { if (_primed) { if (_field26C) { - DEALLOCATE(_trackInfo.handleList[0]); + DEALLOCATE(_handleList[0]); DEALLOCATE(_field26E); _field26E = NULL; } else { for (int idx = 0; idx < _trackInfo.count; ++idx) { - DEALLOCATE(_trackInfo.handleList[idx]); + DEALLOCATE(_handleList[idx]); } } @@ -305,7 +419,7 @@ void Sound::orientAfterDriverChange() { int timeIndex = getTimeIndex(); for (int idx = 0; idx < _trackInfo.count; ++idx) - DEALLOCATE(_trackInfo.handleList[idx]); + DEALLOCATE(_handleList[idx]); _trackInfo.count = 0; _primed = false; diff --git a/engines/tsage/sound.h b/engines/tsage/sound.h index 20edd70292..b175da71c5 100644 --- a/engines/tsage/sound.h +++ b/engines/tsage/sound.h @@ -35,58 +35,90 @@ namespace tSage { class Sound; +#define SOUND_ARR_SIZE 16 + struct trackInfoStruct { int count; - int rlbList[32]; - byte *handleList[75]; + int rlbList[SOUND_ARR_SIZE]; + int arr2[SOUND_ARR_SIZE]; +}; + +class SoundDriverEntry { +public: + +}; + +class SoundDriver { +private: + Common::String _shortDescription, _longDescription; +public: + const Common::String &getShortDriverDescription() { return _shortDescription; } + const Common::String &getLongDriverDescription() { return _longDescription; } + + virtual void setVolume(int volume) = 0; }; class SoundManager : public SaveListener { +private: + void unInstallDriver(SoundDriver *driver); public: + bool __sndmgrReady; int _minVersion, _maxVersion; Common::List<Sound *> _playList; - void *driverList2[16]; - int _field89[16]; - int _fieldA9[16]; - int _fieldE9[16]; int _field109[16]; uint32 _groupMask; - int volume; + int _volume; int _disableCtr; int _suspendCtr; int _field153; Common::List<Sound *> _soundList; - Common::List<void *> _driverList; + Common::List<SoundDriverEntry> _driverList; + + Common::List<SoundDriver *> _installedDrivers; + int _field89[16]; + int _fieldA9[16]; + int _fieldE9[16]; + int _field16D; public: + SoundManager(); + ~SoundManager(); + void dispatch() {} virtual void listenerSynchronise(Serialiser &s); virtual void postInit(); - void proc2() {} static void saveNotifier(bool postFlag); void saveNotifierProc(bool postFlag); static void loadNotifier(bool postFlag); void loadNotifierProc(bool postFlag); + Common::List<SoundDriverEntry> &buildDriverList(bool flag); + Common::List<SoundDriverEntry> &getDriverList(bool flag); + void dumpDriverList(); void checkResVersion(const byte *soundData); int determineGroup(const byte *soundData); int extractPriority(const byte *soundData); int extractLoop(const byte *soundData); + bool isOnPlayList(Sound *sound); + void extractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum); void addToSoundList(Sound *sound); void removeFromSoundList(Sound *sound); void addToPlayList(Sound *sound); void removeFromPlayList(Sound *sound); - bool isOnPlayList(Sound *sound); - void extractTrackInfo(trackInfoStruct *data, const byte *soundData, int groupNum); void suspendSoundServer(); void rethinkVoiceTypes(); void restartSoundServer(); void updateSoundVol(Sound *sound); void updateSoundPri(Sound *sound); void updateSoundLoop(Sound *sound); + void setMasterVol(int volume); + int getMasterVol() const; + void loadSound(int soundNum, bool showErrors); + void unloadSound(int soundNum); // _so methods + static void _sfTerminate(); static void _soSetTimeIndex(int timeIndex); static int _sfDetermineGroup(const byte *soundData); static void _sfAddToPlayList(Sound *sound); @@ -98,11 +130,10 @@ public: static void sub_233EE(Sound *sound); static void _sfUpdatePriority(Sound *sound); static void _sfUpdateLoop(Sound *sound); - + static void _sfSetMasterVol(int volume); + static void _sfExtractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum); }; -#define SOUND_ARR_SIZE 16 - class Sound: public EventHandler { private: void _prime(int soundNum, bool queFlag); @@ -143,6 +174,7 @@ public: int _fieldC8[SOUND_ARR_SIZE]; int _fieldE8[SOUND_ARR_SIZE]; trackInfoStruct _trackInfo; + byte *_handleList[75]; int _field266; int _field268; bool _primed; |