aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2007-04-14 17:12:43 +0000
committerMax Horn2007-04-14 17:12:43 +0000
commit8f5abc1924d5d7bdbc9684b870394f93ad80d2ff (patch)
tree580ffe06c99409b42a785c45ba6494a37da1e264 /sound
parent29523e901756172d112de2cc9514373baa0be80c (diff)
downloadscummvm-rg350-8f5abc1924d5d7bdbc9684b870394f93ad80d2ff.tar.gz
scummvm-rg350-8f5abc1924d5d7bdbc9684b870394f93ad80d2ff.tar.bz2
scummvm-rg350-8f5abc1924d5d7bdbc9684b870394f93ad80d2ff.zip
Extended Audio::openStreamFile function with startTime, duration and numLoops parameters, and slightly cleaned up its code
svn-id: r26471
Diffstat (limited to 'sound')
-rw-r--r--sound/audiostream.cpp27
-rw-r--r--sound/audiostream.h7
2 files changed, 15 insertions, 19 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 90b7bcb26b..8b92f4f30e 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -59,36 +59,29 @@ struct StreamFileFormat {
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 @@ AudioStream* AudioStream::openStreamFile(const char *filename) {
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;
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 9cd8113147..7536588894 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -83,11 +83,14 @@ public:
* 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);
};
/**