aboutsummaryrefslogtreecommitdiff
path: root/queen/sound.cpp
diff options
context:
space:
mode:
authorJoost Peters2003-10-21 12:29:37 +0000
committerJoost Peters2003-10-21 12:29:37 +0000
commit5bcf5a901e6391d7f12f9792c71e63c5701492c1 (patch)
treeecec7aa3455e176a4881e634ace53bbcaadd84b3 /queen/sound.cpp
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
Diffstat (limited to 'queen/sound.cpp')
-rw-r--r--queen/sound.cpp104
1 files changed, 104 insertions, 0 deletions
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