aboutsummaryrefslogtreecommitdiff
path: root/engines/draci
diff options
context:
space:
mode:
authorRobert Špalek2010-06-30 08:27:09 +0000
committerRobert Špalek2010-06-30 08:27:09 +0000
commitc7f6a5b286bad600c987922396b7328079890342 (patch)
tree89b712f809c381646dbfc0f20ccb8ab07f1ef156 /engines/draci
parent764aa1a125e913fb6d9800f97136adcd13fff9ae (diff)
downloadscummvm-rg350-c7f6a5b286bad600c987922396b7328079890342.tar.gz
scummvm-rg350-c7f6a5b286bad600c987922396b7328079890342.tar.bz2
scummvm-rg350-c7f6a5b286bad600c987922396b7328079890342.zip
Generalize the sound archive framework to be able to open new formats
svn-id: r50519
Diffstat (limited to 'engines/draci')
-rw-r--r--engines/draci/draci.cpp4
-rw-r--r--engines/draci/game.cpp2
-rw-r--r--engines/draci/game.h2
-rw-r--r--engines/draci/sound.cpp10
-rw-r--r--engines/draci/sound.h55
5 files changed, 53 insertions, 20 deletions
diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp
index ee883f9881..202bf6d187 100644
--- a/engines/draci/draci.cpp
+++ b/engines/draci/draci.cpp
@@ -123,8 +123,8 @@ int DraciEngine::init() {
_itemImagesArchive = new BArchive(itemImagesPath);
_stringsArchive = new BArchive(stringsPath);
- _soundsArchive = new SoundArchive(soundsPath, kSoundsFrequency);
- _dubbingArchive = new SoundArchive(dubbingPath, kDubbingFrequency);
+ _soundsArchive = new LegacySoundArchive(soundsPath, kSoundsFrequency);
+ _dubbingArchive = new LegacySoundArchive(dubbingPath, kDubbingFrequency);
_sound = new Sound(_mixer);
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp
index 23c50b8f63..8f3ad12cfd 100644
--- a/engines/draci/game.cpp
+++ b/engines/draci/game.cpp
@@ -332,7 +332,7 @@ void Game::handleOrdinaryLoop(int x, int y) {
}
}
-int Game::inventoryPositionFromMouse() {
+int Game::inventoryPositionFromMouse() const {
const int column = CLIP(scummvm_lround(
(_vm->_mouse->getPosX() - kInventoryX + kInventoryItemWidth / 2.) /
kInventoryItemWidth) - 1, 0L, (long) kInventoryColumns - 1);
diff --git a/engines/draci/game.h b/engines/draci/game.h
index 275293074e..21baaed5cc 100644
--- a/engines/draci/game.h
+++ b/engines/draci/game.h
@@ -335,7 +335,7 @@ public:
private:
void updateOrdinaryCursor();
void updateInventoryCursor();
- int inventoryPositionFromMouse();
+ int inventoryPositionFromMouse() const;
void handleOrdinaryLoop(int x, int y);
void handleInventoryLoop();
void handleDialogueLoop();
diff --git a/engines/draci/sound.cpp b/engines/draci/sound.cpp
index 4fb2fd6309..65e7e41ac4 100644
--- a/engines/draci/sound.cpp
+++ b/engines/draci/sound.cpp
@@ -39,7 +39,7 @@
namespace Draci {
-void SoundArchive::openArchive(const Common::String &path) {
+void LegacySoundArchive::openArchive(const Common::String &path) {
// Close previously opened archive (if any)
closeArchive();
@@ -103,12 +103,12 @@ void SoundArchive::openArchive(const Common::String &path) {
}
/**
- * @brief SoundArchive close method
+ * @brief LegacySoundArchive close method
*
* Closes the currently opened archive. It can be called explicitly to
* free up memory.
*/
-void SoundArchive::closeArchive() {
+void LegacySoundArchive::closeArchive() {
clearCache();
delete _f;
_f = NULL;
@@ -123,7 +123,7 @@ void SoundArchive::closeArchive() {
* Clears the cache of the open files inside the archive without closing it.
* If the files are subsequently accessed, they are read from the disk.
*/
-void SoundArchive::clearCache() {
+void LegacySoundArchive::clearCache() {
// Delete all cached data
for (uint i = 0; i < _sampleCount; ++i) {
_samples[i].close();
@@ -137,7 +137,7 @@ void SoundArchive::clearCache() {
*
* Loads individual samples from an archive to memory on demand.
*/
-SoundSample *SoundArchive::getSample(int i, uint freq) {
+SoundSample *LegacySoundArchive::getSample(int i, uint freq) {
// Check whether requested file exists
if (i < 0 || i >= (int) _sampleCount) {
return NULL;
diff --git a/engines/draci/sound.h b/engines/draci/sound.h
index 28379b5429..e4cf7efdec 100644
--- a/engines/draci/sound.h
+++ b/engines/draci/sound.h
@@ -47,28 +47,61 @@ struct SoundSample {
}
};
+/**
+ * An abstract wrapper around archives of sound samples or dubbing.
+ */
class SoundArchive {
public:
- SoundArchive(const Common::String &path, uint defaultFreq) :
+ SoundArchive() { }
+ virtual ~SoundArchive() { }
+
+ /**
+ * Returns the number of sound samples in the archive. Zero means that
+ * a fake empty archive has been opened and the caller may consider
+ * opening a different one, for example with compressed music.
+ */
+ virtual uint size() const = 0;
+
+ /**
+ * Checks whether there is an archive opened. Should be called before reading
+ * from the archive to check whether opening of the archive has succeeded.
+ */
+ virtual bool isOpen() const = 0;
+
+ /**
+ * Removes cached samples from memory.
+ */
+ virtual void clearCache() = 0;
+
+ /**
+ * Caches a given sample into memory and returns a pointer into it. We
+ * own the pointer. If freq is nonzero, then the sample is played at a
+ * different frequency (only used for uncompressed samples).
+ */
+ virtual SoundSample *getSample(int i, uint freq) = 0;
+};
+
+/**
+ * Reads CD.SAM (with dubbing) and CD2.SAM (with sound samples) from the
+ * original game.
+ */
+class LegacySoundArchive : public SoundArchive {
+public:
+ LegacySoundArchive(const Common::String &path, uint defaultFreq) :
_path(), _samples(NULL), _sampleCount(0), _defaultFreq(defaultFreq), _opened(false), _f(NULL) {
openArchive(path);
}
- ~SoundArchive() { closeArchive(); }
+ virtual ~LegacySoundArchive() { closeArchive(); }
void closeArchive();
void openArchive(const Common::String &path);
- uint size() const { return _sampleCount; }
-
- /**
- * Checks whether there is an archive opened. Should be called before reading
- * from the archive to check whether openArchive() succeeded.
- */
- bool isOpen() const { return _opened; }
- void clearCache();
+ virtual uint size() const { return _sampleCount; }
+ virtual bool isOpen() const { return _opened; }
- SoundSample *getSample(int i, uint freq);
+ virtual void clearCache();
+ virtual SoundSample *getSample(int i, uint freq);
private:
Common::String _path; ///< Path to file