[Scummvm-cvs-logs] CVS: scummvm/queen sound.cpp,NONE,1.1 sound.h,NONE,1.1 cutaway.cpp,1.41,1.42 cutaway.h,1.18,1.19 logic.cpp,1.53,1.54 logic.h,1.38,1.39 module.mk,1.10,1.11 queen.cpp,1.21,1.22 queen.h,1.10,1.11 talk.cpp,1.19,1.20 talk.h,1.11,1.12

Joost Peters joostp at users.sourceforge.net
Tue Oct 21 06:39:03 CEST 2003


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv10351/queen

Modified Files:
	cutaway.cpp cutaway.h logic.cpp logic.h module.mk queen.cpp 
	queen.h talk.cpp talk.h 
Added Files:
	sound.cpp sound.h 
Log Message:
add Sound class + call it from Talk::speakSegment

--- NEW FILE: sound.cpp ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/scummvm/queen/sound.cpp,v 1.1 2003/10/21 12:29:37 joostp Exp $
 *
 */

#include "stdafx.h"
#include "common/file.h"
#include "common/util.h"
#include "queen/resource.h"
#include "queen/sound.h"
#include "queen/queen.h"	//g_queen (temporary)

#define	SB_HEADER_SIZE	110

namespace Queen {

Sound::Sound(SoundMixer *mixer, Resource  *resource) : _mixer(mixer), _resource(resource), _sfxHandle(0) {
}

Sound::~Sound() {
}

Sound *Sound::giveSound(SoundMixer *mixer, Resource *resource, uint8 compression) {
	switch(compression) {
		case COMPRESSION_NONE:
				return new SBSound(mixer, resource);
				break;
		case COMPRESSION_MP3:
				#ifndef USE_MAD
					warning("Using MP3 compressed datafile, but MP3 support not compiled in");
					return new SilentSound(mixer, resource);
				#else
					return new MP3Sound(mixer, resource);

				#endif
				break;
		default:
				warning("Unknown compression type");
				return new SilentSound(mixer, resource);
	}
}

bool Sound::isPlaying() {
	return _sfxHandle != 0;
}

int SBSound::playSound(byte *sound, uint32 size) {
	byte flags = 0 | SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE;
	return _mixer->playRaw(&_sfxHandle, sound, size, 11025, flags);
}

void SBSound::sfxPlay(const char *base) {
	char name[13];
	strcpy(name, base);
	//alter filename to add zeros and append ".SB"
	for (int i = 0; i < 8; i++) {
		if (name[i] == ' ')
			name[i] = '0';
	}
	strcat(name, ".SB");

	while(isPlaying())
		g_queen->delay(10);
	
	if (_resource->exists(name)) 
		playSound(_resource->loadFile(name, SB_HEADER_SIZE), _resource->fileSize(name) - SB_HEADER_SIZE);
}

#ifdef USE_MAD
void MP3Sound::sfxPlay(const char *base) {
	char name[13];
	strcpy(name, base);
	//alter filename to add zeros and append ".SB"
	for (int i = 0; i < 8; i++) {
		if (name[i] == ' ')
			name[i] = '0';
	}
	strcat(name, ".SB");
	
	while(isPlaying())
		g_queen->delay(10);

	if (_resource->exists(name)) 
		_mixer->playMP3(&_sfxHandle, _resource->giveMP3(name), _resource->fileSize(name));
}
#endif

} //End of namespace Queen

--- NEW FILE: sound.h ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/scummvm/queen/sound.h,v 1.1 2003/10/21 12:29:37 joostp Exp $
 *
 */

#ifndef QUEENSOUND_H
#define QUEENSOUND_H

#include "sound/mixer.h"
#include "queen/defs.h"
#include "common/str.h"

namespace Queen {

class Resource;

class Sound {
public:
	Sound(SoundMixer *mixer, Resource *resource);
	virtual ~Sound(); 
	virtual void sfxPlay(const char *base) = 0;
	static Sound *giveSound(SoundMixer *mixer, Resource *resource, uint8 compression);
	bool isPlaying();

protected:
	SoundMixer *_mixer;
	Resource *_resource;

	PlayingSoundHandle _sfxHandle;
};

class SilentSound : public Sound {
public:
	SilentSound(SoundMixer *mixer, Resource *resource) : Sound(mixer, resource) {};
	void sfxPlay(const char *base) { }
};

class SBSound : public Sound {
public:
	SBSound(SoundMixer *mixer, Resource *resource) : Sound(mixer, resource) {};
	int playSound(byte *sound, uint32 size);
	void sfxPlay(const char *base);
};

#ifdef USE_MAD
class MP3Sound : public Sound {
public:
	MP3Sound(SoundMixer *mixer, Resource *resource) : Sound(mixer, resource) {};
	void sfxPlay(const char *base);
};
#endif

} // End of namespace Queen

#endif

Index: cutaway.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/cutaway.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- cutaway.cpp	21 Oct 2003 12:13:56 -0000	1.41
+++ cutaway.cpp	21 Oct 2003 12:29:37 -0000	1.42
@@ -64,8 +64,9 @@
 		char *nextFilename,
 		Graphics *graphics,
 		Logic *logic,
-		Resource *resource) {
-	Cutaway *cutaway = new Cutaway(filename, graphics, logic, resource);
+		Resource *resource,
+		Sound *sound) {
+	Cutaway *cutaway = new Cutaway(filename, graphics, logic, resource, sound);
 	cutaway->run(nextFilename);
 	delete cutaway;
 }
@@ -74,8 +75,9 @@
 		const char *filename, 
 		Graphics *graphics,
 		Logic *logic,
-		Resource *resource) 
-: _graphics(graphics), _logic(logic), _resource(resource), _walk(logic->walk()),
+		Resource *resource,
+		Sound *sound) 
+: _graphics(graphics), _logic(logic), _resource(resource), _sound(sound), _walk(logic->walk()),
 	_quit(false), _personDataCount(0), _personFaceCount(0), _lastSong(0), _songBeforeComic(0) {
 	memset(&_bankNames, 0, sizeof(_bankNames));
 	load(filename); 
@@ -1040,7 +1042,7 @@
 			char voiceFilePrefix[MAX_STRING_SIZE];
 			findCdCut(_basename, index, voiceFilePrefix);
 			Talk::speak(sentence, (object.objectNumber == OBJECT_JOE) ? NULL : &p, voiceFilePrefix,
-				_graphics, _logic, _resource);
+				_graphics, _logic, _resource, _sound);
 		}
 
 	}
@@ -1398,7 +1400,7 @@
 	if (0 == scumm_stricmp(right(_talkFile, 4), ".dog")) {
 		nextFilename[0] = '\0';
 
-		Talk::talk(_talkFile, 0 /* XXX */, nextFilename, _graphics, _logic, _resource);
+		Talk::talk(_talkFile, 0 /* XXX */, nextFilename, _graphics, _logic, _resource, _sound);
 	}
 }
 

Index: cutaway.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/cutaway.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- cutaway.h	21 Oct 2003 12:13:56 -0000	1.18
+++ cutaway.h	21 Oct 2003 12:29:37 -0000	1.19
@@ -30,6 +30,7 @@
 class Graphics;
 class Logic;
 class Resource;
+class Sound;
 class Walk;
 
 
@@ -41,7 +42,8 @@
 				char *nextFilename,
 				Graphics *graphics,
 				Logic *logic,
-				Resource *resource);
+				Resource *resource,
+				Sound *sound);
 
 	public:
 		//! Collection of constants used by QueenCutaway
@@ -136,6 +138,7 @@
 		Graphics    *_graphics;
 		Logic       *_logic;
 		Resource    *_resource;
+		Sound       *_sound;
 		Walk        *_walk;
 
 		//! Raw .cut file data (without 20 byte header)
@@ -212,7 +215,8 @@
 				const char *filename, 
 				Graphics *graphics,
 				Logic *logic,
-				Resource *resource);
+				Resource *resource,
+				Sound *sound);
 		~Cutaway();
 
 		//! Run this cutaway object 

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- logic.cpp	21 Oct 2003 09:05:16 -0000	1.53
+++ logic.cpp	21 Oct 2003 12:29:37 -0000	1.54
@@ -30,8 +30,8 @@
 
 namespace Queen {
 
-Logic::Logic(Resource *resource, Graphics *graphics, Display *theDisplay)
-	: _resource(resource), _graphics(graphics), _display(theDisplay), _talkSpeed(DEFAULT_TALK_SPEED) {
+Logic::Logic(Resource *resource, Graphics *graphics, Display *theDisplay, Sound *sound)
+	: _resource(resource), _graphics(graphics), _display(theDisplay), _sound(sound), _talkSpeed(DEFAULT_TALK_SPEED) {
 	_jas = _resource->loadFile("QUEEN.JAS", 20);
 	_joe.x = _joe.y = 0;
 	_joe.scale = 100;
@@ -1838,7 +1838,7 @@
 void Logic::playCutaway(const char* cutFile) {
 
 	char next[20];
-	Cutaway::run(cutFile, next, _graphics, this, _resource);
+	Cutaway::run(cutFile, next, _graphics, this, _resource, _sound);
 }
 
 

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- logic.h	21 Oct 2003 09:05:16 -0000	1.38
+++ logic.h	21 Oct 2003 12:29:37 -0000	1.39
@@ -54,12 +54,13 @@
 class Graphics;
 class Resource;
 class Display;
+class Sound;
 class Walk;
 
 class Logic {
 
 public:
-	Logic(Resource *resource, Graphics *graphics, Display *display);
+	Logic(Resource *resource, Graphics *graphics, Display *display, Sound *sound);
 	~Logic();
 
 	uint16 currentRoom();
@@ -276,6 +277,7 @@
 	Resource *_resource;
 	Graphics *_graphics;
 	Display *_display;
+	Sound *_sound;
 	Walk *_walk;
 
 	int _talkSpeed;	// TALKSPD

Index: module.mk
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/module.mk,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- module.mk	16 Oct 2003 13:54:48 -0000	1.10
+++ module.mk	21 Oct 2003 12:29:37 -0000	1.11
@@ -8,6 +8,7 @@
 	queen/queen.o \
 	queen/resource.o \
 	queen/restables.o \
+	queen/sound.o \
 	queen/talk.o \
 	queen/walk.o
 

Index: queen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/queen.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- queen.cpp	20 Oct 2003 20:12:59 -0000	1.21
+++ queen.cpp	21 Oct 2003 12:29:37 -0000	1.22
@@ -29,6 +29,7 @@
 #include "queen/display.h"
 #include "queen/graphics.h"
 #include "queen/queen.h"
+#include "queen/sound.h"
 #include "queen/talk.h"
 #include "queen/walk.h"
 
@@ -137,29 +138,29 @@
 
 		if (_resource->isDemo()) {
 			if (_resource->exists("pclogo.cut"))
-				Cutaway::run("pclogo.cut", nextFilename, _graphics, _logic, _resource);
+				Cutaway::run("pclogo.cut", nextFilename, _graphics, _logic, _resource, _sound);
 			else
-				Cutaway::run("clogo.cut",  nextFilename, _graphics, _logic, _resource);
+				Cutaway::run("clogo.cut",  nextFilename, _graphics, _logic, _resource, _sound);
 		}
 		else {
-			Cutaway::run("copy.cut",  nextFilename, _graphics, _logic, _resource);
-			Cutaway::run("clogo.cut", nextFilename, _graphics, _logic, _resource);
+			Cutaway::run("copy.cut",  nextFilename, _graphics, _logic, _resource, _sound);
+			Cutaway::run("clogo.cut", nextFilename, _graphics, _logic, _resource, _sound);
 
 			// TODO enable talking for talkie version
 
-			Cutaway::run("cdint.cut", nextFilename, _graphics, _logic, _resource);
+			Cutaway::run("cdint.cut", nextFilename, _graphics, _logic, _resource, _sound);
 
 			// restore palette colors ranging from 144 to 256
 			_graphics->loadPanel();
 			
-			Cutaway::run("cred.cut",  nextFilename, _graphics, _logic, _resource);
+			Cutaway::run("cred.cut",  nextFilename, _graphics, _logic, _resource, _sound);
 		}
 
 		_logic->currentRoom(73);
 		_logic->entryObj(584);
 
 		_logic->roomDisplay(_logic->roomName(_logic->currentRoom()), RDM_FADE_JOE, 100, 2, true);
-		Cutaway::run("c70d.cut", nextFilename, _graphics, _logic, _resource);
+		Cutaway::run("c70d.cut", nextFilename, _graphics, _logic, _resource, _sound);
 
 		_logic->gameState(VAR_INTRO_PLAYED, 1);
 
@@ -220,8 +221,8 @@
 	_resource = new Resource(_gameDataPath, _detector->_game.detectname);
 	_display = new Display(_system);
 	_graphics = new Graphics(_display, _resource);
-	_logic = new Logic(_resource, _graphics, _display);
-	//_sound = new Sound(_mixer, _detector->_sfx_volume);
+	_sound = Sound::giveSound(_mixer, _resource, _resource->compression());
+	_logic = new Logic(_resource, _graphics, _display, _sound);
 	_timer->installTimerProc(&timerHandler, 1000000 / 50, this); //call 50 times per second
 }
 

Index: queen.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/queen.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- queen.h	20 Oct 2003 20:12:58 -0000	1.10
+++ queen.h	21 Oct 2003 12:29:37 -0000	1.11
@@ -35,6 +35,7 @@
 class Graphics;
 class Logic;
 class Display;
+class Sound;
 
 class QueenEngine : public Engine {
 	void errorString(const char *buf_input, char *buf_output);
@@ -55,7 +56,8 @@
 	Resource *_resource;
 	Logic *_logic;
 	Display *_display;
-
+	Sound *_sound;
+	
 	GameDetector *_detector; // necessary for music
 	
 public:

Index: talk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- talk.cpp	19 Oct 2003 11:55:55 -0000	1.19
+++ talk.cpp	21 Oct 2003 12:29:37 -0000	1.20
@@ -20,8 +20,9 @@
  */
 
 #include "stdafx.h"
-#include "talk.h"
-#include "graphics.h"
+#include "queen/talk.h"
+#include "queen/graphics.h"
+#include "queen/sound.h"
 
 namespace Queen {
 
@@ -38,8 +39,9 @@
 		char *cutawayFilename,
 		Graphics *graphics,
 		Logic *logic,
-		Resource *resource) {
-	Talk *talk = new Talk(graphics, logic, resource);
+		Resource *resource,
+		Sound *sound) {
+	Talk *talk = new Talk(graphics, logic, resource, sound);
 	talk->talk(filename, personInRoom, cutawayFilename);
 	delete talk;
 }
@@ -50,8 +52,9 @@
 		const char *voiceFilePrefix,
 		Graphics *graphics,
 		Logic *logic,
-		Resource *resource) {
-	Talk *talk = new Talk(graphics, logic, resource);
+		Resource *resource,
+	       	Sound *sound) {
+	Talk *talk = new Talk(graphics, logic, resource, sound);
 	bool result = talk->speak(sentence, person, voiceFilePrefix);
 	delete talk;
 	return result;
@@ -60,8 +63,9 @@
 Talk::Talk(
 		Graphics *graphics,
 		Logic *logic,
-		Resource *resource) 
-: _graphics(graphics), _logic(logic), _resource(resource), _fileData(NULL), _quit(false) {
+		Resource *resource,
+		Sound *sound) 
+: _graphics(graphics), _logic(logic), _resource(resource), _sound(sound), _fileData(NULL), _quit(false) {
 
 	//! TODO Move this to the Logic class later!
 	memset(_talkSelected, 0, sizeof(_talkSelected));
@@ -635,6 +639,7 @@
 	//debug(0, "Sentence segment '%*s' is said by person '%s' and voice file '%s' is played",
 	//		length, segment, person, voiceFileName);
 
+	_sound->sfxPlay(voiceFileName);
 	debug(0, "Playing voice file '%s'", voiceFileName);
 
 	int faceDirectionCommand = 0;

Index: talk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- talk.h	18 Oct 2003 12:18:43 -0000	1.11
+++ talk.h	21 Oct 2003 12:29:37 -0000	1.12
@@ -29,6 +29,7 @@
 class Graphics;
 class Logic;
 class Resource;
+class Sound;
 struct BobSlot;
 
 class Talk {
@@ -41,7 +42,8 @@
 		char *cutawayFilename, 
 		Graphics *graphics,
 		Logic *logic,
-		Resource *resource);
+		Resource *resource,
+		Sound *sound);
 
 	//! Public interface to speak a sentence
 	static bool speak(
@@ -50,7 +52,8 @@
 		const char *voiceFilePrefix,
 		Graphics *graphics,
 		Logic *logic,
-		Resource *resource);
+		Resource *resource,
+		Sound *sound);
 
 	//! Read a string from ptr and return new ptr
 	static byte *getString(byte *ptr, char *str, int maxLength, int align = 2);
@@ -107,6 +110,7 @@
 	Graphics  *_graphics;
 	Logic     *_logic;
 	Resource  *_resource;
+	Sound     *_sound;
 
 	//! Raw .dog file data (without 20 byte header)
 	byte *_fileData;
@@ -155,7 +159,7 @@
 
 	static const SpeechParameters _speechParameters[];
 
-	Talk(Graphics *graphics, Logic *logic, Resource *resource);
+	Talk(Graphics *graphics, Logic *logic, Resource *resource, Sound *sound);
 	~Talk();
 
 	//! Perform talk in file and return a cutaway filename





More information about the Scummvm-git-logs mailing list