DRAGONS: work on sfx

This commit is contained in:
Eric Fry 2019-12-20 20:45:10 +11:00 committed by Eugene Sandulenko
parent ddcec20428
commit f9db411416
4 changed files with 76 additions and 13 deletions

View File

@ -1,3 +1,24 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <common/textconsole.h>
#include <common/debug.h>
#include <audio/decoders/xa.h>
@ -12,8 +33,8 @@ namespace Dragons {
loadHeader(msfData);
auto dataSize = msfData->size() - msfData->pos();
byte *newData = new byte[dataSize];
msfData->read(newData, dataSize);
_vbData = new byte[dataSize];
msfData->read(_vbData, dataSize);
// _vbData = new Common::MemoryReadStream(newData, dataSize, DisposeAfterUse::YES);
//
@ -24,17 +45,21 @@ namespace Dragons {
delete msfData;
}
VabSound::VabSound(Common::SeekableReadStream *vhData, Common::SeekableReadStream *vbData): _vbData(vbData) {
VabSound::VabSound(Common::SeekableReadStream *vhData, Common::SeekableReadStream *vbData): _toneAttrs(NULL), _vbData(NULL) {
loadHeader(vhData);
assert(vhData->pos() == vhData->size());
_vbData = new byte[vbData->size()];
vbData->read(_vbData, vbData->size());
delete vhData;
delete vbData;
}
void VabSound::loadHeader(Common::SeekableReadStream *vhData) {
vhData->seek(0);
vhData->read(&_header, sizeof(_header));
vhData->read(&_header, sizeof(_header)); //TODO this is not endian safe!
if (strncmp(_header.magic, "pBAV", 4) != 0) {
error("Invalid VAB file");
}
@ -60,8 +85,20 @@ namespace Dragons {
delete _vbData;
}
void VabSound::playSound(uint16 program, uint16 key) {
Audio::AudioStream *VabSound::getAudioStream(uint16 program, uint16 key) {
assert(program < _header.numVAG);
// TODO
debug("Playing program %d, key %d", program, key);
uint16 vagID = 0;
for (int i = 0; i < _header.numPrograms * 16; i++) {
if (_toneAttrs[i].prog == program) {
vagID = _toneAttrs[i].vag;
}
}
debug("Playing program %d, numTones: %d, key %d vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, key, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
Audio::AudioStream *str = Audio::makeXAStream(
new Common::MemoryReadStream(&_vbData[_vagOffsets[vagID]], _vagSizes[vagID], DisposeAfterUse::NO),
11025,
DisposeAfterUse::YES);
return str;
}
} // End of namespace Dragons

View File

@ -1,6 +1,24 @@
//
// Created by Edu García on 2019-07-25.
//
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef DRAGONS_VABSOUND_H
#define DRAGONS_VABSOUND_H
@ -11,6 +29,10 @@ namespace Common {
class SeekableReadStream;
}
namespace Audio {
class AudioStream;
}
namespace Dragons {
class DragonsEngine;
@ -88,10 +110,10 @@ public:
~VabSound();
void playSound(uint16 program, uint16 key);
Audio::AudioStream *getAudioStream(uint16 program, uint16 key);
private:
Common::SeekableReadStream *_vbData;
byte *_vbData;
VabHeader _header;
VabProgramAttr _programAttrs[128];
@ -105,4 +127,4 @@ private:
} // End of namespace Dragons
#endif //SCUMMVM_VABSOUND_H
#endif //DRAGONS_VABSOUND_H

View File

@ -383,7 +383,9 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
auto key = ((realId & 0xfu) << 1u | 0x40u);
// TODO: Volume
vabSound->playSound(program, key);
if (!_vm->_mixer->isSoundHandleActive(_sfxHandle)) {
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, vabSound->getAudioStream(program, key));
}
}
void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
@ -391,6 +393,7 @@ void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
auto vabId = getVabFromSoundId(soundId);
// TODO: Actually stop sound
_vm->_mixer->stopHandle(_sfxHandle);
}
uint16 SoundManager::getVabFromSoundId(uint16 soundId) {

View File

@ -62,6 +62,7 @@ private:
VabSound* _vabGlob;
Audio::SoundHandle _speechHandle;
Audio::SoundHandle _sfxHandle;
private:
void SomeInitSound_FUN_8003f64c();