Clean up narator sound logic

Also this provides a helper function for calculating the length of a
sound
This commit is contained in:
Anders Jenbo 2021-01-24 07:08:11 +01:00
commit 88a715cdcc
7 changed files with 74 additions and 103 deletions

View file

@ -11,10 +11,8 @@ DEVILUTION_BEGIN_NAMESPACE
int sfxdelay;
int sfxdnum;
/** A handle to the current sound effect playing. */
HANDLE sghStream;
/** Specifies the sound file and the playback state of the current sound effect. */
TSFX *sgpStreamSFX;
static TSFX *sgpStreamSFX = NULL;
/**
* Monster sound type prefix
@ -1069,11 +1067,10 @@ BOOL effect_is_playing(int nSFX)
void stream_stop()
{
if (sghStream) {
SFileDdaEnd(sghStream);
SFileCloseFile(sghStream);
SFileFreeChunk();
sghStream = NULL;
if (sgpStreamSFX != NULL) {
sgpStreamSFX->pSnd->DSB->Stop();
sound_file_cleanup(sgpStreamSFX->pSnd);
sgpStreamSFX->pSnd = NULL;
sgpStreamSFX = NULL;
}
}
@ -1089,23 +1086,16 @@ static void stream_play(TSFX *pSFX, int lVolume, int lPan)
if (lVolume >= VOLUME_MIN) {
if (lVolume > VOLUME_MAX)
lVolume = VOLUME_MAX;
success = SFileOpenFile(pSFX->pszName, &sghStream);
if (!success) {
sghStream = NULL;
} else {
if (!SFileDdaBeginEx(sghStream, 0x40000, 0, 0, lVolume, lPan, 0))
stream_stop();
else
sgpStreamSFX = pSFX;
}
if (pSFX->pSnd == NULL)
pSFX->pSnd = sound_file_load(pSFX->pszName);
pSFX->pSnd->DSB->Play(lVolume, lPan, 0);
sgpStreamSFX = pSFX;
}
}
static void stream_update()
{
DWORD current, end;
if (sghStream != NULL && SFileDdaGetPos(sghStream, &current, &end) && current >= end) {
if (sgpStreamSFX != NULL && !sgpStreamSFX->pSnd->DSB->IsPlaying()) {
stream_stop();
}
}
@ -1410,4 +1400,11 @@ void effects_play_sound(const char *snd_file)
}
}
int GetSFXLength(int nSFX)
{
if (sgSFX[nSFX].pSnd == NULL)
sgSFX[nSFX].pSnd = sound_file_load(sgSFX[nSFX].pszName);
return sgSFX[nSFX].pSnd->DSB->GetLength();
}
DEVILUTION_END_NAMESPACE