Check sound queue for music in HE games.

Avoid extra sound channel.

svn-id: r16706
This commit is contained in:
Travis Howell 2005-01-30 11:03:49 +00:00
parent 0199bf70fe
commit bebad400d6
10 changed files with 36 additions and 40 deletions

View file

@ -211,7 +211,6 @@ void ScummEngine::akos_decodeData(Actor *a, int frame, uint usemask) {
while (size--) {
if (READ_LE_UINT32(akst) == 0) {
a->cost.seq3[i] = READ_LE_UINT32(akst + 4);
akst += 8;
found = true;
break;
}
@ -243,7 +242,6 @@ void ScummEngine::akos_decodeData(Actor *a, int frame, uint usemask) {
if (READ_LE_UINT16(aksf) == start) {
a->cost.seq1[i] = READ_LE_UINT16(aksf + 2);
a->cost.seq2[i] = READ_LE_UINT16(aksf + 4);
aksf += 6;
found = true;
break;
}
@ -268,7 +266,6 @@ void ScummEngine::akos_decodeData(Actor *a, int frame, uint usemask) {
while (size--) {
if (READ_LE_UINT32(akst) == start) {
a->cost.seq3[i] = READ_LE_UINT32(akst + 4);
akst += 8;
found = true;
break;
}

View file

@ -759,7 +759,7 @@ protected:
void o72_captureWizImage();
void o72_getTimer();
void o72_setTimer();
void o72_unknown5A();
void o72_getSoundElapsedTimeOfSound();
void o72_startScript();
void o72_startObject();
void o72_drawObject();

View file

@ -311,7 +311,7 @@ void ScummEngine_v100he::setupOpcodes() {
OPCODE(o6_isScriptRunning),
OPCODE(o90_sin),
/* D8 */
OPCODE(o72_unknown5A),
OPCODE(o72_getSoundElapsedTimeOfSound),
OPCODE(o6_isSoundRunning),
OPCODE(o80_getSoundVar),
OPCODE(o100_unknown25),

View file

@ -155,7 +155,7 @@ void ScummEngine_v72he::setupOpcodes() {
/* 58 */
OPCODE(o72_getTimer),
OPCODE(o72_setTimer),
OPCODE(o72_unknown5A),
OPCODE(o72_getSoundElapsedTimeOfSound),
OPCODE(o6_wordArrayDec),
/* 5C */
OPCODE(o6_if),
@ -714,13 +714,10 @@ void ScummEngine_v72he::o72_setTimer() {
}
}
void ScummEngine_v72he::o72_unknown5A() {
// Seems to get length of sound already played
void ScummEngine_v72he::o72_getSoundElapsedTimeOfSound() {
int snd = pop();
int r = _mixer->getSoundElapsedTime(_sound->_musicChannelHandle);
push(r * 10);
debug(1,"o72_unknown5A stub (%d)", snd);
push(_mixer->getSoundElapsedTimeOfSoundID(snd) * 10);
debug(1,"o72_getSoundElapsedTimeOfSound (%d)", snd);
}
void ScummEngine_v72he::o72_startScript() {

View file

@ -153,7 +153,7 @@ void ScummEngine_v80he::setupOpcodes() {
/* 58 */
OPCODE(o72_getTimer),
OPCODE(o72_setTimer),
OPCODE(o72_unknown5A),
OPCODE(o72_getSoundElapsedTimeOfSound),
OPCODE(o6_wordArrayDec),
/* 5C */
OPCODE(o6_if),

View file

@ -153,7 +153,7 @@ void ScummEngine_v90he::setupOpcodes() {
/* 58 */
OPCODE(o72_getTimer),
OPCODE(o72_setTimer),
OPCODE(o72_unknown5A),
OPCODE(o72_getSoundElapsedTimeOfSound),
OPCODE(o6_wordArrayDec),
/* 5C */
OPCODE(o6_if),

View file

@ -164,7 +164,6 @@ void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) {
int size = -1;
int rate;
byte flags = SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE;
bool music = false;
if (_vm->_heversion >= 70 && soundID > _vm->_numSounds) {
debug(0, "playSound #%d", soundID);
@ -199,16 +198,15 @@ void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) {
if (skip > tracks - 1)
skip = 0;
musicFile.seek(+28, SEEK_CUR);
if (musicFile.readUint32LE() == TO_LE_32(MKID('SGEN'))) {
if (_vm->_heversion >= 80) {
// Skip to offsets
musicFile.seek(+40, SEEK_CUR);
// Skip to correct music header
skip *= 21;
// Skip to offsets
musicFile.seek(+8, SEEK_CUR);
} else {
// Rewind
musicFile.seek(-28, SEEK_CUR);
// Skip to offsets
musicFile.seek(+4, SEEK_CUR);
// Skip to correct music header
skip *= 25;
@ -229,12 +227,10 @@ void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) {
musicFile.read(ptr, size);
musicFile.close();
_vm->_mixer->stopID(_currentMusic);
_currentMusic = soundID;
music = true;
if (_vm->_heversion == 70) {
// Allocate a sound buffer, copy the data into it, and play
_vm->_mixer->stopHandle(_musicChannelHandle);
_vm->_mixer->playRaw(&_musicChannelHandle, ptr, size, 11025, flags, soundID);
_vm->_mixer->playRaw(NULL, ptr, size, 11025, flags, soundID);
return;
}
} else {
@ -299,17 +295,11 @@ void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) {
}
// TODO: Set sound channel based on heChannel
if (heFlags & 1)
flags |= SoundMixer::FLAG_LOOP;
// Set sound looping based on heFlags
// Allocate a sound buffer, copy the data into it, and play
sound = (char *)malloc(size);
memcpy(sound, ptr + heOffset + 8, size);
if (music == true) {
_vm->_mixer->stopHandle(_musicChannelHandle);
_vm->_mixer->playRaw(&_musicChannelHandle, sound, size, rate, flags, soundID);
} else
_vm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
}
else if (READ_UINT32(ptr) == MKID('MRAW')) {
@ -325,9 +315,9 @@ void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) {
// Allocate a sound buffer, copy the data into it, and play
sound = (char *)malloc(size);
memcpy(sound, ptr + 8, size);
_vm->_mixer->stopID(_currentMusic);
_currentMusic = soundID;
_vm->_mixer->stopHandle(_musicChannelHandle);
_vm->_mixer->playRaw(&_musicChannelHandle, sound, size, rate, flags, soundID);
_vm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
}
// Support for sampled sound effects in Monkey Island 1 and 2
else if (READ_UINT32(ptr) == MKID('SBL ')) {
@ -673,7 +663,7 @@ void Sound::startTalkSound(uint32 offset, uint32 b, int mode, PlayingSoundHandle
_sfxFile->seek(offset + 32, SEEK_SET);
if (_sfxFile->readUint32LE() == TO_LE_32(MKID('SBNG'))) {
warning("startTalkSound: Skipped SBNG block");
debug(2, "startTalkSound: Skipped SBNG block");
// Skip the SBNG, so we end up at the SDAT chunk
extra = _sfxFile->readUint32BE();
_sfxFile->seek(extra - 4, SEEK_CUR);
@ -821,8 +811,8 @@ int Sound::isSoundRunning(int sound) const {
// getSoundStatus(), with a -1, will return the
// ID number of the first active music it finds.
if (_vm->_heversion >= 70 || _currentMusic)
return (_musicChannelHandle.isActive());
else if (_vm->_imuse)
sound = _currentMusic;
if (_vm->_imuse)
return (_vm->_imuse->getSoundStatus(sound));
}
}

View file

@ -85,7 +85,6 @@ protected:
int16 _currentMusic;
public:
PlayingSoundHandle _talkChannelHandle; // Handle of mixer channel actor is talking on
PlayingSoundHandle _musicChannelHandle; // Handle of mixer channel music is on
bool _soundsPaused;
byte _sfxMode;

View file

@ -333,6 +333,14 @@ void SoundMixer::setChannelBalance(PlayingSoundHandle handle, int8 balance) {
_channels[index]->setBalance(balance);
}
uint32 SoundMixer::getSoundElapsedTimeOfSoundID(int id) {
Common::StackLock lock(_mutex);
for (int i = 0; i != NUM_CHANNELS; i++)
if (_channels[i] && _channels[i]->getId() == id)
return _channels[i]->getElapsedTime();
return 0;
}
uint32 SoundMixer::getSoundElapsedTime(PlayingSoundHandle handle) {
Common::StackLock lock(_mutex);

View file

@ -232,6 +232,11 @@ public:
*/
void setChannelBalance(PlayingSoundHandle handle, int8 balance);
/**
* Get approximation of for how long the Sound ID has been playing.
*/
uint32 getSoundElapsedTimeOfSoundID(int id);
/**
* Get approximation of for how long the channel has been playing.
*/