[Scummvm-cvs-logs] CVS: scummvm/bs2/driver d_draw.cpp,1.19,1.20 d_sound.cpp,1.56,1.57 d_sound.h,1.13,1.14 driver96.h,1.37,1.38

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Sun Sep 21 23:37:04 CEST 2003


Update of /cvsroot/scummvm/scummvm/bs2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv9374/driver

Modified Files:
	d_draw.cpp d_sound.cpp d_sound.h driver96.h 
Log Message:
Cleaned up the sound code enough to add cutscene voice-overs. I haven't had
the time to do much testing yet, but it seems to work for me.


Index: d_draw.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/d_draw.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- d_draw.cpp	14 Sep 2003 23:42:07 -0000	1.19
+++ d_draw.cpp	22 Sep 2003 06:36:38 -0000	1.20
@@ -23,6 +23,8 @@
 #include "bs2/header.h"		// HACK: For cutscenes instruction message
 #include "bs2/memory.h"		// HACK: For cutscenes instruction message
 #include "bs2/maketext.h"	// HACK: For cutscenes instruction message
+#include "bs2/sword2.h"
+#include "sound/mixer.h"
 #include "rdwin.h"
 #include "_mouse.h"
 #include "d_draw.h"
@@ -542,8 +544,6 @@
 	// WORKAROUND: For now, we just do the voice-over parts of the
 	// movies, since they're separate from the actual smacker files.
 
-	// TODO: Play the voice-over sounds.
-
 	// Do we really need to pre-cache the text sprites and speech data
 	// like this? It'd be simpler to just store the text id and construct
 	// the data as we go along.
@@ -600,6 +600,8 @@
 		BS2_SetPalette(0, 256, tmpPal, RDPAL_INSTANT);
 
 		while (1) {
+			PlayingSoundHandle handle;
+
 			if (!text[textCounter])
 				break;
 
@@ -607,8 +609,9 @@
 				EraseBackBuffer();
 				OpenTextObject(text[textCounter]);
 				DrawTextObject(text[textCounter]);
-				if (text[textCounter]->speech)
-					debug(0, "FIXME: Play subtitle speech");
+				if (text[textCounter]->speech) {
+					g_sword2->_mixer->playRaw(&handle, text[textCounter]->speech, text[textCounter]->speechBufferSize, 22050, SoundMixer::FLAG_16BITS);
+				}
 			}
 
 			if (frameCounter == text[textCounter]->endFrame) {
@@ -624,7 +627,7 @@
 			char key;
 
 			if (ReadKey(&key) == RD_OK && key == 27) {
-				// StopWavSpeech()
+				g_sword2->_mixer->stopHandle(handle);
 				break;
 			}
 

Index: d_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/d_sound.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- d_sound.cpp	21 Sep 2003 14:26:25 -0000	1.56
+++ d_sound.cpp	22 Sep 2003 06:36:38 -0000	1.57
@@ -330,184 +330,100 @@
 	return RDSE_QUIET;
 }
 
-int32 Sword2Sound::GetCompSpeechSize(const char *filename, uint32 speechid) {
+uint32 Sword2Sound::PreFetchCompSpeech(const char *filename, uint32 speechid, uint16 **buf) {
+	uint32 i;
+	uint8 *data8;
 	uint32 speechIndex[2];
 	File fp;
-	
+	uint32 bufferSize;
+
+	*buf = NULL;
+
 	// Open the speech cluster and find the data offset & size
 	fp.open(filename);
-	if (fp.isOpen() == false)
+	if (!fp.isOpen())
 		return 0;
 
-	fp.seek((++speechid) * 8, SEEK_SET);
+	fp.seek((speechid + 1) * 8, SEEK_SET);
 
 	if (fp.read(speechIndex, sizeof(uint32) * 2) != (sizeof(uint32) * 2)) {
 		fp.close();
 		return 0;
 	}
 
-	fp.close();
-
 #ifdef SCUMM_BIG_ENDIAN
 	speechIndex[0] = SWAP_BYTES_32(speechIndex[0]);
 	speechIndex[1] = SWAP_BYTES_32(speechIndex[1]);
 #endif
 
-	if (!speechIndex[0] || !speechIndex[1])
+	if (!speechIndex[0] || !speechIndex[1]) {
+		fp.close();
 		return 0;
+	}
 
-	return (speechIndex[1] - 1) * 2 + sizeof(_wavHeader) + 8;
-}
-
-int32 Sword2Sound::PreFetchCompSpeech(const char *filename, uint32 speechid, uint8 *waveMem) {
-	uint32 i;
-	uint16 *data16;
-	uint8 *data8;
-	uint32 speechIndex[2];
-	_wavHeader *pwf = (_wavHeader *) waveMem;
-	File fp;
-
-	// Open the speech cluster and find the data offset & size
-	fp.open(filename);
-	if (fp.isOpen() == false)
-		return RDERR_INVALIDFILENAME;
-
-	fp.seek((++speechid) * 8, SEEK_SET);
-
-	if (fp.read(speechIndex, sizeof(uint32) * 2) != (sizeof(uint32) * 2)) {
+	// Create a temporary buffer for compressed speech
+	if ((data8 = (uint8 *) malloc(speechIndex[1])) == NULL) {
 		fp.close();
-		return RDERR_READERROR;
+		return 0;
 	}
 
-#ifdef SCUMM_BIG_ENDIAN
-	speechIndex[0] = SWAP_BYTES_32(speechIndex[0]);
-	speechIndex[1] = SWAP_BYTES_32(speechIndex[1]);
-#endif
+	fp.seek(speechIndex[0], SEEK_SET);
 
-	if (!speechIndex[0] || !speechIndex[1]) {
+	if (fp.read(data8, speechIndex[1]) != speechIndex[1]) {
 		fp.close();
-		return RDERR_INVALIDID;
+		free(data8);
+		return 0;
 	}
 
-	data16 = (uint16 *) (waveMem + sizeof(_wavHeader));
-
-	memset(pwf, 0, sizeof(_wavHeader));
-
-	pwf->riff = MKID('RIFF');
-	pwf->wavID = MKID('WAVE');
-	pwf->format = MKID('fmt ');
-
-	pwf->formatLen = TO_LE_32(0x00000010);
-	pwf->formatTag = TO_LE_16(0x0001);
-	pwf->channels = TO_LE_16(0x0001);
-	pwf->samplesPerSec = TO_LE_16(0x5622);
-	pwf->avgBytesPerSec = TO_LE_16(0x0000);
-	pwf->blockAlign = TO_LE_16(0xAC44);
-	pwf->unknown1 = TO_LE_16(0x0000);
-	pwf->unknown2 = TO_LE_16(0x0002);
-	pwf->bitsPerSample = TO_LE_16(0x0010);
-
-	*((uint32 *) data16) = MKID('data');
-
-	data16 += 2;
-
-	*((uint32 *) data16) = TO_LE_32((speechIndex[1] - 1) * 2);
-
-	data16 += 2;
+	fp.close();
 
-	pwf->fileLength = (speechIndex[1] - 1) * 2 + sizeof(_wavHeader) + 8;
+	// Decompress data into speech buffer.
 
-	// Calculate position in buffer to load compressed sound into
-	data8 = (uint8 *) data16 + (speechIndex[1] - 1);
-	
-	fp.seek(speechIndex[0], SEEK_SET);
+	bufferSize = (speechIndex[1] - 1) * 2;
 
-	if (fp.read(data8, speechIndex[1]) != speechIndex[1]) {
-		fp.close();
-		return RDERR_INVALIDID;
+	*buf = (uint16 *) malloc(bufferSize);
+	if (!*buf) {
+		free(data8);
+		return 0;
 	}
 
-	fp.close();
+	uint16 *data16 = *buf;
 
 	// Starting Value
 	data16[0] = READ_LE_UINT16(data8);
 
-	for (i = 1; i < (speechIndex[1] - 1); i++) {
+	for (i = 1; i < speechIndex[1] - 1; i++) {
 		if (GetCompressedSign(data8[i + 1]))
 			data16[i] = data16[i - 1] - (GetCompressedAmplitude(data8[i + 1]) << GetCompressedShift(data8[i + 1]));
 		else
 			data16[i] = data16[i - 1] + (GetCompressedAmplitude(data8[i + 1]) << GetCompressedShift(data8[i + 1]));
 	}
 
-	return RD_OK;
+	free(data8);
+
+#ifndef SCUMM_BIG_ENDIAN
+	// Until the mixer supports LE samples natively, we need to convert
+	// our LE ones to BE
+	for (uint j = 0; j < bufferSize / 2; j++)
+		data16[j] = SWAP_BYTES_16(data16[j]);
+#endif
+
+	return bufferSize;
 }
 
 int32 Sword2Sound::PlayCompSpeech(const char *filename, uint32 speechid, uint8 vol, int8 pan) {
-	uint32 i;
 	uint16 *data16;
-	uint8 *data8;
-	uint32 speechIndex[2];
-	File fp;
 	uint32 bufferSize;
 	
 	if (!speechMuted) {
 		if (GetSpeechStatus() == RDERR_SPEECHPLAYING)
 			return RDERR_SPEECHPLAYING;
 
-		//  Open the speech cluster and find the data offset & size
-		fp.open(filename);
-		if (fp.isOpen() == false) 
-			return RDERR_INVALIDFILENAME;
-		
-		fp.seek((++speechid) * 8, SEEK_SET);
-
-		if (fp.read(speechIndex, sizeof(uint32) * 2) != (sizeof(uint32) * 2)) {
-			fp.close();
-			return RDERR_READERROR;
-		}
-
-#ifdef SCUMM_BIG_ENDIAN
-		speechIndex[0] = SWAP_BYTES_32(speechIndex[0]);
-		speechIndex[1] = SWAP_BYTES_32(speechIndex[1]);
-#endif
-
-		if (speechIndex[0] == 0 || speechIndex[1] == 0) {
-			fp.close();
-			return RDERR_INVALIDID;
-		}
-
-		bufferSize = (speechIndex[1] - 1) * 2;
-
-		// Create tempory buffer for compressed speech
-		if ((data8 = (uint8 *) malloc(speechIndex[1])) == NULL) {
-			fp.close();
-			return(RDERR_OUTOFMEMORY);
-		}
-
-		fp.seek(speechIndex[0], SEEK_SET);
-
-		if (fp.read(data8, speechIndex[1]) != speechIndex[1]) {
-			fp.close();
-			free(data8);
-			return RDERR_INVALIDID;
-		}
-
-		fp.close();
-
-		// Decompress data into speech buffer.
-		data16 = (uint16 *) malloc(bufferSize);
-
-		// Starting Value
-		data16[0] = READ_LE_UINT16(data8);
-
-		for (i = 1; i < bufferSize / 2; i++) {
-			if (GetCompressedSign(data8[i + 1]))
-				data16[i] = data16[i - 1] - (GetCompressedAmplitude(data8[i + 1]) << GetCompressedShift(data8[i + 1]));
-			else
-				data16[i] = data16[i - 1] + (GetCompressedAmplitude(data8[i + 1]) << GetCompressedShift(data8[i + 1]));
-		}
+		bufferSize = PreFetchCompSpeech(filename, speechid, &data16);
 
-		free(data8);
+		// We don't know exactly what went wrong here.
+		if (bufferSize == 0)
+			return RDERR_OUTOFMEMORY;
 
 		// Modify the volume according to the master volume
 
@@ -520,13 +436,6 @@
 			
 		uint32 flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE;
 
-#ifndef SCUMM_BIG_ENDIAN
-		// Until the mixer supports LE samples natively, we need to
-		// convert our LE ones to BE
-		for (uint j = 0; j < (bufferSize / 2); j++)
-			data16[j] = SWAP_BYTES_16(data16[j]);
-#endif
-
 		_mixer->playRaw(&soundHandleSpeech, data16, bufferSize, 22050, flags, -1, volume, p);
 
 		speechStatus = 1;
@@ -667,6 +576,7 @@
 			i++;
 			data++;
 		}
+
 		if (!data32)
 			return RDERR_INVALIDWAV;
 

Index: d_sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/d_sound.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- d_sound.h	21 Sep 2003 14:26:25 -0000	1.13
+++ d_sound.h	22 Sep 2003 06:36:38 -0000	1.14
@@ -74,8 +74,7 @@
 		void FxServer(void);
 		int32 PlaySpeech(uint8 *data, uint8 vol, int8 pan);
 		int32 PlayCompSpeech(const char *filename, uint32 speechid, uint8 vol, int8 pan);
-		int32 PreFetchCompSpeech(const char *filename, uint32 speechid, uint8 *waveMem);
-		int32 GetCompSpeechSize(const char *filename, uint32 speechid);
+		uint32 PreFetchCompSpeech(const char *filename, uint32 speechid, uint16 **buf);
 		int32 AmISpeaking();
 		int32 StopSpeechSword2(void);
 		int32 GetSpeechStatus(void);

Index: driver96.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/driver96.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- driver96.h	19 Sep 2003 06:42:21 -0000	1.37
+++ driver96.h	22 Sep 2003 06:36:38 -0000	1.38
@@ -1293,7 +1293,8 @@
 	uint16 startFrame;
 	uint16 endFrame;
 	_spriteInfo *textSprite;
-	_wavHeader *speech;
+	uint32 speechBufferSize;
+	uint16 *speech;
 } _movieTextObject;
 
 





More information about the Scummvm-git-logs mailing list