[Scummvm-cvs-logs] SF.net SVN: scummvm:[48133] scummvm/trunk/engines/mohawk

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Fri Feb 26 09:11:45 CET 2010


Revision: 48133
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48133&view=rev
Author:   mthreepwood
Date:     2010-02-26 08:11:45 +0000 (Fri, 26 Feb 2010)

Log Message:
-----------
Cleanup the sound code a bit.

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/sound.cpp
    scummvm/trunk/engines/mohawk/sound.h

Modified: scummvm/trunk/engines/mohawk/sound.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/sound.cpp	2010-02-26 07:37:35 UTC (rev 48132)
+++ scummvm/trunk/engines/mohawk/sound.cpp	2010-02-26 08:11:45 UTC (rev 48133)
@@ -338,27 +338,23 @@
 }
 
 Audio::AudioStream *Sound::makeMohawkWaveStream(Common::SeekableReadStream *stream) {
-	bool foundData = false;
 	uint32 tag = 0;
 	ADPC_Chunk adpc;
 	Cue_Chunk cue;
 	Data_Chunk data_chunk;
+	uint32 dataSize = 0;
 
 	memset(&data_chunk, 0, sizeof(Data_Chunk));
 
-	if (stream->readUint32BE() == ID_MHWK) // MHWK tag again
-		debug(2, "Found Tag MHWK");
-	else
+	if (stream->readUint32BE() != ID_MHWK) // MHWK tag again
 		error ("Could not find tag \'MHWK\'");
 
 	stream->readUint32BE(); // Skip size
 
-	if (stream->readUint32BE() == ID_WAVE)
-		debug(2, "Found Tag WAVE");
-	else
+	if (stream->readUint32BE() != ID_WAVE)
 		error ("Could not find tag \'WAVE\'");
 
-	while (!foundData) {
+	while (!data_chunk.audio_data) {
 		tag = stream->readUint32BE();
 
 		switch (tag) {
@@ -424,7 +420,7 @@
 			debug(2, "Found Tag DATA");
 			// We subtract 20 from the actual chunk size, which is the total size
 			// of the chunk's header
-			data_chunk.size = stream->readUint32BE() - 20;
+			dataSize = stream->readUint32BE() - 20;
 			data_chunk.sample_rate = stream->readUint16BE();
 			data_chunk.sample_count = stream->readUint32BE();
 			data_chunk.bitsPerSample = stream->readByte();
@@ -440,9 +436,7 @@
 			// therefore does not contain any of this metadata and we have to specify whether
 			// or not to loop elsewhere.
 
-			data_chunk.audio_data = (byte *)malloc(data_chunk.size);
-			stream->read(data_chunk.audio_data, data_chunk.size);
-			foundData = true;
+			data_chunk.audio_data = stream->readStream(dataSize);
 			break;
 		default:
 			error ("Unknown tag found in 'tWAV' chunk -- \'%s\'", tag2str(tag));
@@ -461,15 +455,13 @@
 		if (data_chunk.channels == 2)
 			flags |= Audio::FLAG_STEREO;
 
-		return Audio::makeRawStream(data_chunk.audio_data, data_chunk.size, data_chunk.sample_rate, flags);
+		return Audio::makeRawStream(data_chunk.audio_data, data_chunk.sample_rate, flags);
 	} else if (data_chunk.encoding == kCodecADPCM) {
-		Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES);
 		uint32 blockAlign = data_chunk.channels * data_chunk.bitsPerSample / 8;
-		return Audio::makeADPCMStream(dataStream, DisposeAfterUse::YES, data_chunk.size, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign);
+		return Audio::makeADPCMStream(data_chunk.audio_data, DisposeAfterUse::YES, dataSize, Audio::kADPCMIma, data_chunk.sample_rate, data_chunk.channels, blockAlign);
 	} else if (data_chunk.encoding == kCodecMPEG2) {
 #ifdef USE_MAD
-		Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(data_chunk.audio_data, data_chunk.size, DisposeAfterUse::YES);
-		return Audio::makeMP3Stream(dataStream, DisposeAfterUse::YES);
+		return Audio::makeMP3Stream(data_chunk.audio_data, DisposeAfterUse::YES);
 #else
 		warning ("MAD library not included - unable to play MP2 audio");
 #endif
@@ -496,12 +488,10 @@
 	} else
 		error("Could not find Old Mohawk Sound header");
 
-	assert(size);
-	byte *data = (byte *)malloc(size);
-	stream->read(data, size);
+	Common::SeekableReadStream *dataStream = stream->readStream(size);
 	delete stream;
 
-	return Audio::makeRawStream(data, size, rate, Audio::FLAG_UNSIGNED);
+	return Audio::makeRawStream(dataStream, rate, Audio::FLAG_UNSIGNED);
 }
 
 SndHandle *Sound::getHandle() {

Modified: scummvm/trunk/engines/mohawk/sound.h
===================================================================
--- scummvm/trunk/engines/mohawk/sound.h	2010-02-26 07:37:35 UTC (rev 48132)
+++ scummvm/trunk/engines/mohawk/sound.h	2010-02-26 08:11:45 UTC (rev 48133)
@@ -46,15 +46,15 @@
 struct SLSTRecord {
 	uint16 index;
 	uint16 sound_count;
-	uint16* sound_ids;
+	uint16 *sound_ids;
 	uint16 fade_flags;
 	uint16 loop;
 	uint16 global_volume;
 	uint16 u0;
 	uint16 u1;
-	uint16* volumes;
-	int16* balances;
-	uint16* u2;
+	uint16 *volumes;
+	int16 *balances;
+	uint16 *u2;
 };
 
 enum SndHandleType {
@@ -100,7 +100,6 @@
 };
 
 struct Data_Chunk {
-	uint32 size;
 	uint16 sample_rate;
 	uint32 sample_count;
 	byte bitsPerSample;
@@ -109,7 +108,7 @@
 	uint16 loop;
 	uint32 loopStart;
 	uint32 loopEnd;
-	byte* audio_data;
+	Common::SeekableReadStream *audio_data;
 };
 
 class MohawkEngine;


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