aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoost Peters2003-10-21 12:29:37 +0000
committerJoost Peters2003-10-21 12:29:37 +0000
commit5bcf5a901e6391d7f12f9792c71e63c5701492c1 (patch)
treeecec7aa3455e176a4881e634ace53bbcaadd84b3
parent1744ba3441ff74b240ccf77e23da536c74bb4c28 (diff)
downloadscummvm-rg350-5bcf5a901e6391d7f12f9792c71e63c5701492c1.tar.gz
scummvm-rg350-5bcf5a901e6391d7f12f9792c71e63c5701492c1.tar.bz2
scummvm-rg350-5bcf5a901e6391d7f12f9792c71e63c5701492c1.zip
add Sound class + call it from Talk::speakSegment
svn-id: r10933
-rw-r--r--queen/cutaway.cpp14
-rw-r--r--queen/cutaway.h8
-rw-r--r--queen/logic.cpp6
-rw-r--r--queen/logic.h4
-rw-r--r--queen/module.mk1
-rw-r--r--queen/queen.cpp19
-rw-r--r--queen/queen.h4
-rw-r--r--queen/sound.cpp104
-rw-r--r--queen/sound.h71
-rw-r--r--queen/talk.cpp21
-rw-r--r--queen/talk.h10
11 files changed, 229 insertions, 33 deletions
diff --git a/queen/cutaway.cpp b/queen/cutaway.cpp
index 1efb63570b..893fca3e35 100644
--- a/queen/cutaway.cpp
+++ b/queen/cutaway.cpp
@@ -64,8 +64,9 @@ void Cutaway::run(
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 @@ Cutaway::Cutaway(
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 @@ void Cutaway::handlePersonRecord(
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 @@ void Cutaway::talk(char *nextFilename) {
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);
}
}
diff --git a/queen/cutaway.h b/queen/cutaway.h
index 3405853d6f..e82858f9d3 100644
--- a/queen/cutaway.h
+++ b/queen/cutaway.h
@@ -30,6 +30,7 @@ namespace Queen {
class Graphics;
class Logic;
class Resource;
+class Sound;
class Walk;
@@ -41,7 +42,8 @@ class Cutaway {
char *nextFilename,
Graphics *graphics,
Logic *logic,
- Resource *resource);
+ Resource *resource,
+ Sound *sound);
public:
//! Collection of constants used by QueenCutaway
@@ -136,6 +138,7 @@ class Cutaway {
Graphics *_graphics;
Logic *_logic;
Resource *_resource;
+ Sound *_sound;
Walk *_walk;
//! Raw .cut file data (without 20 byte header)
@@ -212,7 +215,8 @@ class Cutaway {
const char *filename,
Graphics *graphics,
Logic *logic,
- Resource *resource);
+ Resource *resource,
+ Sound *sound);
~Cutaway();
//! Run this cutaway object
diff --git a/queen/logic.cpp b/queen/logic.cpp
index ebad1160dd..5edcb329d3 100644
--- a/queen/logic.cpp
+++ b/queen/logic.cpp
@@ -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::joeUseUnderwear() {
void Logic::playCutaway(const char* cutFile) {
char next[20];
- Cutaway::run(cutFile, next, _graphics, this, _resource);
+ Cutaway::run(cutFile, next, _graphics, this, _resource, _sound);
}
diff --git a/queen/logic.h b/queen/logic.h
index 10c33b5cf5..c1db94ebea 100644
--- a/queen/logic.h
+++ b/queen/logic.h
@@ -54,12 +54,13 @@ struct Command {
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 @@ protected:
Resource *_resource;
Graphics *_graphics;
Display *_display;
+ Sound *_sound;
Walk *_walk;
int _talkSpeed; // TALKSPD
diff --git a/queen/module.mk b/queen/module.mk
index 27fb037772..97cf76f38e 100644
--- a/queen/module.mk
+++ b/queen/module.mk
@@ -8,6 +8,7 @@ MODULE_OBJS = \
queen/queen.o \
queen/resource.o \
queen/restables.o \
+ queen/sound.o \
queen/talk.o \
queen/walk.o
diff --git a/queen/queen.cpp b/queen/queen.cpp
index 1466bdb805..df0e319937 100644
--- a/queen/queen.cpp
+++ b/queen/queen.cpp
@@ -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 @@ void QueenEngine::roomChanged() {
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 @@ void QueenEngine::initialise(void) {
_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
}
diff --git a/queen/queen.h b/queen/queen.h
index 71231fff76..70d6f92eca 100644
--- a/queen/queen.h
+++ b/queen/queen.h
@@ -35,6 +35,7 @@ namespace Queen {
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 @@ protected:
Resource *_resource;
Logic *_logic;
Display *_display;
-
+ Sound *_sound;
+
GameDetector *_detector; // necessary for music
public:
diff --git a/queen/sound.cpp b/queen/sound.cpp
new file mode 100644
index 0000000000..3a9df8d8aa
--- /dev/null
+++ b/queen/sound.cpp
@@ -0,0 +1,104 @@
+/* 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$
+ *
+ */
+
+#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
diff --git a/queen/sound.h b/queen/sound.h
new file mode 100644
index 0000000000..c64443cf99
--- /dev/null
+++ b/queen/sound.h
@@ -0,0 +1,71 @@
+/* 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$
+ *
+ */
+
+#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
diff --git a/queen/talk.cpp b/queen/talk.cpp
index 10a26f7876..eea9fde9ce 100644
--- a/queen/talk.cpp
+++ b/queen/talk.cpp
@@ -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 @@ void Talk::talk(
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 @@ bool Talk::speak(
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 @@ bool Talk::speak(
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 @@ void Talk::speakSegment(
//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;
diff --git a/queen/talk.h b/queen/talk.h
index 26b6226112..48d493f8af 100644
--- a/queen/talk.h
+++ b/queen/talk.h
@@ -29,6 +29,7 @@ namespace Queen {
class Graphics;
class Logic;
class Resource;
+class Sound;
struct BobSlot;
class Talk {
@@ -41,7 +42,8 @@ class Talk {
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 @@ class Talk {
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 @@ class Talk {
Graphics *_graphics;
Logic *_logic;
Resource *_resource;
+ Sound *_sound;
//! Raw .dog file data (without 20 byte header)
byte *_fileData;
@@ -155,7 +159,7 @@ class Talk {
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