diff options
author | Torbjörn Andersson | 2005-01-11 08:32:10 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2005-01-11 08:32:10 +0000 |
commit | c5e83de099dcffca0f5c0d791305c0189467e9d9 (patch) | |
tree | 043f8eff7f879a221c18a68e6e164e2bd9510417 | |
parent | 9eecc9406dba5b7f7a16713c7802bd2bb2f3292a (diff) | |
download | scummvm-rg350-c5e83de099dcffca0f5c0d791305c0189467e9d9.tar.gz scummvm-rg350-c5e83de099dcffca0f5c0d791305c0189467e9d9.tar.bz2 scummvm-rg350-c5e83de099dcffca0f5c0d791305c0189467e9d9.zip |
Use Fingolfin's new WAV code.
svn-id: r16540
-rw-r--r-- | saga/sndres.cpp | 54 | ||||
-rw-r--r-- | sword2/anims.cpp | 19 | ||||
-rw-r--r-- | sword2/driver/animation.cpp | 12 | ||||
-rw-r--r-- | sword2/driver/animation.h | 4 | ||||
-rw-r--r-- | sword2/driver/d_sound.cpp | 75 | ||||
-rw-r--r-- | sword2/driver/d_sound.h | 11 | ||||
-rw-r--r-- | sword2/sound.cpp | 4 |
7 files changed, 33 insertions, 146 deletions
diff --git a/saga/sndres.cpp b/saga/sndres.cpp index de47cafc09..8bb225bb0d 100644 --- a/saga/sndres.cpp +++ b/saga/sndres.cpp @@ -199,61 +199,19 @@ int SndRes::loadVocSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf } int SndRes::loadWavSound(byte *snd_res, size_t snd_res_len, SOUNDBUFFER *snd_buf_i) { - // TODO: This function should, perhaps, be made more robust. - - // TODO: use loadWAVFromStream to load the WAVE data! - /* + Common::MemoryReadStream readS(snd_res, snd_res_len); int rate, size; - bye flags; - bool isValidWAV; - Common::MemoryReadStream stream(snd_res, snd_res_len); - isValidWAV = loadWAVFromStream(stream, size, rate, flags); - */ - - MemoryReadStreamEndian readS(snd_res, snd_res_len, IS_BIG_ENDIAN); - - byte buf[4]; - - readS.read(buf, sizeof(buf)); - if (memcmp(buf, "RIFF", sizeof(buf)) != 0) { - return FAILURE; - } - - readS.readUint32(); - - readS.read(buf, sizeof(buf)); - if (memcmp(buf, "WAVE", sizeof(buf)) != 0) { - return FAILURE; - } + byte flags; - readS.read(buf, sizeof(buf)); - if (memcmp(buf, "fmt ", sizeof(buf)) != 0) { + if (!loadWAVFromStream(readS, size, rate, flags)) { return FAILURE; } - uint32 len = readS.readUint32(); - uint32 pos = readS.pos(); - - readS.readUint16(); - - snd_buf_i->s_stereo = (readS.readUint16() == 2) ? 1 : 0; - snd_buf_i->s_freq = readS.readUint16(); + snd_buf_i->s_stereo = ((flags & SoundMixer::FLAG_STEREO) != 0); + snd_buf_i->s_freq = rate; snd_buf_i->s_samplebits = 16; snd_buf_i->s_signed = 1; - - readS.seek(pos + len); - - for (;;) { - readS.read(buf, sizeof(buf)); - if (memcmp(buf, "data", sizeof(buf)) == 0) { - break; - } - - len = readS.readUint32(); - readS.seek(len, SEEK_CUR); - } - - snd_buf_i->s_buf_len = readS.readUint32(); + snd_buf_i->s_buf_len = size; byte *data = (byte *)malloc(snd_buf_i->s_buf_len); if (!data) { diff --git a/sword2/anims.cpp b/sword2/anims.cpp index 9d41e2c104..777b96329c 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -462,18 +462,16 @@ void Logic::clearSequenceSpeech(MovieTextObject *sequenceText[]) { } int32 Logic::fnSmackerLeadIn(int32 *params) { - byte *leadIn; - uint32 rv; - // params: 0 id of lead-in music - leadIn = _vm->_resman->openResource(params[0]); + byte *leadIn = _vm->_resman->openResource(params[0]); StandardHeader *header = (StandardHeader *) leadIn; assert(header->fileType == WAV_FILE); leadIn += sizeof(StandardHeader); - // wav data gets copied to sound memory - rv = _vm->_sound->playFx(0, leadIn, 0, 0, RDSE_FXLEADIN); + + uint32 len = _vm->_resman->fetchLen(params[0]) - sizeof(StandardHeader); + uint32 rv = _vm->_sound->playFx(0, len, leadIn, 0, 0, RDSE_FXLEADIN); if (rv) debug(5, "SFX ERROR: playFx() returned %.8x", rv); @@ -500,6 +498,7 @@ int32 Logic::fnPlaySequence(int32 *params) { char filename[30]; MovieTextObject *sequenceSpeechArray[MAX_SEQUENCE_TEXT_LINES + 1]; byte *leadOut = NULL; + uint32 leadOutLen = 0; // The original code had some #ifdef blocks for skipping or muting the // cutscenes - fondly described as "the biggest fudge in the history @@ -529,9 +528,9 @@ int32 Logic::fnPlaySequence(int32 *params) { assert(header->fileType == WAV_FILE); leadOut += sizeof(StandardHeader); - } - // play the smacker + leadOutLen = _vm->_resman->fetchLen(_smackerLeadOut) - sizeof(StandardHeader); + } // don't want to carry on streaming game music when smacker starts! fnStopMusic(NULL); @@ -543,9 +542,9 @@ int32 Logic::fnPlaySequence(int32 *params) { uint32 rv; if (_sequenceTextLines && !_scriptVars[DEMO]) - rv = player.play(filename, sequenceSpeechArray, leadOut); + rv = player.play(filename, sequenceSpeechArray, leadOut, leadOutLen); else - rv = player.play(filename, NULL, leadOut); + rv = player.play(filename, NULL, leadOut, leadOutLen); // check the error return-value if (rv) diff --git a/sword2/driver/animation.cpp b/sword2/driver/animation.cpp index 3a1a30f630..91c6847080 100644 --- a/sword2/driver/animation.cpp +++ b/sword2/driver/animation.cpp @@ -168,7 +168,7 @@ void MoviePlayer::drawTextObject(AnimationState *anim, MovieTextObject *obj) { * @param musicOut lead-out music */ -int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *musicOut) { +int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *musicOut, uint32 musicOutLen) { // This happens if the user quits during the "eye" smacker if (_vm->_quit) return RD_OK; @@ -188,7 +188,7 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *mus if (!anim->init(filename)) { delete anim; // Missing Files? Use the old 'Narration Only' hack - playDummy(filename, text, musicOut); + playDummy(filename, text, musicOut, musicOutLen); return RD_OK; } @@ -253,7 +253,7 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *mus frameCounter++; if (frameCounter == leadOutFrame && musicOut) - _vm->_sound->playFx(0, musicOut, 0, 0, RDSE_FXLEADOUT); + _vm->_sound->playFx(0, musicOutLen, musicOut, 0, 0, RDSE_FXLEADOUT); OSystem::Event event; while (_sys->pollEvent(event)) { @@ -334,7 +334,7 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *mus return RD_OK; #else // No MPEG2? Use the old 'Narration Only' hack - playDummy(filename, text, musicOut); + playDummy(filename, text, musicOut, musicOutLen); return RD_OK; #endif } @@ -344,7 +344,7 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], byte *mus * are missing. */ -int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte *musicOut) { +int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte *musicOut, uint32 musicOutLen) { int frameCounter = 0, textCounter = 0; if (text) { byte oldPal[256 * 4]; @@ -484,7 +484,7 @@ int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte // that have subtitles. if (!skipCutscene && musicOut) { - _vm->_sound->playFx(0, musicOut, 0, 0, RDSE_FXLEADOUT); + _vm->_sound->playFx(0, musicOutLen, musicOut, 0, 0, RDSE_FXLEADOUT); _vm->_sound->waitForLeadOut(); } diff --git a/sword2/driver/animation.h b/sword2/driver/animation.h index 1e44343244..edf1c575a6 100644 --- a/sword2/driver/animation.h +++ b/sword2/driver/animation.h @@ -71,11 +71,11 @@ private: void closeTextObject(MovieTextObject *obj); void drawTextObject(AnimationState *anim, MovieTextObject *obj); - int32 playDummy(const char *filename, MovieTextObject *text[], byte *musicOut); + int32 playDummy(const char *filename, MovieTextObject *text[], byte *musicOut, uint32 musicOutLen); public: MoviePlayer(Sword2Engine *vm); - int32 play(const char *filename, MovieTextObject *text[], byte *musicOut); + int32 play(const char *filename, MovieTextObject *text[], byte *musicOut, uint32 musicOutLen); }; } // End of namespace Sword2 diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index c61a349d28..3a1f1ba8b2 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -896,55 +896,6 @@ int32 Sound::playCompSpeech(uint32 speechid, uint8 vol, int8 pan) { // ---------------------------------------------------------------------------- /** - * Retrieve information about an in-memory WAV file. - * @param data The WAV data - * @param wavInfo Pointer to the WavInfo structure to fill with information. - * @return True if the data appears to be a WAV file, otherwise false. - */ - -bool Sound::getWavInfo(byte *data, WavInfo *wavInfo) { - uint32 wavLength; - uint32 offset; - - if (READ_UINT32(data) != MKID('RIFF')) { - warning("getWavInfo: No 'RIFF' header"); - return false; - } - - wavLength = READ_LE_UINT32(data + 4) + 8; - - if (READ_UINT32(data + 8) != MKID('WAVE')) { - warning("getWavInfo: No 'WAVE' header"); - return false; - } - - if (READ_UINT32(data + 12) != MKID('fmt ')) { - warning("getWavInfo: No 'fmt' header"); - return false; - } - - wavInfo->channels = READ_LE_UINT16(data + 22); - wavInfo->rate = READ_LE_UINT16(data + 24); - - offset = READ_LE_UINT32(data + 16) + 20; - - // It's almost certainly a WAV file, but we still need to find its - // 'data' chunk. - - while (READ_UINT32(data + offset) != MKID('data')) { - if (offset >= wavLength) { - warning("getWavInfo: Can't find 'data' chunk"); - return false; - } - offset += (READ_LE_UINT32(data + offset + 4) + 8); - } - - wavInfo->samples = READ_LE_UINT32(data + offset + 4); - wavInfo->data = data + offset + 8; - return true; -} - -/** * @return the index of the sound effect with the ID passed in. */ @@ -1112,7 +1063,7 @@ int32 Sound::stopFx(int32 id) { * @warning Zero is not a valid id */ -int32 Sound::playFx(int32 id, byte *data, uint8 vol, int8 pan, uint8 type) { +int32 Sound::playFx(int32 id, uint32 len, byte *data, uint8 vol, int8 pan, uint8 type) { if (!_soundOn) return RD_OK; @@ -1128,19 +1079,11 @@ int32 Sound::playFx(int32 id, byte *data, uint8 vol, int8 pan, uint8 type) { soundType = SoundMixer::kMusicAudioDataType; } - WavInfo wavInfo; - - // TODO: use loadWAVFromStream to load the WAVE data! - /* + Common::MemoryReadStream stream(data, len); int rate, size; - bye flags; - // FIXME: Instead of passing an arbitrary large size for the memory stream - // here, we should instead determine the real size of the memory area. - Common::MemoryReadStream stream(data, 10000000); - isValidWAV = loadWAVFromStream(stream, size, rate, flags); - */ - - if (!getWavInfo(data, &wavInfo)) { + byte flags; + + if (!loadWAVFromStream(stream, size, rate, flags)) { warning("playFx: Not a valid WAV file"); return RDERR_INVALIDWAV; } @@ -1176,12 +1119,6 @@ int32 Sound::playFx(int32 id, byte *data, uint8 vol, int8 pan, uint8 type) { if (_fx[fxi]._handle.isActive()) return RDERR_FXALREADYOPEN; - uint32 flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_LITTLE_ENDIAN; - - if (wavInfo.channels == 2) - flags |= SoundMixer::FLAG_STEREO; - - if (type == RDSE_FXLOOP) flags |= SoundMixer::FLAG_LOOP; else @@ -1191,7 +1128,7 @@ int32 Sound::playFx(int32 id, byte *data, uint8 vol, int8 pan, uint8 type) { int8 p = _panTable[pan + 16]; - _vm->_mixer->playRaw(&_fx[fxi]._handle, wavInfo.data, wavInfo.samples, wavInfo.rate, flags, -1, volume, p, 0, 0, soundType); + _vm->_mixer->playRaw(&_fx[fxi]._handle, data + stream.pos(), size, rate, flags, -1, volume, p, 0, 0, soundType); return RD_OK; } diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h index 77d8f753d0..244f58625c 100644 --- a/sword2/driver/d_sound.h +++ b/sword2/driver/d_sound.h @@ -41,13 +41,6 @@ enum { extern void sword2_sound_handler(void *refCon); -struct WavInfo { - uint8 channels; - uint16 rate; - uint32 samples; - uint8 *data; -}; - struct FxHandle { int32 _id; bool _paused; @@ -97,8 +90,6 @@ public: void buildPanTable(bool reverse); - bool getWavInfo(uint8 *data, WavInfo *wavInfo); - void muteMusic(bool mute); bool isMusicMute(void); void pauseMusic(void); @@ -126,7 +117,7 @@ public: void pauseFxForSequence(void); void unpauseFx(void); bool isFxPlaying(int32 id); - int32 playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type); + int32 playFx(int32 id, uint32 len, uint8 *data, uint8 vol, int8 pan, uint8 type); int32 stopFx(int32 id); void clearAllFx(void); }; diff --git a/sword2/sound.cpp b/sword2/sound.cpp index a2bb003bf2..b5dff64f4a 100644 --- a/sword2/sound.cpp +++ b/sword2/sound.cpp @@ -128,7 +128,9 @@ void Sword2Engine::triggerFx(uint8 i) { else type = RDSE_FXSPOT; - uint32 rv = _sound->playFx(i + 1, fxQueue[i].data, fxQueue[i].volume, fxQueue[i].pan, type); + uint32 len = _resman->fetchLen(fxQueue[i].resource) - sizeof(StandardHeader); + uint32 rv = _sound->playFx(i + 1, len, fxQueue[i].data, fxQueue[i].volume, fxQueue[i].pan, type); + if (rv) debug(5, "SFX ERROR: playFx() returned %.8x", rv); } |