diff options
-rw-r--r-- | engines/gob/inter_bargon.cpp | 4 | ||||
-rw-r--r-- | engines/gob/inter_v4.cpp | 2 | ||||
-rw-r--r-- | engines/gob/inter_v6.cpp | 5 | ||||
-rw-r--r-- | engines/gob/map_v1.cpp | 4 | ||||
-rw-r--r-- | engines/gob/sound/sound.cpp | 18 | ||||
-rw-r--r-- | engines/gob/sound/sound.h | 6 | ||||
-rw-r--r-- | engines/gob/sound/sounddesc.cpp | 56 | ||||
-rw-r--r-- | engines/gob/sound/sounddesc.h | 8 |
8 files changed, 73 insertions, 30 deletions
diff --git a/engines/gob/inter_bargon.cpp b/engines/gob/inter_bargon.cpp index 5bb695c92b..db4d163a88 100644 --- a/engines/gob/inter_bargon.cpp +++ b/engines/gob/inter_bargon.cpp @@ -771,7 +771,7 @@ void Inter_Bargon::oBargon_intro2(OpGobParams ¶ms) { return; for (i = 0; i < 4; i++) - _vm->_sound->sampleLoad(&samples[i], sndFiles[i]); + _vm->_sound->sampleLoad(&samples[i], SOUND_SND, sndFiles[i]); _vm->_sound->blasterPlayComposition(comp, 0, samples, 4); _vm->_sound->blasterWaitEndPlay(true, false); _vm->_palAnim->fade(0, 0, 0); @@ -790,7 +790,7 @@ void Inter_Bargon::oBargon_intro3(OpGobParams ¶ms) { static const char *palFiles[] = {"2ou2.clt", "2ou3.clt", "2ou4.clt", "2ou5.clt"}; for (int i = 0; i < 2; i++) - _vm->_sound->sampleLoad(&samples[i], sndFiles[i]); + _vm->_sound->sampleLoad(&samples[i], SOUND_SND, sndFiles[i]); for (int i = 0; i < 4; i++) palettes[i] = _vm->_dataIO->getData(palFiles[i]); palBak = _vm->_global->_pPaletteDesc->vgaPal; diff --git a/engines/gob/inter_v4.cpp b/engines/gob/inter_v4.cpp index 1921f4c6fd..2b02c942a4 100644 --- a/engines/gob/inter_v4.cpp +++ b/engines/gob/inter_v4.cpp @@ -871,7 +871,7 @@ void Inter_v4::o4_playVmdOrMusic() { } else if (lastFrame == -9) { _vm->_sound->bgStop(); _vm->_sound->bgSetPlayMode(BackgroundAtmosphere::kPlayModeRandom); - _vm->_sound->bgPlay(fileName, palStart); + _vm->_sound->bgPlay(fileName, "SND", SOUND_SND, palStart); return; } else if (lastFrame < 0) { warning("Unknown Video/Music command: %d, %s", lastFrame, fileName); diff --git a/engines/gob/inter_v6.cpp b/engines/gob/inter_v6.cpp index f4c10dfb2f..13b84639f5 100644 --- a/engines/gob/inter_v6.cpp +++ b/engines/gob/inter_v6.cpp @@ -686,10 +686,11 @@ void Inter_v6::o6_playVmdOrMusic() { if (lastFrame == -1) { close = true; } else if (lastFrame == -5) { - warning("Urban Stub: Stopping background music \"%s\"", fileName); + _vm->_sound->bgStop(); return; } else if (lastFrame == -9) { - warning("Urban Stub: Starting background music \"%s\"", fileName); + _vm->_sound->bgStop(); + _vm->_sound->bgPlay(fileName, SOUND_WAV); return; } else if (lastFrame == -10) { _vm->_vidPlayer->primaryClose(); diff --git a/engines/gob/map_v1.cpp b/engines/gob/map_v1.cpp index 4ac99d2465..2c94b3fb24 100644 --- a/engines/gob/map_v1.cpp +++ b/engines/gob/map_v1.cpp @@ -159,7 +159,7 @@ void Map_v1::loadSounds(Common::SeekableReadStream &data) { strcpy(sndNames[i], buf); } - _vm->_sound->sampleLoad(&_vm->_goblin->_soundData[14], "diamant1.snd"); + _vm->_sound->sampleLoad(&_vm->_goblin->_soundData[14], SOUND_SND, "diamant1.snd"); for (int i = 0; i < count; i++) { handle = _vm->_dataIO->openData(sndNames[i]); @@ -167,7 +167,7 @@ void Map_v1::loadSounds(Common::SeekableReadStream &data) { continue; _vm->_dataIO->closeData(handle); - _vm->_sound->sampleLoad(&_vm->_goblin->_soundData[i], sndNames[i]); + _vm->_sound->sampleLoad(&_vm->_goblin->_soundData[i], SOUND_SND, sndNames[i]); } } 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 |