[Scummvm-cvs-logs] SF.net SVN: scummvm: [28071] scummvm/trunk/engines/saga/music.cpp

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sat Jul 14 17:06:06 CEST 2007


Revision: 28071
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28071&view=rev
Author:   thebluegr
Date:     2007-07-14 08:06:06 -0700 (Sat, 14 Jul 2007)

Log Message:
-----------
Some more updates for looping of compressed digital music. It's still not working, though

Modified Paths:
--------------
    scummvm/trunk/engines/saga/music.cpp

Modified: scummvm/trunk/engines/saga/music.cpp
===================================================================
--- scummvm/trunk/engines/saga/music.cpp	2007-07-14 14:18:45 UTC (rev 28070)
+++ scummvm/trunk/engines/saga/music.cpp	2007-07-14 15:06:06 UTC (rev 28071)
@@ -42,6 +42,8 @@
 private:
 	Audio::AudioStream *_stream;
 	ResourceContext *_context;
+	ResourceData * resourceData;
+	GameSoundTypes soundType;
 	Common::File *_file;
 	uint32 _filePos;
 	uint32 _startPos;
@@ -62,6 +64,8 @@
 	DigitalMusicInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping, uint32 loopStart);
 	~DigitalMusicInputStream();
 
+	void DigitalMusicInputStream::createCompressedStream();
+
 	int readBuffer(int16 *buffer, const int numSamples);
 
 	bool endOfData() const	{ return eosIntern(); }
@@ -72,9 +76,7 @@
 DigitalMusicInputStream::DigitalMusicInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping, uint32 loopStart)
 	: _context(context), _finished(false), _looping(looping), _bufferEnd(_buf + BUFFER_SIZE) {
 
-	ResourceData * resourceData;
 	byte compressedHeader[10];
-	GameSoundTypes soundType;
 
 	resourceData = vm->_resource->getResourceData(context, resourceId);
 	_file = context->getFile(resourceData);
@@ -99,31 +101,7 @@
 			soundType = kSoundFLAC;
 		}
 
-		switch (soundType) {
-#ifdef USE_MAD
-			case kSoundMP3:
-				debug(1, "Playing MP3 compressed digital music");
-				_stream = Audio::makeMP3Stream(_file, resourceData->size);
-				break;
-#endif
-#ifdef USE_VORBIS
-			case kSoundOGG:
-				debug(1, "Playing OGG compressed digital music");
-				_stream = Audio::makeVorbisStream(_file, resourceData->size);
-				break;
-#endif
-#ifdef USE_FLAC
-			case kSoundFLAC:
-				debug(1, "Playing FLAC compressed digital music");
-				_stream = Audio::makeFlacStream(_file, resourceData->size);
-				break;
-#endif
-			default:
-				// Unknown compression
-				error("Trying to play a compressed digital music, but the compression is not known");
-				break;
-		}
-
+		createCompressedStream();
 		resourceData->offset += 9;	// Skip compressed header
 	}
 
@@ -142,26 +120,61 @@
 	delete _stream;
 }
 
+void DigitalMusicInputStream::createCompressedStream() {
+	switch (soundType) {
+#ifdef USE_MAD
+		case kSoundMP3:
+			debug(1, "Playing MP3 compressed digital music");
+			_stream = Audio::makeMP3Stream(_file, resourceData->size);
+			break;
+#endif
+#ifdef USE_VORBIS
+		case kSoundOGG:
+			debug(1, "Playing OGG compressed digital music");
+			_stream = Audio::makeVorbisStream(_file, resourceData->size);
+			break;
+#endif
+#ifdef USE_FLAC
+		case kSoundFLAC:
+			debug(1, "Playing FLAC compressed digital music");
+			_stream = Audio::makeFlacStream(_file, resourceData->size);
+			break;
+#endif
+		default:
+			// Unknown compression
+			error("Trying to play a compressed digital music, but the compression is not known");
+			break;
+	}
+}
+
 int DigitalMusicInputStream::readBuffer(int16 *buffer, const int numSamples) {
-	// TODO/FIXME: Add looping support for compressed digital music
-	//if (!_looping && _stream != NULL)
-	if (_stream != NULL)
+	// TODO/FIXME: Add looping support for compressed digital music - remove this once it's done
+	// Currently, an illegal read is made, leading to a crash. Therefore, it's disabled for now
+	if (_stream != NULL) _looping = false;
+
+	if (!_looping && _stream != NULL)
 		return _stream->readBuffer(buffer, numSamples);
 
 	int samples = 0;
 	while (samples < numSamples && !eosIntern()) {
 		int len = 0;
-		if (_stream != NULL)
+		if (_stream != NULL) {
 			len = _stream->readBuffer(buffer, numSamples);
-		else
+			if (len < numSamples) {
+				delete _stream;
+				createCompressedStream();
+				//_file->seek(_startPos, SEEK_SET);
+				//_pos = 0;
+			}
+		} else {
 			len = MIN(numSamples - samples, (int) (_bufferEnd - _pos));
-		memcpy(buffer, _pos, len * 2);
+			memcpy(buffer, _pos, len * 2);
+		}
 		buffer += len;
 		_pos += len;
 		samples += len;
-		if (_pos >= _bufferEnd) {
+		if (_pos >= _bufferEnd)
 			refill();
-		}
 	}
 	return samples;
 }


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