DRAGONS: Fixed incorrect delete on PSX audio stream.

This commit is contained in:
Eric Fry 2020-05-14 23:58:01 +10:00
parent 29493de637
commit dd90652187
2 changed files with 33 additions and 35 deletions

View file

@ -89,18 +89,12 @@ void SoundManager::playSpeech(uint32 textIndex) {
error("Failed to open dtspeech.xa");
}
CdIntToPos_0(speechLocation.sectorStart * 32);
//TODO move the stream creation logic inside PSXAudioTrack.
fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset) * RAW_CD_SECTOR_SIZE);
PSXAudioTrack *_audioTrack = new PSXAudioTrack(fd, Audio::Mixer::kSpeechSoundType);
for (int i = 0x0; i < speechLocation.sectorEnd - speechLocation.sectorStart; i++) {
fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset + i * 32) * RAW_CD_SECTOR_SIZE);
_audioTrack->queueAudioFromSector(fd);
}
_audioTrack->getAudioStream()->finish();
PSXAudioTrack *_audioTrack = new PSXAudioTrack();
_vm->setFlags(ENGINE_FLAG_8000);
_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->createNewAudioStream(fd, speechLocation.sectorStart, speechLocation.startOffset, speechLocation.sectorEnd), -1, _speechVolume);
fd->close();
delete fd;
_vm->setFlags(ENGINE_FLAG_8000);
_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->getAudioStream(), -1, _speechVolume);
delete _audioTrack;
}
@ -146,20 +140,10 @@ void SoundManager::PauseCDMusic() {
}
}
SoundManager::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) {
sector->skip(19);
byte format = sector->readByte();
bool stereo = (format & (1 << 0)) != 0;
uint rate = (format & (1 << 2)) ? 18900 : 37800;
_audStream = Audio::makeQueuingAudioStream(rate, stereo);
SoundManager::PSXAudioTrack::PSXAudioTrack() {
memset(&_adpcmStatus, 0, sizeof(_adpcmStatus));
}
SoundManager::PSXAudioTrack::~PSXAudioTrack() {
delete _audStream;
}
// Ha! It's palindromic!
#define AUDIO_DATA_CHUNK_SIZE 2304
#define AUDIO_DATA_SAMPLE_COUNT 4032
@ -172,7 +156,7 @@ static const int s_xaTable[5][2] = {
{ 122, -60 }
};
void SoundManager::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStream *sector) {
void SoundManager::PSXAudioTrack::queueAudioFromSector(Audio::QueuingAudioStream *audStream, Common::SeekableReadStream *sector) {
sector->skip(24);
// This XA audio is different (yet similar) from normal XA audio! Watch out!
@ -183,7 +167,7 @@ void SoundManager::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStrea
byte *buf = new byte[AUDIO_DATA_CHUNK_SIZE];
sector->read(buf, AUDIO_DATA_CHUNK_SIZE);
int channels = _audStream->isStereo() ? 2 : 1;
int channels = audStream->isStereo() ? 2 : 1;
int16 *dst = new int16[AUDIO_DATA_SAMPLE_COUNT];
int16 *leftChannel = dst;
int16 *rightChannel = dst + 1;
@ -246,17 +230,33 @@ void SoundManager::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStrea
int flags = Audio::FLAG_16BITS;
if (_audStream->isStereo())
if (audStream->isStereo())
flags |= Audio::FLAG_STEREO;
#ifdef SCUMM_LITTLE_ENDIAN
flags |= Audio::FLAG_LITTLE_ENDIAN;
#endif
_audStream->queueBuffer((byte *)dst, AUDIO_DATA_SAMPLE_COUNT * 2, DisposeAfterUse::YES, flags);
audStream->queueBuffer((byte *)dst, AUDIO_DATA_SAMPLE_COUNT * 2, DisposeAfterUse::YES, flags);
delete[] buf;
}
Audio::QueuingAudioStream *SoundManager::PSXAudioTrack::createNewAudioStream(Common::File *fd, uint16 sectorStart, int8 startOffset, uint16 sectorEnd) {
fd->seek(((sectorStart * 32) + startOffset) * RAW_CD_SECTOR_SIZE);
fd->skip(19);
byte format = fd->readByte();
bool stereo = (format & (1 << 0)) != 0;
uint rate = (format & (1 << 2)) ? 18900 : 37800;
Audio::QueuingAudioStream *audStream = Audio::makeQueuingAudioStream(rate, stereo);
for (int i = 0x0; i < sectorEnd - sectorStart; i++) {
fd->seek(((sectorStart * 32) + startOffset + i * 32) * RAW_CD_SECTOR_SIZE);
queueAudioFromSector(audStream, fd);
}
audStream->finish();
return audStream;
}
SoundManager::SoundManager(DragonsEngine *vm, BigfileArchive *bigFileArchive, DragonRMS *dragonRMS)
: _vm(vm),
_bigFileArchive(bigFileArchive),

View file

@ -100,20 +100,18 @@ private:
private:
class PSXAudioTrack {
public:
PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
~PSXAudioTrack();
void queueAudioFromSector(Common::SeekableReadStream *sector);
Audio::QueuingAudioStream *getAudioStream() {
return _audStream;
}
private:
Audio::QueuingAudioStream *_audStream;
struct ADPCMStatus {
int16 sample[2];
} _adpcmStatus[2];
public:
PSXAudioTrack();
Audio::QueuingAudioStream *createNewAudioStream(Common::File *fd, uint16 sectorStart, int8 startOffset, uint16 sectorEnd);
private:
void queueAudioFromSector(Audio::QueuingAudioStream *audStream, Common::SeekableReadStream *sector);
};
};