2019-11-20 16:21:32 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 sirlemonhead, Nuke.YKT
|
|
|
|
This file is part of PCExhumed.
|
|
|
|
PCExhumed is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-11-22 23:11:37 +00:00
|
|
|
#include "ns.h"
|
2019-11-24 20:32:07 +00:00
|
|
|
#include "build.h"
|
2019-08-27 06:08:18 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "baselayer.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "cd.h"
|
2019-11-24 20:32:07 +00:00
|
|
|
#include "fx_man.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "exhumed.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
extern short word_9AC30;
|
|
|
|
|
2019-11-24 20:32:07 +00:00
|
|
|
static char *pTrack = NULL;
|
2019-11-28 20:40:17 +00:00
|
|
|
static int trackhandle = -1;
|
2019-11-24 20:32:07 +00:00
|
|
|
int nLastVolumeSet = 0;
|
|
|
|
|
2019-11-28 20:40:17 +00:00
|
|
|
/* TODO
|
2019-11-24 20:32:07 +00:00
|
|
|
|
2019-11-28 20:40:17 +00:00
|
|
|
Currently playing music must keep playing on return to map screen or exit from training level
|
2019-11-20 16:21:32 +00:00
|
|
|
|
2019-11-28 20:40:17 +00:00
|
|
|
*/
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
void setCDaudiovolume(int val)
|
|
|
|
{
|
2019-11-24 20:32:07 +00:00
|
|
|
if (trackhandle > 0) {
|
|
|
|
FX_SetPan(trackhandle, val, val, val);
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 20:40:17 +00:00
|
|
|
bool playCDtrack(int nTrack, bool bLoop)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-11-24 20:32:07 +00:00
|
|
|
if (nTrack < 2) {
|
2019-11-28 20:40:17 +00:00
|
|
|
return false;
|
2019-11-24 20:32:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 20:40:17 +00:00
|
|
|
StopCD();
|
2019-11-26 12:47:12 +00:00
|
|
|
|
|
|
|
char filename[128];
|
2019-11-24 20:32:07 +00:00
|
|
|
|
|
|
|
// prefer flac if available
|
2019-11-26 12:47:12 +00:00
|
|
|
sprintf(filename, "exhumed%02d.flac", nTrack);
|
|
|
|
int32_t hFile = kopen4load(filename, 0);
|
2019-11-24 20:32:07 +00:00
|
|
|
if (hFile < 0)
|
|
|
|
{
|
|
|
|
// try ogg vorbis now
|
2019-11-26 12:47:12 +00:00
|
|
|
sprintf(filename, "exhumed%02d.ogg", nTrack);
|
|
|
|
hFile = kopen4load(filename, 0);
|
2019-11-24 20:32:07 +00:00
|
|
|
if (hFile < 0) {
|
2019-11-28 20:40:17 +00:00
|
|
|
return false;
|
2019-11-24 20:32:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t nFileLen = kfilelength(hFile);
|
|
|
|
|
|
|
|
pTrack = (char*)Xaligned_alloc(16, nFileLen);
|
2019-11-26 12:47:12 +00:00
|
|
|
if (pTrack == NULL)
|
|
|
|
{
|
|
|
|
OSD_Printf("Error allocating music track data memory for %s", filename);
|
|
|
|
kclose(hFile);
|
2019-11-28 20:40:17 +00:00
|
|
|
return false;
|
2019-11-26 12:47:12 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 20:32:07 +00:00
|
|
|
int nRead = kread(hFile, pTrack, nFileLen);
|
2019-11-26 12:47:12 +00:00
|
|
|
if (nRead != nFileLen)
|
|
|
|
{
|
|
|
|
OSD_Printf("Error reading music track data for %s", filename);
|
|
|
|
Xaligned_free(pTrack);
|
|
|
|
pTrack = NULL;
|
|
|
|
kclose(hFile);
|
2019-11-28 20:40:17 +00:00
|
|
|
return false;
|
2019-11-26 12:47:12 +00:00
|
|
|
}
|
2019-11-24 20:32:07 +00:00
|
|
|
|
|
|
|
kclose(hFile);
|
|
|
|
|
2019-12-05 21:20:11 +00:00
|
|
|
trackhandle = FX_Play(pTrack, nRead, bLoop ? 0 : -1, 0, 0, gMusicVolume, gMusicVolume, gMusicVolume, FX_MUSIC_PRIORITY, fix16_one, MUSIC_ID);
|
2019-11-26 12:47:12 +00:00
|
|
|
if (trackhandle <= FX_Ok)
|
2019-11-24 20:32:07 +00:00
|
|
|
{
|
2019-11-26 12:47:12 +00:00
|
|
|
OSD_Printf("Error playing music track %s", filename);
|
2019-11-24 20:32:07 +00:00
|
|
|
if (pTrack)
|
|
|
|
{
|
|
|
|
Xaligned_free(pTrack);
|
|
|
|
pTrack = NULL;
|
|
|
|
}
|
2019-11-28 20:40:17 +00:00
|
|
|
return false;
|
2019-11-24 20:32:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 20:40:17 +00:00
|
|
|
return true;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StartfadeCDaudio()
|
|
|
|
{
|
2019-11-24 20:32:07 +00:00
|
|
|
if (CDplaying()) {
|
|
|
|
nLastVolumeSet = gMusicVolume;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int StepFadeCDaudio()
|
|
|
|
{
|
2019-11-24 20:32:07 +00:00
|
|
|
if (!CDplaying()) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return 0;
|
2019-11-24 20:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nLastVolumeSet <= 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nLastVolumeSet -= 8;
|
|
|
|
|
|
|
|
if (nLastVolumeSet <= 0) {
|
|
|
|
nLastVolumeSet = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCDaudiovolume(nLastVolumeSet);
|
|
|
|
|
|
|
|
if (nLastVolumeSet == 0) {
|
|
|
|
StopCD();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 20:40:17 +00:00
|
|
|
bool CDplaying()
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-11-28 20:40:17 +00:00
|
|
|
if (trackhandle <= 0) {
|
|
|
|
return false;
|
2019-11-24 20:32:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-11-28 20:40:17 +00:00
|
|
|
return FX_SoundActive(trackhandle);
|
2019-11-24 20:32:07 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StopCD()
|
|
|
|
{
|
2019-11-24 20:32:07 +00:00
|
|
|
if (trackhandle > 0) {
|
|
|
|
FX_StopSound(trackhandle);
|
|
|
|
trackhandle = -1;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-24 20:32:07 +00:00
|
|
|
if (pTrack)
|
|
|
|
{
|
|
|
|
Xaligned_free(pTrack);
|
|
|
|
pTrack = NULL;
|
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
}
|
2019-11-24 20:32:07 +00:00
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|