2016-08-27 01:39:50 +00:00
|
|
|
//-------------------------------------------------------------------------
|
2009-07-27 05:47:50 +00:00
|
|
|
/*
|
2016-08-27 01:39:50 +00:00
|
|
|
Copyright (C) 2016 EDuke32 developers and contributors
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2016-08-27 01:39:50 +00:00
|
|
|
This file is part of EDuke32.
|
|
|
|
|
|
|
|
EDuke32 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.
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
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
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-07-27 05:47:50 +00:00
|
|
|
*/
|
2016-08-27 01:39:50 +00:00
|
|
|
//-------------------------------------------------------------------------
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2019-10-19 23:48:31 +00:00
|
|
|
#include "fx_man.h"
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
#include "compat.h"
|
2009-07-27 05:47:50 +00:00
|
|
|
#include "drivers.h"
|
2019-10-19 23:48:31 +00:00
|
|
|
#include "driver_adlib.h"
|
|
|
|
#include "midi.h"
|
2009-07-27 05:47:50 +00:00
|
|
|
#include "multivoc.h"
|
2019-10-19 23:48:31 +00:00
|
|
|
#include "osd.h"
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int FX_ErrorCode = FX_Ok;
|
|
|
|
int FX_Installed;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2019-10-19 23:48:51 +00:00
|
|
|
const char *FX_ErrorString(int const ErrorNumber)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
const char *ErrorString;
|
|
|
|
|
|
|
|
switch (ErrorNumber)
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
case FX_Warning:
|
2016-08-27 01:39:50 +00:00
|
|
|
case FX_Error: ErrorString = FX_ErrorString(FX_ErrorCode); break;
|
|
|
|
case FX_Ok: ErrorString = "Fx ok."; break;
|
|
|
|
case FX_MultiVocError: ErrorString = MV_ErrorString(MV_Error); break;
|
|
|
|
default: ErrorString = "Unknown Fx error code."; break;
|
2015-07-08 03:33:56 +00:00
|
|
|
}
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
return ErrorString;
|
|
|
|
}
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2019-10-19 23:48:35 +00:00
|
|
|
|
2019-10-19 23:48:51 +00:00
|
|
|
int FX_Init(int numvoices, int numchannels, int mixrate, void *initdata)
|
2015-07-08 03:33:56 +00:00
|
|
|
{
|
2009-07-27 05:47:50 +00:00
|
|
|
if (FX_Installed)
|
|
|
|
FX_Shutdown();
|
2019-10-19 23:48:51 +00:00
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int SoundCard = ASS_AutoDetect;
|
|
|
|
|
2019-10-19 23:48:51 +00:00
|
|
|
if (SoundCard == ASS_AutoDetect)
|
|
|
|
{
|
2019-10-19 23:47:54 +00:00
|
|
|
#if defined RENDERTYPESDL
|
|
|
|
SoundCard = ASS_SDL;
|
2019-10-19 23:48:20 +00:00
|
|
|
#elif defined RENDERTYPEWIN
|
2019-10-19 23:47:54 +00:00
|
|
|
SoundCard = ASS_DirectSound;
|
2009-07-27 05:47:50 +00:00
|
|
|
#else
|
2019-10-19 23:47:54 +00:00
|
|
|
SoundCard = ASS_NoSound;
|
2009-07-27 05:47:50 +00:00
|
|
|
#endif
|
2019-10-19 23:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SoundCard < 0 || SoundCard >= ASS_NumSoundCards)
|
|
|
|
{
|
|
|
|
FX_SetErrorCode(FX_InvalidCard);
|
|
|
|
return FX_Error;
|
|
|
|
}
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
if (SoundDriver_IsPCMSupported(SoundCard) == 0)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
// unsupported cards fall back to no sound
|
2019-10-19 23:47:54 +00:00
|
|
|
MV_Printf("Couldn't init %s, falling back to no sound...\n", SoundDriver_GetName(SoundCard));
|
2009-07-27 05:47:50 +00:00
|
|
|
SoundCard = ASS_NoSound;
|
|
|
|
}
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int status = FX_Ok;
|
|
|
|
|
2015-07-08 03:34:09 +00:00
|
|
|
if (MV_Init(SoundCard, mixrate, numvoices, numchannels, initdata) != MV_Ok)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
FX_SetErrorCode(FX_MultiVocError);
|
|
|
|
status = FX_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == FX_Ok)
|
|
|
|
FX_Installed = TRUE;
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return status;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int FX_Shutdown(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
if (!FX_Installed)
|
2012-12-29 10:59:21 +00:00
|
|
|
return FX_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int status = MV_Shutdown();
|
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
if (status != MV_Ok)
|
|
|
|
{
|
|
|
|
FX_SetErrorCode(FX_MultiVocError);
|
|
|
|
status = FX_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
FX_Installed = FALSE;
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return status;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 05:47:29 +00:00
|
|
|
int FX_GetDevice()
|
|
|
|
{
|
|
|
|
return ASS_PCMSoundDriver;
|
|
|
|
}
|
|
|
|
|
2016-08-27 01:39:38 +00:00
|
|
|
static wavefmt_t FX_DetectFormat(char const * const ptr, uint32_t length)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2016-08-27 01:39:38 +00:00
|
|
|
if (length < 12)
|
|
|
|
return FMT_UNKNOWN;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
wavefmt_t fmt = FMT_UNKNOWN;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
switch (B_LITTLE32(*(int const *)ptr))
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
case 'C' + ('r' << 8) + ('e' << 16) + ('a' << 24): // Crea
|
|
|
|
fmt = FMT_VOC;
|
2014-01-27 10:30:00 +00:00
|
|
|
break;
|
2015-07-08 03:33:56 +00:00
|
|
|
case 'O' + ('g' << 8) + ('g' << 16) + ('S' << 24): // OggS
|
|
|
|
fmt = FMT_VORBIS;
|
|
|
|
break;
|
|
|
|
case 'R' + ('I' << 8) + ('F' << 16) + ('F' << 24): // RIFF
|
2019-10-19 23:47:54 +00:00
|
|
|
switch (B_LITTLE32(*(int const *)(ptr + 8)))
|
2015-07-08 03:33:56 +00:00
|
|
|
{
|
2018-04-21 06:04:44 +00:00
|
|
|
case 'W' + ('A' << 8) + ('V' << 16) + ('E' << 24): // WAVE
|
|
|
|
fmt = FMT_WAV;
|
|
|
|
break;
|
2015-07-08 03:33:56 +00:00
|
|
|
}
|
2014-01-27 10:30:00 +00:00
|
|
|
break;
|
2015-07-08 03:33:56 +00:00
|
|
|
default:
|
2009-08-06 10:12:13 +00:00
|
|
|
break;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
return fmt;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int FX_Play(char *ptr, uint32_t ptrlength, int loopstart, int loopend, int pitchoffset,
|
2019-10-24 13:25:34 +00:00
|
|
|
int vol, int left, int right, int priority, float volume, intptr_t callbackval)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2019-10-19 23:47:54 +00:00
|
|
|
static constexpr decltype(MV_PlayVOC) *func[] =
|
2019-11-11 18:10:46 +00:00
|
|
|
{ nullptr, nullptr, MV_PlayVOC, MV_PlayWAV, nullptr, nullptr, MV_PlayVorbis, nullptr, nullptr, nullptr };
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2019-11-11 18:10:46 +00:00
|
|
|
//EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2018-10-25 23:32:14 +00:00
|
|
|
wavefmt_t const fmt = FX_DetectFormat(ptr, ptrlength);
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2016-08-27 01:39:38 +00:00
|
|
|
int handle =
|
2018-10-25 23:32:14 +00:00
|
|
|
(func[fmt]) ? func[fmt](ptr, ptrlength, loopstart, loopend, pitchoffset, vol, left, right, priority, volume, callbackval) : -1;
|
2009-08-06 10:12:13 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
if (handle <= MV_Ok)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
FX_SetErrorCode(FX_MultiVocError);
|
|
|
|
handle = FX_Warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int FX_Play3D(char *ptr, uint32_t ptrlength, int loophow, int pitchoffset, int angle, int distance,
|
2019-10-24 13:25:34 +00:00
|
|
|
int priority, float volume, intptr_t callbackval)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2019-10-19 23:47:54 +00:00
|
|
|
static constexpr decltype(MV_PlayVOC3D) *func[] =
|
2019-11-11 18:10:46 +00:00
|
|
|
{ nullptr, nullptr, MV_PlayVOC3D, MV_PlayWAV3D, nullptr, nullptr, MV_PlayVorbis3D, nullptr, nullptr, nullptr };
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2019-11-11 18:10:46 +00:00
|
|
|
//EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2018-10-25 23:32:14 +00:00
|
|
|
wavefmt_t const fmt = FX_DetectFormat(ptr, ptrlength);
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2016-08-27 01:39:38 +00:00
|
|
|
int handle =
|
2018-10-25 23:32:14 +00:00
|
|
|
(func[fmt]) ? func[fmt](ptr, ptrlength, loophow, pitchoffset, angle, distance, priority, volume, callbackval) : -1;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
if (handle <= MV_Ok)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
FX_SetErrorCode(FX_MultiVocError);
|
|
|
|
handle = FX_Warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2019-10-24 13:25:34 +00:00
|
|
|
int FX_PlayRaw(char *ptr, uint32_t ptrlength, int rate, int pitchoffset, int vol,
|
|
|
|
int left, int right, int priority, float volume, intptr_t callbackval)
|
|
|
|
{
|
|
|
|
int handle = MV_PlayRAW(ptr, ptrlength, rate, NULL, NULL, pitchoffset, vol, left, right, priority, volume, callbackval);
|
|
|
|
|
|
|
|
if (handle <= MV_Ok)
|
|
|
|
{
|
|
|
|
FX_SetErrorCode(FX_MultiVocError);
|
|
|
|
handle = FX_Warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FX_PlayLoopedRaw(char *ptr, uint32_t ptrlength, char *loopstart, char *loopend, int rate,
|
|
|
|
int pitchoffset, int vol, int left, int right, int priority, float volume, intptr_t callbackval)
|
|
|
|
{
|
|
|
|
int handle = MV_PlayRAW(ptr, ptrlength, rate, loopstart, loopend, pitchoffset, vol, left, right, priority, volume, callbackval);
|
|
|
|
|
|
|
|
if (handle <= MV_Ok)
|
|
|
|
{
|
|
|
|
FX_SetErrorCode(FX_MultiVocError);
|
|
|
|
handle = FX_Warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int FX_SetPrintf(void (*function)(const char *, ...))
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
MV_SetPrintf(function);
|
|
|
|
|
|
|
|
return FX_Ok;
|
2010-06-22 21:50:01 +00:00
|
|
|
}
|