aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/sound
diff options
context:
space:
mode:
authorSven Hesse2009-06-24 21:49:37 +0000
committerSven Hesse2009-06-24 21:49:37 +0000
commitd03dc08b64073044267fb4b3ca6704fd62a19741 (patch)
treeb614178e652348fe9072479254ca333825a28a05 /engines/gob/sound
parentef33f98a1a966b3956990414e62584ec371a550e (diff)
downloadscummvm-rg350-d03dc08b64073044267fb4b3ca6704fd62a19741.tar.gz
scummvm-rg350-d03dc08b64073044267fb4b3ca6704fd62a19741.tar.bz2
scummvm-rg350-d03dc08b64073044267fb4b3ca6704fd62a19741.zip
Wrapping resources (out of TOT, EXT, IM? and EX? files) loading into its own class
svn-id: r41839
Diffstat (limited to 'engines/gob/sound')
-rw-r--r--engines/gob/sound/sound.cpp2
-rw-r--r--engines/gob/sound/sounddesc.cpp42
-rw-r--r--engines/gob/sound/sounddesc.h17
3 files changed, 41 insertions, 20 deletions
diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp
index d667a2d592..d3afc9baa3 100644
--- a/engines/gob/sound/sound.cpp
+++ b/engines/gob/sound/sound.cpp
@@ -127,7 +127,7 @@ bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName,
return false;
size = _vm->_dataIO->getDataSize(fileName);
- return sndDesc->load(type, SOUND_FILE, data, size);
+ return sndDesc->load(type, data, size);
}
void Sound::sampleFree(SoundDesc *sndDesc, bool noteAdlib, int index) {
diff --git a/engines/gob/sound/sounddesc.cpp b/engines/gob/sound/sounddesc.cpp
index c4c78eebbd..79f4a48b77 100644
--- a/engines/gob/sound/sounddesc.cpp
+++ b/engines/gob/sound/sounddesc.cpp
@@ -29,15 +29,17 @@
#include "sound/wave.h"
#include "gob/sound/sounddesc.h"
+#include "gob/resources.h"
namespace Gob {
SoundDesc::SoundDesc() {
+ _resource = 0;
+
_data = _dataPtr = 0;
_size = 0;
_type = SOUND_SND;
- _source = SOUND_FILE;
_repCount = 0;
_frequency = 0;
@@ -50,23 +52,31 @@ SoundDesc::~SoundDesc() {
free();
}
-void SoundDesc::set(SoundType type, SoundSource src,
- byte *data, uint32 dSize) {
-
+void SoundDesc::set(SoundType type, byte *data, uint32 dSize) {
free();
_type = type;
- _source = src;
_data = _dataPtr = data;
_size = dSize;
}
-bool SoundDesc::load(SoundType type, SoundSource src,
- byte *data, uint32 dSize) {
+void SoundDesc::set(SoundType type, Resource *resource) {
+ byte *data = 0;
+ uint32 dSize = 0;
+
+ if (resource && (resource->getSize() > 0)) {
+ data = resource->getData();
+ dSize = resource->getSize();
+ }
+
+ set(type, data, dSize);
+
+ _resource = resource;
+}
+bool SoundDesc::load(SoundType type, byte *data, uint32 dSize) {
free();
- _source = src;
switch (type) {
case SOUND_ADL:
return loadADL(data, dSize);
@@ -79,9 +89,21 @@ bool SoundDesc::load(SoundType type, SoundSource src,
return false;
}
+bool SoundDesc::load(SoundType type, Resource *resource) {
+ if (!resource || (resource->getSize() <= 0))
+ return false;
+
+ if (!load(type, resource->getData(), resource->getSize()))
+ return false;
+
+ _resource = resource;
+ return true;
+}
+
void SoundDesc::free() {
- if (_source != SOUND_TOT)
- delete[] _data;
+ delete _resource;
+
+ _resource = 0;
_data = _dataPtr = 0;
_id = 0;
}
diff --git a/engines/gob/sound/sounddesc.h b/engines/gob/sound/sounddesc.h
index 83efd61e6d..9e5d20e138 100644
--- a/engines/gob/sound/sounddesc.h
+++ b/engines/gob/sound/sounddesc.h
@@ -30,18 +30,14 @@
namespace Gob {
+class Resource;
+
enum SoundType {
SOUND_SND,
SOUND_WAV,
SOUND_ADL
};
-enum SoundSource {
- SOUND_FILE,
- SOUND_TOT,
- SOUND_EXT
-};
-
class SoundDesc {
public:
int16 _repCount;
@@ -58,8 +54,11 @@ public:
bool isId(int16 id) const { return _dataPtr && (_id == id); }
- void set(SoundType type, SoundSource src, byte *data, uint32 dSize);
- bool load(SoundType type, SoundSource src, byte *data, uint32 dSize);
+ void set(SoundType type, byte *data, uint32 dSize);
+ void set(SoundType type, Resource *resource);
+ bool load(SoundType type, byte *data, uint32 dSize);
+ bool load(SoundType type, Resource *resource);
+
void free();
void convToSigned();
@@ -71,12 +70,12 @@ public:
~SoundDesc();
private:
+ Resource *_resource;
byte *_data;
byte *_dataPtr;
uint32 _size;
SoundType _type;
- SoundSource _source;
bool loadSND(byte *data, uint32 dSize);
bool loadWAV(byte *data, uint32 dSize);