[Scummvm-cvs-logs] CVS: scummvm/sword2/driver d_sound.cpp,1.103,1.104 d_sound.h,1.42,1.43

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Fri Jan 16 00:17:00 CET 2004


Update of /cvsroot/scummvm/scummvm/sword2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv4178

Modified Files:
	d_sound.cpp d_sound.h 
Log Message:
Made a separate function out of the code that retrieves information about
an in-memory WAV file. At the moment it's only used in one place, which is
a bit silly, but I hope to use it for the cutscene player to figure out
when to start the lead-out music.

(To do that I'll need to know how long the cutscene is, though. I haven't
looked into how to find that out yet.)


Index: d_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_sound.cpp,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- d_sound.cpp	14 Jan 2004 18:33:30 -0000	1.103
+++ d_sound.cpp	16 Jan 2004 08:16:23 -0000	1.104
@@ -243,6 +243,44 @@
 }
 
 /**
+ * Retrieve information about an in-memory WAV file.
+ * @param data The WAV data
+ * @param wavInfo Pointer to the WavInfo structure to fill with information.
+ * @return True if the data appears to be a WAV file, otherwise false.
+ */
+
+bool Sound::getWavInfo(uint8 *data, WavInfo *wavInfo) {
+	if (READ_UINT32(data) != MKID('RIFF')) {
+		warning("getWavInfo: No 'RIFF' header");
+		return false;
+	}
+
+	if (READ_UINT32(data + 8) != MKID('WAVE')) {
+		warning("getWavInfo: No 'WAVE' header");
+		return false;
+	}
+
+	if (READ_UINT32(data + 12) != MKID('fmt ')) {
+		warning("getWavInfo: No 'fmt' header");
+		return false;
+	}
+
+	wavInfo->channels = READ_LE_UINT16(data + 22);
+	wavInfo->rate = READ_LE_UINT16(data + 24);
+
+	data += READ_LE_UINT32(data + 16) + 20;
+
+	if (READ_UINT32(data) != MKID('data')) {
+		warning("getWavInfo: No 'data' header");
+		return false;
+	}
+
+	wavInfo->samples = READ_LE_UINT32(data + 4);
+	wavInfo->data = data + 8;
+	return true;
+}
+
+/**
  * Mutes/Unmutes the music.
  * @param mute If mute is false, restore the volume to the last set master
  * level. Otherwise the music is muted (volume 0).
@@ -1026,32 +1064,26 @@
 		}
 	}
 
-	if (READ_UINT32(data) != MKID('RIFF') || READ_UINT32(data + 8) != MKID('WAVE') || READ_UINT32(data + 12) != MKID('fmt ')) {
-		warning("openFx: Not a valid WAV file");
-		return RDERR_INVALIDWAV;
-	}
-
 	_fx[fxi]._id = id;
 	_fx[fxi]._flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_LITTLE_ENDIAN;
 
-	if (READ_LE_UINT16(data + 22) == 2)
-		_fx[fxi]._flags |= SoundMixer::FLAG_STEREO;
-
-	_fx[fxi]._rate = READ_LE_UINT16(data + 24);
-
-	data += READ_LE_UINT32(data + 16) + 20;
+	WavInfo wavInfo;
 
-	if (READ_UINT32(data) != MKID('data')) {
-		warning("openFx: WAV file has no 'data' chunk");
+	if (!getWavInfo(data, &wavInfo)) {
+		warning("openFx: Not a valida WAV file");
 		return RDERR_INVALIDWAV;
 	}
 
-	_fx[fxi]._bufSize = READ_LE_UINT32(data + 4);
+	if (wavInfo.channels == 2)
+		_fx[fxi]._flags |= SoundMixer::FLAG_STEREO;
+
+	_fx[fxi]._rate = wavInfo.rate;
+	_fx[fxi]._bufSize = wavInfo.samples;
 
 	// Fill the speech buffer with data
 	free(_fx[fxi]._buf);
 	_fx[fxi]._buf = (uint16 *) malloc(_fx[fxi]._bufSize);
-	memcpy(_fx[fxi]._buf, data + 8, _fx[fxi]._bufSize);
+	memcpy(_fx[fxi]._buf, wavInfo.data, _fx[fxi]._bufSize);
 
 	return RD_OK;
 }

Index: d_sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_sound.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- d_sound.h	6 Jan 2004 13:44:17 -0000	1.42
+++ d_sound.h	16 Jan 2004 08:16:23 -0000	1.43
@@ -33,6 +33,13 @@
 
 extern void sword2_sound_handler(void *refCon);
 
+struct WavInfo {
+	uint8 channels;
+	uint16 rate;
+	uint32 samples;
+	uint8 *data;
+};
+
 struct FxHandle {
 	int32 _id;
 	bool _paused;
@@ -113,6 +120,8 @@
 	void fxServer(int16 *data, uint len);
 	void buildPanTable(bool reverse);
 
+	bool getWavInfo(uint8 *data, WavInfo *wavInfo);
+
 	void muteMusic(bool mute);
 	bool isMusicMute(void);
 	void setMusicVolume(uint8 vol);





More information about the Scummvm-git-logs mailing list