Fixed inappropriate expiration of sound resources,

which fixes concurrency issues esp. in PocketPC and MorphOS.
Stubbed SysEx command 2 (start of song) to get rid of annoying warning.
Changed MT-32 instrument warnings to fit on one (80-char) line.

svn-id: r5842
This commit is contained in:
Jamieson Christian 2002-12-05 21:45:55 +00:00
parent 632f44a1a4
commit 50b69cb2db
5 changed files with 67 additions and 12 deletions

View File

@ -103,6 +103,7 @@ public:
int stop_sound(int sound) { in(); int ret = _target->stop_sound (sound); out(); return ret; } int stop_sound(int sound) { in(); int ret = _target->stop_sound (sound); out(); return ret; }
int stop_all_sounds() { in(); int ret = _target->stop_all_sounds(); out(); return ret; } int stop_all_sounds() { in(); int ret = _target->stop_all_sounds(); out(); return ret; }
int get_sound_status(int sound) { in(); int ret = _target->get_sound_status (sound); out(); return ret; } int get_sound_status(int sound) { in(); int ret = _target->get_sound_status (sound); out(); return ret; }
bool get_sound_active(int sound) { in(); bool ret = _target->get_sound_active (sound); out(); return ret; }
int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h) { in(); int32 ret = _target->do_command (a,b,c,d,e,f,g,h); out(); return ret; } int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h) { in(); int32 ret = _target->do_command (a,b,c,d,e,f,g,h); out(); return ret; }
int clear_queue() { in(); int ret = _target->clear_queue(); out(); return ret; } int clear_queue() { in(); int ret = _target->clear_queue(); out(); return ret; }
void setBase(byte **base) { in(); _target->setBase (base); out(); } void setBase(byte **base) { in(); _target->setBase (base); out(); }
@ -487,6 +488,7 @@ public:
int stop_sound(int sound); int stop_sound(int sound);
int stop_all_sounds(); int stop_all_sounds();
int get_sound_status(int sound); int get_sound_status(int sound);
bool get_sound_active(int sound);
int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h); int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h);
int clear_queue(); int clear_queue();
void setBase(byte **base); void setBase(byte **base);
@ -715,14 +717,14 @@ byte *IMuseInternal::findTag(int sound, char *tag, int index)
int32 size, pos; int32 size, pos;
if (_base_sounds) { if (_base_sounds) {
// FIXME: This is a hack to make certain parts of Sam & Max work. // The following hack was commented out because calling
// It's a NASTY HACK because it has to specifically skip sound 1. // ensureResourceLoaded() is not safe from within this
// For some reason (maybe a script parse bug?), sound 1 is being // function. TODO: Make sure all Sam & Max music still works
// played at the very beginning (opening logo). Until this "fix", // without this hack. It's very likely that changes to the
// the sound was never found and thus never played. It SHOULDN'T // resource expiration process solved whatever S&M problem
// be played. // this hack was originally intended to address.
if (!_base_sounds[sound] && (sound > 1 || g_scumm->_gameId != GID_SAMNMAX)) // if (!_base_sounds[sound] && (sound > 1 || g_scumm->_gameId != GID_SAMNMAX))
g_scumm->ensureResourceLoaded (rtSound, sound); // g_scumm->ensureResourceLoaded (rtSound, sound);
ptr = _base_sounds[sound]; ptr = _base_sounds[sound];
} }
@ -1162,6 +1164,21 @@ int IMuseInternal::get_sound_status(int sound)
return get_queue_sound_status(sound); return get_queue_sound_status(sound);
} }
// This is exactly the same as get_sound_status except that
// it treats sounds that are fading out just the same as
// other sounds. This is the method to use when determining
// what resources to expire from memory.
bool IMuseInternal::get_sound_active(int sound)
{
int i;
Player *player;
for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
if (player->_active && player->_id == (uint16)sound)
return 1;
}
return (get_queue_sound_status(sound) != 0);
}
int IMuseInternal::get_queue_sound_status(int sound) int IMuseInternal::get_queue_sound_status(int sound)
{ {
uint16 *a; uint16 *a;
@ -2266,11 +2283,11 @@ void Player::parse_sysex(byte *p, uint len)
return; return;
} }
} }
warning ("Could not find appropriate MT-32 program for GM program %d", (int) a); warning ("Could not map MT-32 \"%s\" to GM %d", buf, (int) a);
return; return;
} }
} }
warning ("Could not find appropriate GM program for MT-32 custom instrument \"%s\"", buf); warning ("MT-32 instrument \"%s\" not supported yet", buf);
} }
} else { } else {
warning ("Unknown SysEx manufacturer 0x%02X", (int) a); warning ("Unknown SysEx manufacturer 0x%02X", (int) a);
@ -2334,7 +2351,10 @@ void Player::parse_sysex(byte *p, uint len)
break; break;
maybe_jump (p[0], p[1] - 1, (read_word (p + 2) - 1) * 4 + p[4], ((p[5] * _ticks_per_beat) >> 2) + p[6]); maybe_jump (p[0], p[1] - 1, (read_word (p + 2) - 1) * 4 + p[4], ((p[5] * _ticks_per_beat) >> 2) + p[6]);
break; break;
case 2: // Start of song. Ignore for now.
break;
case 16: /* set instrument in part */ case 16: /* set instrument in part */
a = *p++ & 0x0F; a = *p++ & 0x0F;
if (_se->_hardware_type != *p++ && false) if (_se->_hardware_type != *p++ && false)

View File

@ -50,6 +50,7 @@ public:
virtual int stop_sound(int sound) = 0; virtual int stop_sound(int sound) = 0;
virtual int stop_all_sounds() = 0; virtual int stop_all_sounds() = 0;
virtual int get_sound_status(int sound) = 0; virtual int get_sound_status(int sound) = 0;
virtual bool get_sound_active(int sound) = 0;
virtual int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h) = 0; virtual int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h) = 0;
virtual int clear_queue() = 0; virtual int clear_queue() = 0;
virtual void setBase(byte **base) = 0; virtual void setBase(byte **base) = 0;

View File

@ -1356,7 +1356,7 @@ bool Scumm::isResourceInUse(int type, int i)
case rtCostume: case rtCostume:
return isCostumeInUse(i); return isCostumeInUse(i);
case rtSound: case rtSound:
return _sound->isSoundRunning(i) != 0; return _sound->isSoundActive(i);
default: default:
return false; return false;
} }

View File

@ -587,6 +587,39 @@ int Sound::isSoundRunning(int sound) {
return se->get_sound_status(sound); return se->get_sound_status(sound);
} }
// This is exactly the same as isSoundRunning except that it
// calls IMuse::get_sound_active() instead of IMuse::get_sound_status().
// This is necessary when determining what resources to
// expire from memory.
bool Sound::isSoundActive(int sound) {
IMuse *se;
int i;
if (sound == _scumm->current_cd_sound)
return pollCD() != 0;
i = _soundQue2Pos;
while (i--) {
if (_soundQue2[i] == sound)
return true;
}
if (isSoundInQueue(sound))
return true;
if (!_scumm->isResourceLoaded(rtSound, sound))
return false;
if (_scumm->_imuseDigital) {
return _scumm->_imuseDigital->getSoundStatus(sound) != 0;
}
se = _scumm->_imuse;
if (!se)
return false;
return se->get_sound_active(sound);
}
bool Sound::isSoundInQueue(int sound) { bool Sound::isSoundInQueue(int sound) {
int i = 0, j, num; int i = 0, j, num;
int16 table[16]; int16 table[16];

View File

@ -144,6 +144,7 @@ public:
void stopTalkSound(); void stopTalkSound();
bool isMouthSyncOff(uint pos); bool isMouthSyncOff(uint pos);
int isSoundRunning(int sound); int isSoundRunning(int sound);
bool isSoundActive(int sound);
bool isSoundInQueue(int sound); bool isSoundInQueue(int sound);
void stopSound(int a); void stopSound(int a);
void stopAllSounds(); void stopAllSounds();