[Scummvm-cvs-logs] SF.net SVN: scummvm:[45655] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Wed Nov 4 11:20:28 CET 2009


Revision: 45655
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45655&view=rev
Author:   thebluegr
Date:     2009-11-04 10:20:25 +0000 (Wed, 04 Nov 2009)

Log Message:
-----------
Moved the sound sync code inside the AudioPlayer class

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/ksound.cpp
    scummvm/trunk/engines/sci/sfx/audio.cpp
    scummvm/trunk/engines/sci/sfx/audio.h

Modified: scummvm/trunk/engines/sci/engine/ksound.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/ksound.cpp	2009-11-04 09:49:28 UTC (rev 45654)
+++ scummvm/trunk/engines/sci/engine/ksound.cpp	2009-11-04 10:20:25 UTC (rev 45655)
@@ -1189,10 +1189,7 @@
 	case kSciAudioSyncStart: {
 		ResourceId id;
 
-		if (s->_audio->_syncResource) {
-			s->resMan->unlockResource(s->_audio->_syncResource);
-			s->_audio->_syncResource = NULL;
-		}
+		s->_audio->stopSoundSync();
 
 		// Load sound sync resource and lock it
 		if (argc == 3) {
@@ -1205,41 +1202,14 @@
 			return s->r_acc;
 		}
 
-		s->_audio->_syncResource = s->resMan->findResource(id, 1);
-
-		if (s->_audio->_syncResource) {
-			PUT_SEL32V(segMan, argv[1], syncCue, 0);
-			s->_audio->_syncOffset = 0;
-		} else {
-			warning("DoSync: failed to find resource %s", id.toString().c_str());
-			// Notify the scripts to stop sound sync
-			PUT_SEL32V(segMan, argv[1], syncCue, SIGNAL_OFFSET);
-		}
+		s->_audio->setSoundSync(id, argv[1], segMan);
 		break;
 	}
-	case kSciAudioSyncNext: {
-		Resource *res = s->_audio->_syncResource;
-		if (res && (s->_audio->_syncOffset < res->size - 1)) {
-			int16 syncCue = -1;
-			int16 syncTime = (int16)READ_LE_UINT16(res->data + s->_audio->_syncOffset);
-
-			s->_audio->_syncOffset += 2;
-
-			if ((syncTime != -1) && (s->_audio->_syncOffset < res->size - 1)) {
-				syncCue = (int16)READ_LE_UINT16(res->data + s->_audio->_syncOffset);
-				s->_audio->_syncOffset += 2;
-			}
-
-			PUT_SEL32V(segMan, argv[1], syncTime, syncTime);
-			PUT_SEL32V(segMan, argv[1], syncCue, syncCue);
-		}
+	case kSciAudioSyncNext: 
+		s->_audio->doSoundSync(argv[1], segMan);
 		break;
-	}
 	case kSciAudioSyncStop:
-		if (s->_audio->_syncResource) {
-			s->resMan->unlockResource(s->_audio->_syncResource);
-			s->_audio->_syncResource = NULL;
-		}
+		s->_audio->stopSoundSync();
 		break;
 	default:
 		warning("DoSync: Unhandled subfunction %d", argv[0].toUint16());

Modified: scummvm/trunk/engines/sci/sfx/audio.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/audio.cpp	2009-11-04 09:49:28 UTC (rev 45654)
+++ scummvm/trunk/engines/sci/sfx/audio.cpp	2009-11-04 10:20:25 UTC (rev 45655)
@@ -24,6 +24,8 @@
  */
 
 #include "sci/resource.h"
+#include "sci/engine/kernel.h"
+#include "sci/engine/seg_manager.h"
 #include "sci/sfx/audio.h"
 
 #include "common/system.h"
@@ -38,10 +40,8 @@
 }
 
 AudioPlayer::~AudioPlayer() {
+	stopSoundSync();
 	stopAudio();
-
-	if (_syncResource)
-		_resMan->unlockResource(_syncResource);
 }
 
 int AudioPlayer::startAudio(uint16 module, uint32 number) {
@@ -224,4 +224,41 @@
 	return NULL;
 }
 
+void AudioPlayer::setSoundSync(ResourceId id, reg_t syncObjAddr, SegManager *segMan) {
+	_syncResource = _resMan->findResource(id, 1);
+	_syncOffset = 0;
+
+	if (_syncResource) {
+		PUT_SEL32V(segMan, syncObjAddr, syncCue, 0);
+	} else {
+		warning("setSoundSync: failed to find resource %s", id.toString().c_str());
+		// Notify the scripts to stop sound sync
+		PUT_SEL32V(segMan, syncObjAddr, syncCue, SIGNAL_OFFSET);
+	}
+}
+
+void AudioPlayer::doSoundSync(reg_t syncObjAddr, SegManager *segMan) {
+	if (_syncResource && (_syncOffset < _syncResource->size - 1)) {
+		int16 syncCue = -1;
+		int16 syncTime = (int16)READ_LE_UINT16(_syncResource->data + _syncOffset);
+
+		_syncOffset += 2;
+
+		if ((syncTime != -1) && (_syncOffset < _syncResource->size - 1)) {
+			syncCue = (int16)READ_LE_UINT16(_syncResource->data + _syncOffset);
+			_syncOffset += 2;
+		}
+
+		PUT_SEL32V(segMan, syncObjAddr, syncTime, syncTime);
+		PUT_SEL32V(segMan, syncObjAddr, syncCue, syncCue);
+	}
+}
+
+void AudioPlayer::stopSoundSync() {
+	if (_syncResource) {
+		_resMan->unlockResource(_syncResource);
+		_syncResource = NULL;
+	}
+}
+
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/sfx/audio.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/audio.h	2009-11-04 09:49:28 UTC (rev 45654)
+++ scummvm/trunk/engines/sci/sfx/audio.h	2009-11-04 10:20:25 UTC (rev 45655)
@@ -30,6 +30,7 @@
 namespace Sci {
 
 class ResourceManager;
+class SegManager;
 
 class AudioPlayer {
 public:
@@ -44,14 +45,17 @@
 	void pauseAudio() { g_system->getMixer()->pauseHandle(_audioHandle, true); }
 	void resumeAudio() { g_system->getMixer()->pauseHandle(_audioHandle, false); }
 
-	Resource *_syncResource; /**< Used by kDoSync for speech syncing in CD talkie games */
-	uint _syncOffset;
+	void setSoundSync(ResourceId id, reg_t syncObjAddr, SegManager *segMan);
+	void doSoundSync(reg_t syncObjAddr, SegManager *segMan);
+	void stopSoundSync();
 
 private:
 	ResourceManager *_resMan;
 	uint16 _audioRate;
 	Audio::SoundHandle _audioHandle;
 	Audio::AudioStream* getAudioStream(uint32 number, uint32 volume, int *sampleLen);
+	Resource *_syncResource; /**< Used by kDoSync for speech syncing in CD talkie games */
+	uint _syncOffset;
 };
 
 } // End of namespace Sci


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list