Subversion Repositories eduke32

Compare Revisions

Ignore whitespace Rev 8783 → Rev 8782

/source/audiolib/include/multivoc.h
37,7 → 37,7
extern "C" {
#endif
 
typedef enum wavefmt_t : char
typedef enum : char
{
FMT_UNKNOWN,
FMT_RAW,
/source/audiolib/src/fx_man.cpp
195,51 → 195,57
int FX_GetDevice(void) { return ASS_PCMSoundDriver; }
 
 
#define FMT_MAGIC(i, j, k, l) (i + (j << 8) + (k << 16) + (l << 24))
uint32_t constexpr FMT_CDXA_MAGIC = FMT_MAGIC('C','D','X','A');
uint32_t constexpr FMT_FLAC_MAGIC = FMT_MAGIC('f','L','a','C');
uint32_t constexpr FMT_OGG_MAGIC = FMT_MAGIC('O','g','g','S');
uint32_t constexpr FMT_RIFF_MAGIC = FMT_MAGIC('R','I','F','F');
uint32_t constexpr FMT_VOC_MAGIC = FMT_MAGIC('C','r','e','a');
uint32_t constexpr FMT_WAVE_MAGIC = FMT_MAGIC('W','A','V','E');
#undef FMT_MAGIC
 
static wavefmt_t FX_ReadFmt(char const * const ptr, uint32_t length)
static wavefmt_t FX_DetectFormat(char const * const ptr, uint32_t length)
{
if (length < 12)
return FMT_UNKNOWN;
 
auto const ptr32 = (uint32_t const *)ptr;
wavefmt_t fmt = FMT_UNKNOWN;
 
switch (B_LITTLE32(*ptr32))
switch (B_LITTLE32(*(int const *)ptr))
{
case FMT_OGG_MAGIC: return FMT_VORBIS;
case FMT_VOC_MAGIC: return FMT_VOC;
case FMT_FLAC_MAGIC: return FMT_FLAC;
case FMT_RIFF_MAGIC:
if (B_LITTLE32(ptr32[2]) == FMT_WAVE_MAGIC) return FMT_WAV;
if (B_LITTLE32(ptr32[2]) == FMT_CDXA_MAGIC) return FMT_XA;
case 'C' + ('r' << 8) + ('e' << 16) + ('a' << 24): // Crea
fmt = FMT_VOC;
break;
case 'O' + ('g' << 8) + ('g' << 16) + ('S' << 24): // OggS
fmt = FMT_VORBIS;
break;
case 'R' + ('I' << 8) + ('F' << 16) + ('F' << 24): // RIFF
switch (B_LITTLE32(*(int const *)(ptr + 8)))
{
case 'C' + ('D' << 8) + ('X' << 16) + ('A' << 24): // CDXA
fmt = FMT_XA;
break;
case 'W' + ('A' << 8) + ('V' << 16) + ('E' << 24): // WAVE
fmt = FMT_WAV;
break;
}
break;
case 'f' + ('L' << 8) + ('a' << 16) + ('C' << 24): // fLaC
fmt = FMT_FLAC;
break;
default:
if (MV_IdentifyXMP(ptr, length)) return FMT_XMP;
if (MV_IdentifyXMP(ptr, length))
fmt = FMT_XMP;
break;
}
 
return FMT_UNKNOWN;
return fmt;
}
 
static int FX_BadFmt(char *, uint32_t, int, int, int, int, int, int, int, fix16_t, intptr_t) { return MV_SetErrorCode(MV_InvalidFile); }
static int FX_BadFmt3D(char *, uint32_t, int, int, int, int, int, fix16_t, intptr_t) { return MV_SetErrorCode(MV_InvalidFile); }
 
int FX_Play(char *ptr, uint32_t ptrlength, int loopstart, int loopend, int pitchoffset,
int vol, int left, int right, int priority, fix16_t volume, intptr_t callbackval)
int vol, int left, int right, int priority, fix16_t volume, intptr_t callbackval)
{
static constexpr decltype(FX_Play) *func[] = { FX_BadFmt, nullptr, MV_PlayVOC, MV_PlayWAV, MV_PlayVorbis, MV_PlayFLAC, MV_PlayXA, MV_PlayXMP };
static constexpr decltype(MV_PlayVOC) *func[] =
{ nullptr, nullptr, MV_PlayVOC, MV_PlayWAV, MV_PlayVorbis, MV_PlayFLAC, MV_PlayXA, MV_PlayXMP };
 
EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
 
int handle = func[FX_ReadFmt(ptr, ptrlength)](ptr, ptrlength, loopstart, loopend, pitchoffset, vol, left, right, priority, volume, callbackval);
wavefmt_t const fmt = FX_DetectFormat(ptr, ptrlength);
 
int handle =
(func[fmt]) ? func[fmt](ptr, ptrlength, loopstart, loopend, pitchoffset, vol, left, right, priority, volume, callbackval) : -1;
 
if (handle <= MV_Ok)
{
FX_SetErrorCode(FX_MultiVocError);
250,14 → 256,18
}
 
int FX_Play3D(char *ptr, uint32_t ptrlength, int loophow, int pitchoffset, int angle, int distance,
int priority, fix16_t volume, intptr_t callbackval)
int priority, fix16_t volume, intptr_t callbackval)
{
static constexpr decltype(FX_Play3D) *func[] = { FX_BadFmt3D, nullptr, MV_PlayVOC3D, MV_PlayWAV3D, MV_PlayVorbis3D, MV_PlayFLAC3D, MV_PlayXA3D, MV_PlayXMP3D };
static constexpr decltype(MV_PlayVOC3D) *func[] =
{ nullptr, nullptr, MV_PlayVOC3D, MV_PlayWAV3D, MV_PlayVorbis3D, MV_PlayFLAC3D, MV_PlayXA3D, MV_PlayXMP3D };
 
EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
 
int handle = func[FX_ReadFmt(ptr, ptrlength)](ptr, ptrlength, loophow, pitchoffset, angle, distance, priority, volume, callbackval);
wavefmt_t const fmt = FX_DetectFormat(ptr, ptrlength);
 
int handle =
(func[fmt]) ? func[fmt](ptr, ptrlength, loophow, pitchoffset, angle, distance, priority, volume, callbackval) : -1;
 
if (handle <= MV_Ok)
{
FX_SetErrorCode(FX_MultiVocError);
/source/audiolib/src/xmp.cpp
67,6 → 67,12
 
int MV_PlayXMP3D(char *ptr, uint32_t length, int loophow, int pitchoffset, int angle, int distance, int priority, fix16_t volume, intptr_t callbackval)
{
int left;
int right;
int mid;
int vol;
int status;
 
if (!MV_Installed)
return MV_SetErrorCode(MV_NotInstalled);
 
76,26 → 82,32
angle += MV_NUMPANPOSITIONS / 2;
}
 
int vol = MIX_VOLUME(distance);
vol = MIX_VOLUME(distance);
 
// Ensure angle is within 0 - 127
angle &= MV_MAXPANPOSITION;
 
int left = MV_PanTable[angle][vol].left;
int right = MV_PanTable[angle][vol].right;
int mid = max( 0, 255 - distance );
left = MV_PanTable[angle][vol].left;
right = MV_PanTable[angle][vol].right;
mid = max( 0, 255 - distance );
 
return MV_PlayXMP(ptr, length, loophow, -1, pitchoffset, mid, left, right, priority, volume, callbackval);
status = MV_PlayXMP(ptr, length, loophow, -1, pitchoffset, mid, left, right, priority, volume, callbackval);
 
return status;
}
 
int MV_PlayXMP(char *ptr, uint32_t length, int loopstart, int loopend, int pitchoffset, int vol, int left, int right, int priority, fix16_t volume, intptr_t callbackval)
{
VoiceNode *voice;
xmp_data * xmpd = 0;
int retval;
 
UNREFERENCED_PARAMETER(loopend);
 
if (!MV_Installed)
return MV_SetErrorCode(MV_NotInstalled);
 
auto xmpd = (xmp_data *)Xcalloc(1, sizeof(xmp_data));
xmpd = (xmp_data *)Xcalloc(1, sizeof(xmp_data));
if (!xmpd)
return MV_SetErrorCode(MV_InvalidFile);
 
108,18 → 120,15
return MV_SetErrorCode(MV_InvalidFile);
}
 
int const xmp_status = xmp_load_module_from_memory(xmpd->context, ptr, length);
 
if (xmp_status)
if ((retval = xmp_load_module_from_memory(xmpd->context, ptr, length)) != 0)
{
xmp_free_context(xmpd->context);
Xfree(xmpd);
MV_Printf("MV_PlayXMP: xmp_load_module_from_memory failed (%i)\n", xmp_status);
MV_Printf("MV_PlayXMP: xmp_load_module_from_memory failed (%i)\n", retval);
return MV_SetErrorCode(MV_InvalidFile);
}
 
// Request a voice from the voice pool
auto voice = MV_AllocVoice(priority);
voice = MV_AllocVoice(priority);
if (voice == nullptr)
{
xmp_release_module(xmpd->context);
241,7 → 250,12
static int it_test_memory(char const *ptr, uint32_t ptrlength)
{
static char const it_magic[] = "IMPM";
return !!(ptrlength < sizeof(it_magic) - 1 || Bmemcmp(ptr, it_magic, sizeof(it_magic) - 1));
 
if (ptrlength < sizeof(it_magic)-1 ||
memcmp(ptr, it_magic, sizeof(it_magic)-1))
return -1;
 
return 0;
}
 
static int mod_test_memory(char const *ptr, uint32_t ptrlength)
251,7 → 265,7
 
char const * const buf = ptr + 1080;
 
if (!Bstrncmp(buf + 2, "CH", 2) && isdigit((int)buf[0]) && isdigit((int)buf[1]))
if (!strncmp(buf + 2, "CH", 2) && isdigit((int)buf[0]) && isdigit((int)buf[1]))
{
int i = (buf[0] - '0') * 10 + buf[1] - '0';
if (i > 0 && i <= 32)
258,13 → 272,13
return 0;
}
 
if (!Bstrncmp(buf + 1, "CHN", 3) && isdigit((int)*buf))
if (!strncmp(buf + 1, "CHN", 3) && isdigit((int)*buf))
{
if (*buf >= '0' && *buf <= '9')
return 0;
}
 
if (!Bmemcmp(buf, "M.K.", 4))
if (!memcmp(buf, "M.K.", 4))
return 0;
 
return -1;
275,21 → 289,34
static char const s3m_magic[] = "SCRM";
#define s3m_magic_offset 44
 
return !!(ptrlength < s3m_magic_offset + sizeof(s3m_magic)-1 ||
Bmemcmp(ptr + s3m_magic_offset, s3m_magic, sizeof(s3m_magic)-1) ||
ptr[29] != 0x10);
if (ptrlength < s3m_magic_offset + sizeof(s3m_magic)-1 ||
memcmp(ptr + s3m_magic_offset, s3m_magic, sizeof(s3m_magic)-1) ||
ptr[29] != 0x10)
return -1;
 
return 0;
}
 
static int xm_test_memory(char const *ptr, uint32_t ptrlength)
{
static char const xm_magic[] = "Extended Module: ";
return !!(ptrlength < sizeof(xm_magic) - 1 || Bmemcmp(ptr, xm_magic, sizeof(xm_magic) - 1));
 
if (ptrlength < sizeof(xm_magic)-1 ||
memcmp(ptr, xm_magic, sizeof(xm_magic)-1))
return -1;
 
return 0;
}
 
static int mtm_test_memory(char const *ptr, uint32_t ptrlength)
{
static char const mtm_magic[] = "MTM\x10";
return !!(ptrlength < sizeof(mtm_magic) - 1 || Bmemcmp(ptr, mtm_magic, sizeof(mtm_magic) - 1));
 
if (ptrlength < sizeof(mtm_magic)-1 ||
memcmp(ptr, mtm_magic, sizeof(mtm_magic)-1))
return -1;
 
return 0;
}
 
int MV_IdentifyXMP(char const *ptr, uint32_t ptrlength)