Initial music playback support code

# Conflicts:
#	source/exhumed/src/cd.cpp
#	source/exhumed/src/cd.h
This commit is contained in:
sirlemonhead 2019-11-24 20:32:07 +00:00 committed by Christoph Oelckers
parent 28294c8a96
commit 326947d976
7 changed files with 117 additions and 13 deletions

View file

@ -16,9 +16,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#include "ns.h" #include "ns.h"
#include "build.h"
#include "compat.h" #include "compat.h"
#include "baselayer.h" #include "baselayer.h"
#include "cd.h" #include "cd.h"
#include "fx_man.h"
#include "sound.h"
#include "exhumed.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -26,6 +30,11 @@ BEGIN_PS_NS
extern short word_9AC30; extern short word_9AC30;
static char *pTrack = NULL;
int trackhandle = -1;
int nLastVolumeSet = 0;
int cd_check_device_present() int cd_check_device_present()
{ {
return 1; return 1;
@ -47,31 +56,113 @@ int initcdaudio()
void setCDaudiovolume(int val) void setCDaudiovolume(int val)
{ {
if (trackhandle > 0) {
FX_SetPan(trackhandle, val, val, val);
}
} }
int playCDtrack(int nTrack) int playCDtrack(int nTrack)
{ {
return 1; if (nTrack < 2) {
return 0;
}
char filebuf[128];
// prefer flac if available
sprintf(filebuf, "exhumed%02d.flac", nTrack);
int32_t hFile = kopen4load(filebuf, 0);
if (hFile < 0)
{
// try ogg vorbis now
sprintf(filebuf, "exhumed%02d.ogg", nTrack);
hFile = kopen4load(filebuf, 0);
if (hFile < 0) {
return 0;
}
}
int32_t nFileLen = kfilelength(hFile);
pTrack = (char*)Xaligned_alloc(16, nFileLen);
int nRead = kread(hFile, pTrack, nFileLen);
kclose(hFile);
trackhandle = FX_Play(pTrack, nRead, -1, 0, 0, 255, 255, 255, FX_MUSIC_PRIORITY, fix16_one, MUSIC_ID);
if (trackhandle < 0)
{
if (pTrack)
{
Xaligned_free(pTrack);
pTrack = NULL;
}
return 0;
}
setCDaudiovolume(gMusicVolume);
nCDTrackLength = 1;
return nCDTrackLength;
} }
void StartfadeCDaudio() void StartfadeCDaudio()
{ {
if (CDplaying()) {
nLastVolumeSet = gMusicVolume;
}
} }
int StepFadeCDaudio() int StepFadeCDaudio()
{ {
if (!CDplaying()) {
return 0; return 0;
} }
if (nLastVolumeSet <= 0) {
return 0;
}
nLastVolumeSet -= 8;
if (nLastVolumeSet <= 0) {
nLastVolumeSet = 0;
}
setCDaudiovolume(nLastVolumeSet);
if (nLastVolumeSet == 0) {
StopCD();
}
return 1;
}
int CDplaying() int CDplaying()
{ {
if (trackhandle > 0 && pTrack) { // better way to do this?
return 1; return 1;
} }
else {
return 0;
}
}
void StopCD() void StopCD()
{ {
if (trackhandle > 0) {
FX_StopSound(trackhandle);
trackhandle = -1;
} }
nCDTrackLength = 0;
if (pTrack)
{
Xaligned_free(pTrack);
pTrack = NULL;
}
}
END_PS_NS END_PS_NS

View file

@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS BEGIN_PS_NS
extern int trackhandle;
int initcdaudio(); int initcdaudio();
void setCDaudiovolume(int val); void setCDaudiovolume(int val);
int playCDtrack(int nTrack); int playCDtrack(int nTrack);

View file

@ -17,12 +17,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#include "ns.h" #include "ns.h"
#include "cdaudio.h" #include "cdaudio.h"
#include "cd.h"
#include "exhumed.h"
BEGIN_PS_NS BEGIN_PS_NS
int fadecdaudio() int fadecdaudio()
{ {
/* TODO
StartfadeCDaudio(); StartfadeCDaudio();
while (1) while (1)
@ -34,7 +36,7 @@ int fadecdaudio()
WaitTicks(1); WaitTicks(1);
} }
} }
*/
return 1; return 1;
} }

View file

@ -874,9 +874,9 @@ void timerhandler()
lastfps = fps; lastfps = fps;
fps = 0; fps = 0;
if (nCDTrackLength > 0) { // if (nCDTrackLength > 0) {
nCDTrackLength--; // nCDTrackLength--;
} // }
} }
if (!bInMove) if (!bInMove)
OSD_DispatchQueued(); OSD_DispatchQueued();
@ -2291,7 +2291,7 @@ LOOP3:
lPlayerXVel = 0; lPlayerXVel = 0;
lPlayerYVel = 0; lPlayerYVel = 0;
movefifopos = movefifoend; movefifopos = movefifoend;
nCDTrackLength = 0; // nCDTrackLength = 0;
RefreshStatus(); RefreshStatus();
if (bSerialPlay) { if (bSerialPlay) {

View file

@ -923,7 +923,7 @@ void menu_AdjustVolume()
} }
// TODO SetMusicVolume(); // TODO SetMusicVolume();
// TODO setCDaudiovolume(gMusicVolume); setCDaudiovolume(gMusicVolume);
continue; continue;
} }
@ -955,8 +955,8 @@ void menu_AdjustVolume()
gMusicVolume += 4; gMusicVolume += 4;
} }
// TODO SetMusicVolume(); // SetMusicVolume();
// TODO setCDaudiovolume(gMusicVolume); setCDaudiovolume(gMusicVolume);
continue; continue;
} }

View file

@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "snake.h" #include "snake.h"
#include "trigdat.h" #include "trigdat.h"
#include "sequence.h" #include "sequence.h"
#include "cd.h"
BEGIN_PS_NS BEGIN_PS_NS
@ -295,6 +296,12 @@ 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) {
trackhandle = -1;
StopCD();
return;
}
// TODO: add mutex? // TODO: add mutex?
if ((int32_t)num == -1) if ((int32_t)num == -1)
handle = -1; handle = -1;
@ -1174,7 +1181,7 @@ void StopAllSounds(void)
for (int i = 0; i < kMaxActiveSounds; i++) for (int i = 0; i < kMaxActiveSounds; i++)
{ {
if (sActiveSound[i].f_e >= 0) if (sActiveSound[i].f_e >= 0 && sActiveSound[i].f_e != trackhandle)
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

@ -29,6 +29,8 @@ BEGIN_PS_NS
#define kCreepyCount 150 #define kCreepyCount 150
#define MUSIC_ID (-65536)
enum { enum {
kSound0 = 0, kSound0 = 0,
kSound1, kSound1,