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 "build.h"
#include "compat.h"
#include "baselayer.h"
#include "cd.h"
#include "fx_man.h"
#include "sound.h"
#include "exhumed.h"
#include <stdio.h>
#include <stdlib.h>
@ -26,6 +30,11 @@ BEGIN_PS_NS
extern short word_9AC30;
static char *pTrack = NULL;
int trackhandle = -1;
int nLastVolumeSet = 0;
int cd_check_device_present()
{
return 1;
@ -47,31 +56,113 @@ int initcdaudio()
void setCDaudiovolume(int val)
{
if (trackhandle > 0) {
FX_SetPan(trackhandle, val, val, val);
}
}
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()
{
if (CDplaying()) {
nLastVolumeSet = gMusicVolume;
}
}
int StepFadeCDaudio()
{
if (!CDplaying()) {
return 0;
}
if (nLastVolumeSet <= 0) {
return 0;
}
nLastVolumeSet -= 8;
if (nLastVolumeSet <= 0) {
nLastVolumeSet = 0;
}
setCDaudiovolume(nLastVolumeSet);
if (nLastVolumeSet == 0) {
StopCD();
}
return 1;
}
int CDplaying()
{
if (trackhandle > 0 && pTrack) { // better way to do this?
return 1;
}
else {
return 0;
}
}
void StopCD()
{
if (trackhandle > 0) {
FX_StopSound(trackhandle);
trackhandle = -1;
}
nCDTrackLength = 0;
if (pTrack)
{
Xaligned_free(pTrack);
pTrack = NULL;
}
}
END_PS_NS

View file

@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS
extern int trackhandle;
int initcdaudio();
void setCDaudiovolume(int val);
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 "cdaudio.h"
#include "cd.h"
#include "exhumed.h"
BEGIN_PS_NS
int fadecdaudio()
{
/* TODO
StartfadeCDaudio();
while (1)
@ -34,7 +36,7 @@ int fadecdaudio()
WaitTicks(1);
}
}
*/
return 1;
}

View file

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

View file

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

View file

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

View file

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