94 lines
1.9 KiB
C++
94 lines
1.9 KiB
C++
#include "XAAudio.h"
|
|
#include <STDDEF.H>
|
|
#include <LIBSND.H>
|
|
|
|
namespace XAAudio
|
|
{
|
|
static constexpr int BigSectorSize = 2340;
|
|
|
|
static CdlCB oldCallback = nullptr;
|
|
static CdlLOC curLoc;
|
|
static int curChannel;
|
|
|
|
static u_char buffer[(sizeof(u_long)*8)];
|
|
|
|
static u_short getChannel(u_char *buffer)
|
|
{
|
|
const u_short currentChannel = *((unsigned short *)(buffer + 12) + 1);
|
|
return ((currentChannel&31744) >> 10);
|
|
}
|
|
|
|
static u_short getID(u_char *buffer)
|
|
{
|
|
return *(u_short*)(buffer + 12);
|
|
}
|
|
|
|
void cbready(int intr, u_char *result)
|
|
{
|
|
static const u_short VideoFrameID = 352;
|
|
|
|
if(intr == CdlDataReady)
|
|
{
|
|
CdGetSector((u_long*)buffer, 8);
|
|
|
|
const u_short ID = getID(buffer);
|
|
const u_short actChannel = getChannel(buffer);
|
|
|
|
if((ID == VideoFrameID) && (actChannel == curChannel))
|
|
{
|
|
CdControlF(CdlReadS, (u_char*)&curLoc);
|
|
}
|
|
}
|
|
}
|
|
|
|
void enable(bool doubleSpeed)
|
|
{
|
|
// setup the XA playback - adjust the speed as needed by your XA samples
|
|
u_char param[4];
|
|
|
|
param[0] = (((doubleSpeed) ? CdlModeSpeed : 0x0)|CdlModeRT|CdlModeSF|CdlModeSize1);
|
|
|
|
CdControlB(CdlSetmode, param, 0);
|
|
CdControlF(CdlPause, 0);
|
|
|
|
oldCallback = CdReadyCallback((CdlCB)cbready);
|
|
}
|
|
|
|
void disable()
|
|
{
|
|
// reset any callback that we replaced
|
|
CdControlF(CdlPause, 0);
|
|
CdReadyCallback(oldCallback);
|
|
|
|
// clear XA mode
|
|
u_char param = 0x0;
|
|
CdControlB(CdlSetmode, ¶m, 0);
|
|
}
|
|
|
|
void play(const CdlLOC &file, int channel)
|
|
{
|
|
CdlFILTER theFilter;
|
|
|
|
curLoc = file;
|
|
curChannel = channel;
|
|
|
|
// set the volume to max
|
|
SsSetSerialVol(SS_SERIAL_A, 127, 127);
|
|
|
|
// set up the XA filter
|
|
theFilter.file = 1;
|
|
theFilter.chan = channel;
|
|
CdControlF(CdlSetfilter, (u_char*)&theFilter);
|
|
|
|
// begin playing
|
|
CdControlF(CdlReadS, (u_char*)&file);
|
|
}
|
|
|
|
CdlLOC locate(const char* fileName)
|
|
{
|
|
CdlFILE file = {0};
|
|
|
|
CdSearchFile(&file, const_cast<char*>(fileName));
|
|
return file.pos;
|
|
}
|
|
} |