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;
static char *pTrack = NULL;
int trackhandle = -1;
static int trackhandle = -1;
int nLastVolumeSet = 0;
/* TODO
int cd_check_device_present()
{
return 1;
}
Currently playing music must keep playing on return to map screen or exit from training level
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)
{
@ -61,13 +47,13 @@ void setCDaudiovolume(int val)
}
}
int playCDtrack(int nTrack)
bool playCDtrack(int nTrack, bool bLoop)
{
if (nTrack < 2) {
return 0;
return false;
}
nCDTrackLength = 0;
StopCD();
char filename[128];
@ -80,7 +66,7 @@ int playCDtrack(int nTrack)
sprintf(filename, "exhumed%02d.ogg", nTrack);
hFile = kopen4load(filename, 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);
kclose(hFile);
return 0;
return false;
}
int nRead = kread(hFile, pTrack, nFileLen);
@ -101,12 +87,12 @@ int playCDtrack(int nTrack)
Xaligned_free(pTrack);
pTrack = NULL;
kclose(hFile);
return 0;
return false;
}
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)
{
OSD_Printf("Error playing music track %s", filename);
@ -115,14 +101,12 @@ int playCDtrack(int nTrack)
Xaligned_free(pTrack);
pTrack = NULL;
}
return 0;
return false;
}
setCDaudiovolume(gMusicVolume);
nCDTrackLength = 1;
return nCDTrackLength;
return true;
}
void StartfadeCDaudio()
@ -157,13 +141,13 @@ int StepFadeCDaudio()
return 1;
}
int CDplaying()
bool CDplaying()
{
if (trackhandle > 0 && pTrack) { // better way to do this?
return 1;
if (trackhandle <= 0) {
return false;
}
else {
return 0;
return FX_SoundActive(trackhandle);
}
}
@ -174,8 +158,6 @@ void StopCD()
trackhandle = -1;
}
nCDTrackLength = 0;
if (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__
BEGIN_PS_NS
extern int trackhandle;
int initcdaudio();
void setCDaudiovolume(int val);
int playCDtrack(int nTrack);
bool playCDtrack(int nTrack, bool bLoop);
void StartfadeCDaudio();
int StepFadeCDaudio();
int CDplaying();
bool CDplaying();
void StopCD();
END_PS_NS

View file

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

View file

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

View file

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

View file

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

View file

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