Rewrote music playback to be more sensible. Hopefully this will get rid of the crashes that the handful of people reported. Needs to be fully tested.

Also, not sure what to do re: map screen. OG seems to keep playing the currently playing track, which seems slightly janky? should we just play track 19?

# Conflicts:
#	source/exhumed/src/cd.cpp
#	source/exhumed/src/cd.h
This commit is contained in:
sirlemonhead 2019-11-28 20:40:17 +00:00 committed by Christoph Oelckers
parent 115675417a
commit e115058cd3
7 changed files with 37 additions and 78 deletions

View file

@ -31,28 +31,14 @@ BEGIN_PS_NS
extern short word_9AC30; extern short word_9AC30;
static char *pTrack = NULL; static char *pTrack = NULL;
int trackhandle = -1; static int trackhandle = -1;
int nLastVolumeSet = 0; int nLastVolumeSet = 0;
/* TODO
int cd_check_device_present() Currently playing music must keep playing on return to map screen or exit from training level
{
return 1;
}
int initcdaudio() */
{
if (!cd_check_device_present())
{
word_9AC30 = 1;
// return to text video mode
initprintf("No MSCDEX driver installed!\n");
exit(0);
}
return 1;
}
void setCDaudiovolume(int val) void setCDaudiovolume(int val)
{ {
@ -61,13 +47,13 @@ void setCDaudiovolume(int val)
} }
} }
int playCDtrack(int nTrack) bool playCDtrack(int nTrack, bool bLoop)
{ {
if (nTrack < 2) { if (nTrack < 2) {
return 0; return false;
} }
nCDTrackLength = 0; StopCD();
char filename[128]; char filename[128];
@ -80,7 +66,7 @@ int playCDtrack(int nTrack)
sprintf(filename, "exhumed%02d.ogg", nTrack); sprintf(filename, "exhumed%02d.ogg", nTrack);
hFile = kopen4load(filename, 0); hFile = kopen4load(filename, 0);
if (hFile < 0) { if (hFile < 0) {
return 0; return false;
} }
} }
@ -91,7 +77,7 @@ int playCDtrack(int nTrack)
{ {
OSD_Printf("Error allocating music track data memory for %s", filename); OSD_Printf("Error allocating music track data memory for %s", filename);
kclose(hFile); kclose(hFile);
return 0; return false;
} }
int nRead = kread(hFile, pTrack, nFileLen); int nRead = kread(hFile, pTrack, nFileLen);
@ -101,12 +87,12 @@ int playCDtrack(int nTrack)
Xaligned_free(pTrack); Xaligned_free(pTrack);
pTrack = NULL; pTrack = NULL;
kclose(hFile); kclose(hFile);
return 0; return false;
} }
kclose(hFile); kclose(hFile);
trackhandle = FX_Play(pTrack, nRead, -1, 0, 0, 255, 255, 255, FX_MUSIC_PRIORITY, fix16_one, MUSIC_ID); trackhandle = FX_Play(pTrack, nRead, bLoop ? 0 : -1, 0, 0, 255, 255, 255, FX_MUSIC_PRIORITY, fix16_one, MUSIC_ID);
if (trackhandle <= FX_Ok) if (trackhandle <= FX_Ok)
{ {
OSD_Printf("Error playing music track %s", filename); OSD_Printf("Error playing music track %s", filename);
@ -115,14 +101,12 @@ int playCDtrack(int nTrack)
Xaligned_free(pTrack); Xaligned_free(pTrack);
pTrack = NULL; pTrack = NULL;
} }
return 0; return false;
} }
setCDaudiovolume(gMusicVolume); setCDaudiovolume(gMusicVolume);
nCDTrackLength = 1; return true;
return nCDTrackLength;
} }
void StartfadeCDaudio() void StartfadeCDaudio()
@ -157,13 +141,13 @@ int StepFadeCDaudio()
return 1; return 1;
} }
int CDplaying() bool CDplaying()
{ {
if (trackhandle > 0 && pTrack) { // better way to do this? if (trackhandle <= 0) {
return 1; return false;
} }
else { else {
return 0; return FX_SoundActive(trackhandle);
} }
} }
@ -174,8 +158,6 @@ void StopCD()
trackhandle = -1; trackhandle = -1;
} }
nCDTrackLength = 0;
if (pTrack) if (pTrack)
{ {
Xaligned_free(pTrack); Xaligned_free(pTrack);

View file

@ -20,15 +20,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define __cd_h__ #define __cd_h__
BEGIN_PS_NS BEGIN_PS_NS
extern int trackhandle;
int initcdaudio();
void setCDaudiovolume(int val); void setCDaudiovolume(int val);
int playCDtrack(int nTrack); bool playCDtrack(int nTrack, bool bLoop);
void StartfadeCDaudio(); void StartfadeCDaudio();
int StepFadeCDaudio(); int StepFadeCDaudio();
int CDplaying(); bool CDplaying();
void StopCD(); void StopCD();
END_PS_NS END_PS_NS

View file

@ -738,15 +738,9 @@ short nCurBodyNum = 0;
short nBodyTotal = 0; short nBodyTotal = 0;
short textpages; short textpages;
short nCDTrackLength = 0;
short lastfps; short lastfps;
short nCDTracks = 0;
short nMapMode = 0; short nMapMode = 0;
short bNoCreatures = kFalse; short bNoCreatures = kFalse;
@ -873,13 +867,11 @@ void timerhandler()
scan_char = 0; scan_char = 0;
lastfps = fps; lastfps = fps;
fps = 0; fps = 0;
// if (nCDTrackLength > 0) {
// nCDTrackLength--;
// }
} }
if (!bInMove)
if (!bInMove) {
OSD_DispatchQueued(); OSD_DispatchQueued();
}
} }
void HandleAsync() void HandleAsync()
@ -1338,7 +1330,7 @@ void DoCredits()
{ {
NoClip(); NoClip();
playCDtrack(19); playCDtrack(19, false);
int var_20 = 0; int var_20 = 0;
@ -1976,7 +1968,6 @@ int app_main(int argc, char const* const* argv)
} }
ResetPassword(); ResetPassword();
nCDTracks = initcdaudio();
// GetCurPal(NULL); // GetCurPal(NULL);
@ -2284,7 +2275,7 @@ LOOP3:
lPlayerXVel = 0; lPlayerXVel = 0;
lPlayerYVel = 0; lPlayerYVel = 0;
movefifopos = movefifoend; movefifopos = movefifoend;
// nCDTrackLength = 0;
RefreshStatus(); RefreshStatus();
if (bSerialPlay) { if (bSerialPlay) {
@ -2306,19 +2297,16 @@ LOOP3:
HandleAsync(); HandleAsync();
OSD_DispatchQueued(); OSD_DispatchQueued();
// Section B // Section B
if (!nCDTrackLength && !nFreeze && !nNetPlayerCount) if (!CDplaying() && !nFreeze && !nNetPlayerCount)
{ {
int nTrack = levelnum; int nTrack = levelnum;
if (nTrack != 0) { if (nTrack != 0) {
nTrack--; nTrack--;
} }
nCDTrackLength = playCDtrack((nTrack % 8) + 11); playCDtrack((nTrack % 8) + 11, true);
if (!nCDTrackLength) {
nCDTrackLength = -1;
}
} }
// TODO CONTROL_GetButtonInput(); // TODO CONTROL_GetButtonInput();
@ -2714,13 +2702,12 @@ void DoTitle()
EraseScreen(4); EraseScreen(4);
playCDtrack(19); playCDtrack(19, true);
videoNextPage(); videoNextPage();
FadeIn(); FadeIn();
WaitVBL(); WaitVBL();
int String_Copyright = FindGString("COPYRIGHT"); int String_Copyright = FindGString("COPYRIGHT");
const char *a = gString[String_Copyright]; const char *a = gString[String_Copyright];
@ -3103,9 +3090,7 @@ void InitSpiritHead()
nTrack = 7; nTrack = 7;
} }
nCDTrackLength = playCDtrack(nTrack); bSubTitles = playCDtrack(nTrack, false) == 0;
bSubTitles = nCDTrackLength == 0;
StartSwirlies(); StartSwirlies();

View file

@ -103,8 +103,6 @@ void HandleAsync();
extern int32_t g_commandSetup; extern int32_t g_commandSetup;
extern int32_t g_noSetup; extern int32_t g_noSetup;
extern short nCDTrackLength;
extern char sHollyStr[]; extern char sHollyStr[];
extern int localclock; extern int localclock;

View file

@ -1893,10 +1893,9 @@ void ReadyCinemaText(uint16_t nVal)
uint8_t AdvanceCinemaText() uint8_t AdvanceCinemaText()
{ {
int var_1C = nCDTrackLength;
int tmp = nHeight + nCrawlY > 0; int tmp = nHeight + nCrawlY > 0;
if (tmp || nCDTrackLength && nCDTrackLength > 0) if (tmp || CDplaying())
{ {
nextclock = (int)totalclock + 14; nextclock = (int)totalclock + 14;
@ -1928,7 +1927,7 @@ uint8_t AdvanceCinemaText()
break; break;
} }
if (var_1C || nCDTrackLength) if (CDplaying())
{ {
if (nextclock <= (int)totalclock) { if (nextclock <= (int)totalclock) {
return kTrue; return kTrue;
@ -2094,7 +2093,7 @@ void GoToTheCinema(int nVal)
fadecdaudio(); fadecdaudio();
} }
playCDtrack(edx + 2); // , 1); playCDtrack(edx + 2, false);
} }
DoCinemaText(ebx); DoCinemaText(ebx);
@ -2102,7 +2101,7 @@ void GoToTheCinema(int nVal)
FadeOut(kTrue); FadeOut(kTrue);
overwritesprite(0, 0, 764, 100, 2, kPalNormal); overwritesprite(0, 0, kMovieTile, 100, 2, kPalNormal);
videoNextPage(); videoNextPage();
GrabPalette(); GrabPalette();
@ -2169,7 +2168,7 @@ void DoFailedFinalScene()
fadecdaudio(); fadecdaudio();
} }
playCDtrack(9); playCDtrack(9, false);
FadeToWhite(); FadeToWhite();
GoToTheCinema(4); GoToTheCinema(4);

View file

@ -297,8 +297,6 @@ void CalcASSPan(int nPan, int nVolume, int *pLeft, int *pRight)
void ASSCallback(intptr_t num) void ASSCallback(intptr_t num)
{ {
if ((int32_t)num == MUSIC_ID) { if ((int32_t)num == MUSIC_ID) {
trackhandle = -1;
StopCD();
return; return;
} }
@ -1181,7 +1179,7 @@ void StopAllSounds(void)
for (int i = 0; i < kMaxActiveSounds; i++) for (int i = 0; i < kMaxActiveSounds; i++)
{ {
if (sActiveSound[i].f_e >= 0 && sActiveSound[i].f_e != trackhandle) if (sActiveSound[i].f_e >= 0)
FX_StopSound(sActiveSound[i].f_e); FX_StopSound(sActiveSound[i].f_e);
// AIL_end_sample(sActiveSound[i].f_e); // AIL_end_sample(sActiveSound[i].f_e);
} }

View file

@ -596,8 +596,9 @@ void DrawView(int smoothRatio)
I_AdvanceTriggerClear(); I_AdvanceTriggerClear();
levelnew = levelnum + 1; levelnew = levelnum + 1;
if (CDplaying()) if (CDplaying()) {
fadecdaudio(); fadecdaudio();
}
} }
videoSetViewableArea(nViewLeft, nViewTop, nViewRight, nViewBottom); videoSetViewableArea(nViewLeft, nViewTop, nViewRight, nViewBottom);