aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/sound
diff options
context:
space:
mode:
authorSven Hesse2008-12-14 03:44:39 +0000
committerSven Hesse2008-12-14 03:44:39 +0000
commit68dcb1ffee87ce04dceb879f5eb3916fb99a1abe (patch)
treea08a68cb94008cb56e504a3acf5a1fd143e2b643 /engines/gob/sound
parentbbe6ff006e79473a0beeac5a4d88f901c68102fb (diff)
downloadscummvm-rg350-68dcb1ffee87ce04dceb879f5eb3916fb99a1abe.tar.gz
scummvm-rg350-68dcb1ffee87ce04dceb879f5eb3916fb99a1abe.tar.bz2
scummvm-rg350-68dcb1ffee87ce04dceb879f5eb3916fb99a1abe.zip
Background "music" for Urban Runner, though only 8bit for now
svn-id: r35352
Diffstat (limited to 'engines/gob/sound')
-rw-r--r--engines/gob/sound/sound.cpp18
-rw-r--r--engines/gob/sound/sound.h6
-rw-r--r--engines/gob/sound/sounddesc.cpp56
-rw-r--r--engines/gob/sound/sounddesc.h8
4 files changed, 65 insertions, 23 deletions
diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp
index 84f47990ec..5acc255275 100644
--- a/engines/gob/sound/sound.cpp
+++ b/engines/gob/sound/sound.cpp
@@ -50,6 +50,8 @@ Sound::Sound(GobEngine *vm) : _vm(vm) {
_cdrom = new CDROM;
if (_vm->getGameType() == kGameTypeWoodruff)
_bgatmos = new BackgroundAtmosphere(*_vm->_mixer);
+ if (_vm->getGameType() == kGameTypeUrban)
+ _bgatmos = new BackgroundAtmosphere(*_vm->_mixer);
}
Sound::~Sound() {
@@ -91,7 +93,7 @@ int Sound::sampleGetNextFreeSlot() const {
return -1;
}
-bool Sound::sampleLoad(SoundDesc *sndDesc, const char *fileName, bool tryExist) {
+bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName, bool tryExist) {
if (!sndDesc)
return false;
@@ -113,9 +115,7 @@ bool Sound::sampleLoad(SoundDesc *sndDesc, const char *fileName, bool tryExist)
return false;
size = _vm->_dataIO->getDataSize(fileName);
- sndDesc->load(SOUND_SND, SOUND_FILE, data, size);
-
- return true;
+ return sndDesc->load(type, SOUND_FILE, data, size);
}
void Sound::sampleFree(SoundDesc *sndDesc, bool noteAdlib, int index) {
@@ -520,7 +520,7 @@ void Sound::cdTest(int trySubst, const char *label) {
_cdrom->testCD(trySubst, label);
}
-void Sound::bgPlay(const char *file) {
+void Sound::bgPlay(const char *file, SoundType type) {
if (!_bgatmos)
return;
@@ -530,7 +530,7 @@ void Sound::bgPlay(const char *file) {
_bgatmos->queueClear();
SoundDesc *sndDesc = new SoundDesc;
- if (!sampleLoad(sndDesc, file)) {
+ if (!sampleLoad(sndDesc, type, file)) {
delete sndDesc;
return;
}
@@ -539,7 +539,7 @@ void Sound::bgPlay(const char *file) {
_bgatmos->play();
}
-void Sound::bgPlay(const char *base, int count) {
+void Sound::bgPlay(const char *base, const char *ext, SoundType type, int count) {
if (!_bgatmos)
return;
@@ -553,10 +553,10 @@ void Sound::bgPlay(const char *base, int count) {
SoundDesc *sndDesc;
for (int i = 1; i <= count; i++) {
- snprintf(fileName, length, "%s%02d.SND", base, i);
+ snprintf(fileName, length, "%s%02d.%s", base, i, ext);
sndDesc = new SoundDesc;
- if (sampleLoad(sndDesc, fileName))
+ if (sampleLoad(sndDesc, type, fileName))
_bgatmos->queueSample(*sndDesc);
else
delete sndDesc;
diff --git a/engines/gob/sound/sound.h b/engines/gob/sound/sound.h
index 641df6eb51..6fde4660aa 100644
--- a/engines/gob/sound/sound.h
+++ b/engines/gob/sound/sound.h
@@ -50,7 +50,7 @@ public:
const SoundDesc *sampleGetBySlot(int slot) const;
int sampleGetNextFreeSlot() const;
- bool sampleLoad(SoundDesc *sndDesc, const char *fileName, bool tryExist = true);
+ bool sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName, bool tryExist = true);
void sampleFree(SoundDesc *sndDesc, bool noteAdlib = false, int index = -1);
@@ -121,8 +121,8 @@ public:
// Background Atmosphere
- void bgPlay(const char *file);
- void bgPlay(const char *base, int count);
+ void bgPlay(const char *file, SoundType type);
+ void bgPlay(const char *base, const char *ext, SoundType type, int count);
void bgStop();
void bgSetPlayMode(BackgroundAtmosphere::PlayMode mode);
diff --git a/engines/gob/sound/sounddesc.cpp b/engines/gob/sound/sounddesc.cpp
index e0885d9faa..ee3125728b 100644
--- a/engines/gob/sound/sounddesc.cpp
+++ b/engines/gob/sound/sounddesc.cpp
@@ -24,6 +24,9 @@
*/
#include "common/util.h"
+#include "common/stream.h"
+#include "sound/mixer.h"
+#include "sound/wave.h"
#include "gob/sound/sounddesc.h"
@@ -57,7 +60,7 @@ void SoundDesc::set(SoundType type, SoundSource src,
_size = dSize;
}
-void SoundDesc::load(SoundType type, SoundSource src,
+bool SoundDesc::load(SoundType type, SoundSource src,
byte *data, uint32 dSize) {
free();
@@ -65,12 +68,14 @@ void SoundDesc::load(SoundType type, SoundSource src,
_source = src;
switch (type) {
case SOUND_ADL:
- loadADL(data, dSize);
- break;
+ return loadADL(data, dSize);
case SOUND_SND:
- loadSND(data, dSize);
- break;
+ return loadSND(data, dSize);
+ case SOUND_WAV:
+ return loadWAV(data, dSize);
}
+
+ return false;
}
void SoundDesc::free() {
@@ -81,7 +86,7 @@ void SoundDesc::free() {
}
void SoundDesc::convToSigned() {
- if ((_type == SOUND_SND) && _data && _dataPtr)
+ if (((_type == SOUND_SND) || (_type == SOUND_WAV)) && _data && _dataPtr)
for (uint32 i = 0; i < _size; i++)
_dataPtr[i] ^= 0x80;
}
@@ -95,7 +100,7 @@ uint32 SoundDesc::calcLength(int16 repCount, int16 frequency, bool fade) {
return ((_size * repCount - fadeSize) * 1000) / frequency;
}
-void SoundDesc::loadSND(byte *data, uint32 dSize) {
+bool SoundDesc::loadSND(byte *data, uint32 dSize) {
assert(dSize > 6);
_type = SOUND_SND;
@@ -105,12 +110,47 @@ void SoundDesc::loadSND(byte *data, uint32 dSize) {
_flag = data[0] ? (data[0] & 0x7F) : 8;
data[0] = 0;
_size = MIN(READ_BE_UINT32(data), dSize - 6);
+
+ return true;
}
-void SoundDesc::loadADL(byte *data, uint32 dSize) {
+bool SoundDesc::loadWAV(byte *data, uint32 dSize) {
+ Common::MemoryReadStream stream(data, dSize);
+
+ int wavSize, wavRate;
+ byte wavFlags;
+ uint16 wavtype;
+
+ if (!Audio::loadWAVFromStream(stream, wavSize, wavRate, wavFlags, &wavtype, 0))
+ return false;
+
+ if (wavFlags & Audio::Mixer::FLAG_16BITS) {
+ warning("TODO: SoundDesc::loadWAV() - 16bit");
+ return false;
+ }
+
+ if (wavFlags & Audio::Mixer::FLAG_STEREO) {
+ warning("TODO: SoundDesc::loadWAV() - stereo");
+ return false;
+ }
+
+ _data = data;
+ _dataPtr = data + stream.pos();
+ _size = wavSize;
+ _frequency = wavRate;
+
+ if (wavFlags & Audio::Mixer::FLAG_UNSIGNED)
+ convToSigned();
+
+ return true;
+}
+
+bool SoundDesc::loadADL(byte *data, uint32 dSize) {
_type = SOUND_ADL;
_data = _dataPtr = data;
_size = dSize;
+
+ return true;
}
} // End of namespace Gob
diff --git a/engines/gob/sound/sounddesc.h b/engines/gob/sound/sounddesc.h
index ed4447254c..fe1da14760 100644
--- a/engines/gob/sound/sounddesc.h
+++ b/engines/gob/sound/sounddesc.h
@@ -32,6 +32,7 @@ namespace Gob {
enum SoundType {
SOUND_SND,
+ SOUND_WAV,
SOUND_ADL
};
@@ -57,7 +58,7 @@ public:
bool isId(int16 id) const { return _dataPtr && (_id == id); }
void set(SoundType type, SoundSource src, byte *data, uint32 dSize);
- void load(SoundType type, SoundSource src, byte *data, uint32 dSize);
+ bool load(SoundType type, SoundSource src, byte *data, uint32 dSize);
void free();
void convToSigned();
@@ -76,8 +77,9 @@ private:
SoundType _type;
SoundSource _source;
- void loadSND(byte *data, uint32 dSize);
- void loadADL(byte *data, uint32 dSize);
+ bool loadSND(byte *data, uint32 dSize);
+ bool loadWAV(byte *data, uint32 dSize);
+ bool loadADL(byte *data, uint32 dSize);
};
} // End of namespace Gob