Add voice channel tracking to stop script race in BumpusVille VR.

svn-id: r4048
This commit is contained in:
James Brown 2002-04-22 08:16:16 +00:00
parent d0d3316634
commit d447f05709
5 changed files with 49 additions and 28 deletions

View file

@ -1652,6 +1652,7 @@ void Scumm::o6_isSoundRunning()
int snd = pop(); int snd = pop();
if (snd) if (snd)
snd = isSoundRunning(snd); snd = isSoundRunning(snd);
push(snd); push(snd);
} }
@ -2328,6 +2329,8 @@ void Scumm::o6_wait()
return; return;
} }
case 169: case 169:
//printf("waiting for message: %d\n", _vars[VAR_HAVE_MSG]);
if (_vars[VAR_HAVE_MSG]) if (_vars[VAR_HAVE_MSG])
break; break;
return; return;
@ -2342,6 +2345,7 @@ void Scumm::o6_wait()
return; return;
case 171: case 171:
printf("wait for sentence");
if (_sentenceNum) { if (_sentenceNum) {
if (sentence[_sentenceNum - 1].unk && if (sentence[_sentenceNum - 1].unk &&
!isScriptInUse(_vars[VAR_SENTENCE_SCRIPT])) !isScriptInUse(_vars[VAR_SENTENCE_SCRIPT]))

View file

@ -1002,10 +1002,10 @@ public:
void clearSoundQue(); void clearSoundQue();
void talkSound(uint32 a, uint32 b, int mode); void talkSound(uint32 a, uint32 b, int mode);
void processSfxQueues(); void processSfxQueues();
void startTalkSound(uint32 a, uint32 b, int mode); int startTalkSound(uint32 a, uint32 b, int mode);
void stopTalkSound(); void stopTalkSound();
bool isMouthSyncOff(uint pos); bool isMouthSyncOff(uint pos);
void startSfxSound(void *file, int size); int startSfxSound(void *file, int size);
void *openSfxFile(); void *openSfxFile();
void addSoundToQueue(int sound); void addSoundToQueue(int sound);
void addSoundToQueue2(int sound); void addSoundToQueue2(int sound);
@ -1016,10 +1016,11 @@ public:
void pauseSounds(bool pause); void pauseSounds(bool pause);
bool isSfxFinished(); bool isSfxFinished();
void playBundleSound(char *sound); void playBundleSound(char *sound);
void playSfxSound(void *sound, uint32 size, uint rate); int playSfxSound(void *sound, uint32 size, uint rate);
void playSfxSound_MP3(void *sound, uint32 size); void playSfxSound_MP3(void *sound, uint32 size);
void stopSfxSound(); void stopSfxSound();
int _talkChannel; /* Mixer channel actor is talking on */
bool _useTalkAnims; bool _useTalkAnims;
uint16 _defaultTalkDelay; uint16 _defaultTalkDelay;
byte _haveMsg; byte _haveMsg;

View file

@ -128,13 +128,22 @@ void Scumm::processSfxQueues()
bool b, finished; bool b, finished;
if (_talk_sound_mode != 0) { if (_talk_sound_mode != 0) {
startTalkSound(_talk_sound_a, _talk_sound_b, _talk_sound_mode); if (_talk_sound_mode == 2)
_talkChannel = startTalkSound(_talk_sound_a, _talk_sound_b, _talk_sound_mode);
else
startTalkSound(_talk_sound_a, _talk_sound_b, _talk_sound_mode);
_talk_sound_mode = 0; _talk_sound_mode = 0;
} }
if (_sfxMode == 2) { if (_vars[VAR_TALK_ACTOR]) { //_sfxMode == 2) {
act = _vars[VAR_TALK_ACTOR]; act = _vars[VAR_TALK_ACTOR];
finished = isSfxFinished(); if (_talkChannel < 0)
finished = false;
else if (this->_mixer->_channels[_talkChannel] == NULL)
finished = true;
else
finished = false;
if (act != 0 && (uint) act < 0x80 && !string[0].no_talk_anim) { if (act != 0 && (uint) act < 0x80 && !string[0].no_talk_anim) {
a = derefActorSafe(act, "processSfxQueues"); a = derefActorSafe(act, "processSfxQueues");
@ -148,11 +157,15 @@ void Scumm::processSfxQueues()
} }
} }
} }
if (finished && _talkDelay == 0) {
if (finished && _talkDelay == 0) {
stopTalk(); stopTalk();
_sfxMode = 0; _sfxMode = 0;
_talkChannel = -1;
} }
} else if (_sfxMode == 1) { }
if (_sfxMode == 1) {
if (isSfxFinished()) { if (isSfxFinished()) {
_sfxMode = 0; _sfxMode = 0;
} }
@ -167,7 +180,7 @@ static int compar(const void *a, const void *b)
} }
#endif #endif
void Scumm::startTalkSound(uint32 offset, uint32 b, int mode) int Scumm::startTalkSound(uint32 offset, uint32 b, int mode)
{ {
int num = 0, i; int num = 0, i;
byte file_byte, file_byte_2; byte file_byte, file_byte_2;
@ -175,7 +188,7 @@ void Scumm::startTalkSound(uint32 offset, uint32 b, int mode)
if (!_sfxFile) { if (!_sfxFile) {
warning("startTalkSound: SFX file is not open"); warning("startTalkSound: SFX file is not open");
return; return -1;
} }
if (b > 8) { if (b > 8) {
@ -220,7 +233,7 @@ void Scumm::startTalkSound(uint32 offset, uint32 b, int mode)
_curSoundPos = 0; _curSoundPos = 0;
_mouthSyncMode = true; _mouthSyncMode = true;
startSfxSound(_sfxFile, size); return startSfxSound(_sfxFile, size);
} }
void Scumm::stopTalkSound() void Scumm::stopTalkSound()
@ -409,7 +422,7 @@ enum {
}; };
void Scumm::startSfxSound(void *file, int file_size) int Scumm::startSfxSound(void *file, int file_size)
{ {
char ident[8]; char ident[8];
int block_type; int block_type;
@ -441,13 +454,13 @@ void Scumm::startSfxSound(void *file, int file_size)
} else { } else {
invalid:; invalid:;
warning("startSfxSound: invalid header"); warning("startSfxSound: invalid header");
return; return -1;
} }
block_type = getc((FILE *) file); block_type = getc((FILE *) file);
if (block_type != 1) { if (block_type != 1) {
warning("startSfxSound: Expecting block_type == 1, got %d", block_type); warning("startSfxSound: Expecting block_type == 1, got %d", block_type);
return; return -1;
} }
fread(work, 3, 1, (FILE *) file); fread(work, 3, 1, (FILE *) file);
@ -458,19 +471,19 @@ void Scumm::startSfxSound(void *file, int file_size)
if (comp != 0) { if (comp != 0) {
warning("startSfxSound: Unsupported compression type %d", comp); warning("startSfxSound: Unsupported compression type %d", comp);
return; return -1;
} }
data = (byte *)malloc(size); data = (byte *)malloc(size);
if (data == NULL) { if (data == NULL) {
error("startSfxSound: out of memory"); error("startSfxSound: out of memory");
return; return -1;
} }
if (fread(data, size, 1, (FILE *) file) != 1) { if (fread(data, size, 1, (FILE *) file) != 1) {
/* no need to free the memory since error will shut down */ /* no need to free the memory since error will shut down */
error("startSfxSound: cannot read %d bytes", size); error("startSfxSound: cannot read %d bytes", size);
return; return -1;
} }
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
// Fixme: From WinCE port // Fixme: From WinCE port
@ -479,7 +492,7 @@ void Scumm::startSfxSound(void *file, int file_size)
data[i] ^= 0x80; data[i] ^= 0x80;
} }
playSfxSound(data, size, 1000000 / (256 - rate)); return playSfxSound(data, size, 1000000 / (256 - rate));
} }
@ -584,11 +597,11 @@ void Scumm::playBundleSound(char *sound)
warning("playBundleSound: %s", sound); warning("playBundleSound: %s", sound);
} }
void Scumm::playSfxSound(void *sound, uint32 size, uint rate) int Scumm::playSfxSound(void *sound, uint32 size, uint rate)
{ {
if (_soundsPaused) if (_soundsPaused)
return; return -1;
_mixer->play_raw(NULL, sound, size, rate, SoundMixer::FLAG_AUTOFREE); return _mixer->play_raw(NULL, sound, size, rate, SoundMixer::FLAG_AUTOFREE);
} }
void Scumm::playSfxSound_MP3(void *sound, uint32 size) void Scumm::playSfxSound_MP3(void *sound, uint32 size)

View file

@ -38,24 +38,26 @@ void SoundMixer::uninsert(Channel *chan) {
error("SoundMixer::channel_deleted chan not found"); error("SoundMixer::channel_deleted chan not found");
} }
void SoundMixer::insert(PlayingSoundHandle *handle, Channel *chan) { int SoundMixer::insert(PlayingSoundHandle *handle, Channel *chan) {
for(int i=0; i!=NUM_CHANNELS; i++) { for(int i=0; i!=NUM_CHANNELS; i++) {
if (_channels[i] == NULL) { if (_channels[i] == NULL) {
_channels[i] = chan; _channels[i] = chan;
_handles[i] = handle; _handles[i] = handle;
if (handle) if (handle)
*handle = i + 1; *handle = i + 1;
return; return i;
} }
} }
warning("SoundMixer::insert out of mixer slots"); warning("SoundMixer::insert out of mixer slots");
chan->destroy(); chan->destroy();
return -1;
} }
void SoundMixer::play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags) { int SoundMixer::play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags) {
insert(handle, new Channel_RAW(this, sound, size, rate, flags)); return insert(handle, new Channel_RAW(this, sound, size, rate, flags));
} }
#ifdef COMPRESSED_SOUND_FILE #ifdef COMPRESSED_SOUND_FILE
@ -202,8 +204,9 @@ void SoundMixer::Channel_RAW::mix(int16 *data, uint len) {
free(s_org); free(s_org);
} }
if (!_size) if (_size < 1)
destroy(); destroy();
} }
void SoundMixer::Channel_RAW::destroy() { void SoundMixer::Channel_RAW::destroy() {

View file

@ -115,7 +115,7 @@ public:
Channel *_channels[NUM_CHANNELS]; Channel *_channels[NUM_CHANNELS];
PlayingSoundHandle *_handles[NUM_CHANNELS]; PlayingSoundHandle *_handles[NUM_CHANNELS];
void insert(PlayingSoundHandle *handle, Channel *chan); int insert(PlayingSoundHandle *handle, Channel *chan);
void uninsert(Channel *chan); void uninsert(Channel *chan);
/* start playing a raw sound */ /* start playing a raw sound */
@ -124,7 +124,7 @@ public:
FLAG_UNSIGNED = 2, /* unsigned samples */ FLAG_UNSIGNED = 2, /* unsigned samples */
FLAG_FILE = 4, /* sound is a FILE * that's read from */ FLAG_FILE = 4, /* sound is a FILE * that's read from */
}; };
void play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags); int play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags);
#ifdef COMPRESSED_SOUND_FILE #ifdef COMPRESSED_SOUND_FILE
void play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags); void play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
void play_mp3_cdtrack(PlayingSoundHandle *handle, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration); void play_mp3_cdtrack(PlayingSoundHandle *handle, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration);