[Scummvm-cvs-logs] SF.net SVN: scummvm: [31598] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Apr 20 16:36:39 CEST 2008


Revision: 31598
          http://scummvm.svn.sourceforge.net/scummvm/?rev=31598&view=rev
Author:   lordhoto
Date:     2008-04-20 07:36:39 -0700 (Sun, 20 Apr 2008)

Log Message:
-----------
Improved sound priority handling.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/kyra_v3.cpp
    scummvm/trunk/engines/kyra/sound.h
    scummvm/trunk/engines/kyra/sound_digital.cpp

Modified: scummvm/trunk/engines/kyra/kyra_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra_v3.cpp	2008-04-20 14:25:37 UTC (rev 31597)
+++ scummvm/trunk/engines/kyra/kyra_v3.cpp	2008-04-20 14:36:39 UTC (rev 31598)
@@ -331,9 +331,7 @@
 	if (_soundDigital->isPlaying(_musicSoundChannel))
 		return;
 
-	Common::SeekableReadStream *stream = _res->getFileStream(_menuAudioFile);
-	if (stream)
-		_musicSoundChannel = _soundDigital->playSound(stream, 0xFF, SoundDigital::kSoundTypeMusic);
+	_musicSoundChannel = _soundDigital->playSound(_menuAudioFile, 0xFF, SoundDigital::kSoundTypeMusic);
 }
 
 void KyraEngine_v3::playMusicTrack(int track, int force) {
@@ -354,9 +352,7 @@
 	if (_musicSoundChannel == -1) {
 		assert(track < _soundListSize && track >= 0);
 
-		Common::SeekableReadStream *stream = _res->getFileStream(_soundList[track]);
-		if (stream)
-			_musicSoundChannel = _soundDigital->playSound(stream, 0xFF, SoundDigital::kSoundTypeMusic);
+		_musicSoundChannel = _soundDigital->playSound(_soundList[track], 0xFF, SoundDigital::kSoundTypeMusic);
 	}
 
 	_curMusicTrack = track;
@@ -415,9 +411,7 @@
 		snprintf(filename, 16, "%s.AUD", _sfxFileList[_sfxFileMap[item*2+0]]);
 		uint8 priority = _sfxFileMap[item*2+1];
 
-		Common::SeekableReadStream *stream = _res->getFileStream(filename);
-		if (stream)
-			_soundDigital->playSound(stream, priority, SoundDigital::kSoundTypeSfx, volume);
+		_soundDigital->playSound(filename, priority, SoundDigital::kSoundTypeSfx, volume);
 	}
 }
 
@@ -431,10 +425,7 @@
 	char filename[16];
 	snprintf(filename, 16, "%u.AUD", (uint)file);
 
-	Common::SeekableReadStream *stream = _res->getFileStream(filename);
-	if (stream) {
-		_voiceSoundChannel = _soundDigital->playSound(stream, 0xFE, SoundDigital::kSoundTypeSpeech, 255);
-	}
+	_voiceSoundChannel = _soundDigital->playSound(filename, 0xFE, SoundDigital::kSoundTypeSpeech, 255);
 }
 
 bool KyraEngine_v3::snd_voiceIsPlaying() {

Modified: scummvm/trunk/engines/kyra/sound.h
===================================================================
--- scummvm/trunk/engines/kyra/sound.h	2008-04-20 14:25:37 UTC (rev 31597)
+++ scummvm/trunk/engines/kyra/sound.h	2008-04-20 14:36:39 UTC (rev 31598)
@@ -513,8 +513,7 @@
 	/**
 	 * Plays a sound.
 	 *
-	 * @param stream		Data stream used for playback
-	 *                      It will be deleted when playback is finished
+	 * @param filename		file to be played
 	 * @param priority		priority of the sound
 	 * @param type			type
 	 * @param volume		channel volume
@@ -523,7 +522,7 @@
 	 *
 	 * @return channel playing the sound
 	 */
-	int playSound(Common::SeekableReadStream *stream, uint8 priority, kSoundTypes type, int volume = 255, bool loop = false, int channel = -1);
+	int playSound(const char *filename, uint8 priority, kSoundTypes type, int volume = 255, bool loop = false, int channel = -1);
 
 	/**
 	 * Checks if a given channel is playing a sound.
@@ -560,6 +559,8 @@
 
 	struct Sound {
 		Audio::SoundHandle handle;
+
+		char filename[16];
 		uint8 priority;
 		AUDStream *stream;
 	} _sounds[4];

Modified: scummvm/trunk/engines/kyra/sound_digital.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sound_digital.cpp	2008-04-20 14:25:37 UTC (rev 31597)
+++ scummvm/trunk/engines/kyra/sound_digital.cpp	2008-04-20 14:36:39 UTC (rev 31598)
@@ -24,6 +24,7 @@
  */
 
 #include "kyra/sound.h"
+#include "kyra/resource.h"
 
 #include "sound/audiostream.h"
 
@@ -328,13 +329,13 @@
 		stopSound(i);
 }
 
-int SoundDigital::playSound(Common::SeekableReadStream *stream, uint8 priority, kSoundTypes type, int volume, bool loop, int channel) {
+int SoundDigital::playSound(const char *filename, uint8 priority, kSoundTypes type, int volume, bool loop, int channel) {
 	Sound *use = 0;
 	if (channel != -1 && channel < ARRAYSIZE(_sounds)) {
 		stopSound(channel);
 		use = &_sounds[channel];
 	} else {
-		for (channel = 0; channel < ARRAYSIZE(_sounds); ++channel) {
+		for (channel = 0; !use && channel < ARRAYSIZE(_sounds); ++channel) {
 			if (!isPlaying(channel)) {
 				stopSound(channel);
 				use = &_sounds[channel];
@@ -342,23 +343,33 @@
 			}
 		}
 
-		if (!use) {
-			for (channel = 0; channel < ARRAYSIZE(_sounds); ++channel) {
-				if (_sounds[channel].priority <= priority) {
-					stopSound(channel);
-					use = &_sounds[channel];
-					break;
-				}
+		for (channel = 0; !use && channel < ARRAYSIZE(_sounds); ++channel) {
+			if (strcmp(_sounds[channel].filename, filename) == 0) {
+				stopSound(channel);
+				use = &_sounds[channel];
+				break;
 			}
+		}
 
-			if (!use) {
-				warning("no free sound channel");
-				delete stream;
-				return -1;
+		for (channel = 0; !use && channel < ARRAYSIZE(_sounds); ++channel) {
+			if (_sounds[channel].priority <= priority) {
+				stopSound(channel);
+				use = &_sounds[channel];
+				break;
 			}
 		}
+
+		if (!use) {
+			warning("no free sound channel");
+			return -1;
+		}
 	}
 
+	Common::SeekableReadStream *stream = _vm->resource()->getFileStream(filename);
+	if (!stream)
+		return -1;
+
+	strncpy(use->filename, filename, sizeof(use->filename));
 	use->priority = priority;
 	use->stream = new AUDStream(stream, loop);
 	if (use->stream->endOfData()) {


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