[Scummvm-cvs-logs] scummvm master -> 39eab59388c6dc43d1f2c72ee708807ef1bdb198

Strangerke Strangerke at scummvm.org
Sat Dec 27 15:33:15 CET 2014


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
39eab59388 ACCESS: Rewrite sound queueing (WIP)


Commit: 39eab59388c6dc43d1f2c72ee708807ef1bdb198
    https://github.com/scummvm/scummvm/commit/39eab59388c6dc43d1f2c72ee708807ef1bdb198
Author: Strangerke (strangerke at scummvm.org)
Date: 2014-12-27T15:31:43+01:00

Commit Message:
ACCESS: Rewrite sound queueing (WIP)

Changed paths:
    engines/access/amazon/amazon_logic.cpp
    engines/access/events.cpp
    engines/access/sound.cpp
    engines/access/sound.h



diff --git a/engines/access/amazon/amazon_logic.cpp b/engines/access/amazon/amazon_logic.cpp
index 4a313e8..c045377 100644
--- a/engines/access/amazon/amazon_logic.cpp
+++ b/engines/access/amazon/amazon_logic.cpp
@@ -341,15 +341,12 @@ void Opening::doTitle() {
 		_vm->_objectsTable[0] = new SpriteResource(_vm, spriteData);
 		delete spriteData;
 
-		_vm->_sound->playSound(1);
-
 		_vm->_files->_setPaletteFlag = false;
 		_vm->_files->loadScreen(0, 4);
 		_vm->_sound->playSound(1);
 
 		_vm->_buffer2.copyFrom(*_vm->_screen);
 		_vm->_buffer1.copyFrom(*_vm->_screen);
-		_vm->_sound->playSound(1);
 
 		const int COUNTDOWN[6] = { 2, 0x80, 1, 0x7d, 0, 0x87 };
 		for (_pCount = 0; _pCount < 3 && !_vm->shouldQuit(); ++_pCount) {
@@ -508,40 +505,47 @@ void Opening::doTent() {
 	_vm->_screen->forceFadeIn();
 
 	_vm->_video->setVideo(_vm->_screen, Common::Point(126, 73), FileIdent(2, 1), 10);
+	int previousFrame = -1;
 	while (!_vm->shouldQuit() && !_vm->_video->_videoEnd) {
 		_vm->_video->playVideo();
-		if ((_vm->_video->_videoFrame == 32) || (_vm->_video->_videoFrame == 34))
-			_vm->_sound->playSound(4);
-		else if (_vm->_video->_videoFrame == 36) {
-			if (step != 2) {
-				_vm->_sound->playSound(2);
-				step = 2;
-			}
-		} else if (_vm->_video->_videoFrame == 18) {
-			if (step != 1) {
-				_vm->_midi->newMusic(73, 1);
-				_vm->_midi->newMusic(11, 0);
-				step = 1;
-				_vm->_sound->playSound(1);
+		if (previousFrame != _vm->_video->_videoFrame) {
+			previousFrame = _vm->_video->_videoFrame;
+
+			if ((_vm->_video->_videoFrame == 32) || (_vm->_video->_videoFrame == 34))
+				_vm->_sound->playSound(4);
+			else if (_vm->_video->_videoFrame == 36) {
+				if (step != 2) {
+					_vm->_sound->playSound(2);
+					step = 2;
+				}
+			} else if (_vm->_video->_videoFrame == 18) {
+				if (step != 1) {
+					_vm->_midi->newMusic(73, 1);
+					_vm->_midi->newMusic(11, 0);
+					step = 1;
+					_vm->_sound->playSound(1);
+				}
 			}
 		}
-
 		_vm->_events->pollEventsAndWait();
 	}
 
 	_vm->_sound->playSound(5);
 	_vm->_video->setVideo(_vm->_screen, Common::Point(43, 11), FileIdent(2, 2), 10);
+	previousFrame = -1;
 	while (!_vm->shouldQuit() && !_vm->_video->_videoEnd) {
 		_vm->_video->playVideo();
-		if (_vm->_video->_videoFrame == 26) {
-			_vm->_sound->playSound(5);
-		} else if (_vm->_video->_videoFrame == 15) {
-			if (step !=3) {
-				_vm->_sound->playSound(3);
-				step = 3;
+		if (previousFrame != _vm->_video->_videoFrame) {
+			previousFrame = _vm->_video->_videoFrame;
+			if (_vm->_video->_videoFrame == 26) {
+				_vm->_sound->playSound(5);
+			} else if (_vm->_video->_videoFrame == 15) {
+				if (step !=3) {
+					_vm->_sound->playSound(3);
+					step = 3;
+				}
 			}
 		}
-
 		_vm->_events->pollEventsAndWait();
 	}
 
diff --git a/engines/access/events.cpp b/engines/access/events.cpp
index 0867b09..6ffe67a 100644
--- a/engines/access/events.cpp
+++ b/engines/access/events.cpp
@@ -140,6 +140,8 @@ void EventsManager::pollEvents(bool skipTimers) {
 	if (checkForNextTimerUpdate() && !skipTimers)
 		nextTimer();
 
+	_vm->_sound->checkSoundQueue();
+
 	_wheelUp = _wheelDown = false;
 
 	Common::Event event;
diff --git a/engines/access/sound.cpp b/engines/access/sound.cpp
index a7d96da..82199a8 100644
--- a/engines/access/sound.cpp
+++ b/engines/access/sound.cpp
@@ -22,7 +22,6 @@
 
 #include "common/algorithm.h"
 #include "audio/mixer.h"
-#include "audio/audiostream.h"
 #include "audio/decoders/raw.h"
 #include "audio/decoders/wave.h"
 #include "access/access.h"
@@ -44,7 +43,19 @@ void SoundManager::clearSounds() {
 
 	for (uint i = 0; i < _soundTable.size(); ++i)
 		delete _soundTable[i]._res;
+
 	_soundTable.clear();
+
+	if (_mixer->isSoundHandleActive(_effectsHandle))
+		_mixer->stopHandle(_effectsHandle);
+
+	if (_queue.size())
+		_queue.remove_at(0);
+
+	while (_queue.size()) {
+		delete _queue[0];
+		_queue.remove_at(0);
+	}
 }
 
 void SoundManager::queueSound(int idx, int fileNum, int subfile) {
@@ -77,19 +88,14 @@ void SoundManager::playSound(Resource *res, int priority) {
 	debugC(1, kDebugSound, "playSound");
 
 	byte *resourceData = res->data();
-	Audio::SoundHandle audioHandle;
-	Audio::RewindableAudioStream *audioStream = 0;
 
 	assert(res->_size >= 32);
 
-	// HACK: Simulates queueing for the rare sounds played one after the other
-	while (_mixer->hasActiveChannelOfType(Audio::Mixer::kSFXSoundType))
-		;
-
 	if (READ_BE_UINT32(resourceData) == MKTAG('R','I','F','F')) {
 		// CD version uses WAVE-files
 		Common::SeekableReadStream *waveStream = new Common::MemoryReadStream(resourceData, res->_size, DisposeAfterUse::NO);
-		audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES);
+		Audio::RewindableAudioStream *audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES);
+		_queue.push_back(audioStream);
 
 	} else if (READ_BE_UINT32(resourceData) == MKTAG('S', 'T', 'E', 'V')) {
 		// sound files have a fixed header of 32 bytes in total
@@ -130,22 +136,30 @@ void SoundManager::playSound(Resource *res, int priority) {
 			return;
 		}
 
-		audioStream = Audio::makeRawStream(resourceData + 32, sampleSize, sampleRate, 0);
+		Audio::RewindableAudioStream *audioStream = Audio::makeRawStream(resourceData + 32, sampleSize, sampleRate, 0);
+		_queue.push_back(audioStream);
 
 	} else
 		error("Unknown format");
 
-	audioHandle = Audio::SoundHandle();
-	_mixer->playStream(Audio::Mixer::kSFXSoundType, &audioHandle,
-						audioStream, -1, _mixer->kMaxChannelVolume, 0,
+	if (!_mixer->isSoundHandleActive(_effectsHandle))
+		_mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle,
+						_queue[0], -1, _mixer->kMaxChannelVolume, 0,
 						DisposeAfterUse::NO);
+}
+
+void SoundManager::checkSoundQueue() {
+	debugC(5, kDebugSound, "checkSoundQueue");
+
+	if (_queue.empty() || _mixer->isSoundHandleActive(_effectsHandle))
+		return;
+
+	_queue.remove_at(0);
 
-	/*
-	Audio::QueuingAudioStream *audioStream = Audio::makeQueuingAudioStream(22050, false);
-	audioStream->queueBuffer(data, size, DisposeAfterUse::YES, 0);
-	_mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, audioStream, -1,
-		Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES, false);
-		*/
+	if (_queue.size())
+		_mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle,
+		   _queue[0], -1, _mixer->kMaxChannelVolume, 0,
+		   DisposeAfterUse::YES);
 }
 
 void SoundManager::loadSounds(Common::Array<RoomInfo::SoundIdent> &sounds) {
diff --git a/engines/access/sound.h b/engines/access/sound.h
index d0f4584..c276648 100644
--- a/engines/access/sound.h
+++ b/engines/access/sound.h
@@ -24,6 +24,7 @@
 #define ACCESS_SOUND_H
 
 #include "common/scummsys.h"
+#include "audio/audiostream.h"
 #include "audio/mixer.h"
 #include "access/files.h"
 #include "audio/midiplayer.h"
@@ -47,7 +48,8 @@ class SoundManager {
 private:
 	AccessEngine *_vm;
 	Audio::Mixer *_mixer;
-	Audio::SoundHandle _soundHandle;
+	Audio::SoundHandle _effectsHandle;
+	Common::Array<Audio::RewindableAudioStream *> _queue;
 
 	void clearSounds();
 
@@ -63,6 +65,7 @@ public:
 	void queueSound(int idx, int fileNum, int subfile);
 
 	void playSound(int soundIndex);
+	void checkSoundQueue();
 
 	Resource *loadSound(int fileNum, int subfile);
 	void loadSounds(Common::Array<RoomInfo::SoundIdent> &sounds);






More information about the Scummvm-git-logs mailing list