[Scummvm-cvs-logs] SF.net SVN: scummvm: [26471] scummvm/trunk/sound

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Apr 14 19:12:45 CEST 2007


Revision: 26471
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26471&view=rev
Author:   fingolfin
Date:     2007-04-14 10:12:43 -0700 (Sat, 14 Apr 2007)

Log Message:
-----------
Extended Audio::openStreamFile function with startTime, duration and numLoops parameters, and slightly cleaned up its code

Modified Paths:
--------------
    scummvm/trunk/sound/audiostream.cpp
    scummvm/trunk/sound/audiostream.h

Modified: scummvm/trunk/sound/audiostream.cpp
===================================================================
--- scummvm/trunk/sound/audiostream.cpp	2007-04-14 15:13:45 UTC (rev 26470)
+++ scummvm/trunk/sound/audiostream.cpp	2007-04-14 17:12:43 UTC (rev 26471)
@@ -59,36 +59,29 @@
 static const StreamFileFormat STREAM_FILEFORMATS[] = {
 	/* decoderName,		fileExt, openStreamFuntion */
 #ifdef USE_FLAC
-	{ "Flac",			"flac", makeFlacStream },
-	{ "Flac",			"fla",  makeFlacStream },
+	{ "Flac",			".flac", makeFlacStream },
+	{ "Flac",			".fla",  makeFlacStream },
 #endif
 #ifdef USE_VORBIS
-	{ "Ogg Vorbis",		"ogg",  makeVorbisStream },
+	{ "Ogg Vorbis",		".ogg",  makeVorbisStream },
 #endif
 #ifdef USE_MAD
-	{ "MPEG Layer 3",	"mp3",  makeMP3Stream },
+	{ "MPEG Layer 3",	".mp3",  makeMP3Stream },
 #endif
 
 	{ NULL, NULL, NULL } // Terminator
 };
 
-AudioStream* AudioStream::openStreamFile(const char *filename) {
-	char buffer[1024];
-	const uint len = strlen(filename);
-	assert(len+6 < sizeof(buffer)); // we need a bigger buffer if wrong
-
-	memcpy(buffer, filename, len);
-	buffer[len] = '.';
-	char *ext = &buffer[len+1];
-
+AudioStream* AudioStream::openStreamFile(const Common::String &basename, uint32 startTime, uint32 duration, uint numLoops) {
 	AudioStream* stream = NULL;
 	Common::File *fileHandle = new Common::File();
 
 	for (int i = 0; i < ARRAYSIZE(STREAM_FILEFORMATS)-1 && stream == NULL; ++i) {
-		strcpy(ext, STREAM_FILEFORMATS[i].fileExtension);
-		fileHandle->open(buffer);
+		Common::String filename = basename + STREAM_FILEFORMATS[i].fileExtension;
+		fileHandle->open(filename);
 		if (fileHandle->isOpen()) {
-			stream = STREAM_FILEFORMATS[i].openStreamFile(fileHandle, true, 0, 0, 1);
+			// Create the stream object
+			stream = STREAM_FILEFORMATS[i].openStreamFile(fileHandle, true, startTime, duration, numLoops);
 			fileHandle = 0;
 			break;
 		}
@@ -97,7 +90,7 @@
 	delete fileHandle;
 
 	if (stream == NULL) {
-		debug(1, "AudioStream: Could not open compressed AudioFile %s", filename);
+		debug(1, "AudioStream: Could not open compressed AudioFile %s", basename.c_str());
 	}
 
 	return stream;

Modified: scummvm/trunk/sound/audiostream.h
===================================================================
--- scummvm/trunk/sound/audiostream.h	2007-04-14 15:13:45 UTC (rev 26470)
+++ scummvm/trunk/sound/audiostream.h	2007-04-14 17:12:43 UTC (rev 26471)
@@ -83,11 +83,14 @@
 	 * Tries to load a file by trying all available formats.
 	 * In case of an error, the file handle will be closed, but deleting
 	 * it is still the responsibilty of the caller.
-	 * @param filename	a filename without an extension
+	 * @param basename	a filename without an extension
+	 * @param startTime	the (optional) time offset in milliseconds from which to start playback 
+	 * @param duration	the (optional) time in milliseconds specifying how long to play
+	 * @param numLoops	how often the data shall be looped (0 = infinite)
 	 * @return	an Audiostream ready to use in case of success;
 	 *			NULL in case of an error (e.g. invalid/nonexisting file)
 	 */
-	static AudioStream* openStreamFile(const char *filename);
+	static AudioStream* openStreamFile(const Common::String &basename, uint32 startTime = 0, uint32 duration = 0, uint numLoops = 1);
 };
 
 /**


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