clang-format spu2x

Note: it doesn't play well with define around forceinline (might need to fix the inline btw)
And a single macro in RegTable.cpp
This commit is contained in:
Clang Format 2016-10-10 20:35:26 +02:00 committed by Gregory Hainaut
parent 0f022da98c
commit 039573b133
59 changed files with 10023 additions and 10027 deletions

View File

@ -25,8 +25,7 @@ static u32 PsxRates[160];
void InitADSR() // INIT ADSR
{
for (int i=0; i<(32+128); i++)
{
for (int i = 0; i < (32 + 128); i++) {
int shift = (i - 32) >> 2;
s64 rate = (i & 3) + 4;
if (shift < 0)
@ -57,11 +56,9 @@ bool V_ADSR::Calculate()
if (Releasing && (Phase < 5))
Phase = 5;
switch (Phase)
{
switch (Phase) {
case 1: // attack
if( Value == ADSR_MAX_VOL )
{
if (Value == ADSR_MAX_VOL) {
// Already maxed out. Progress phase and nothing more:
Phase++;
break;
@ -75,8 +72,7 @@ bool V_ADSR::Calculate()
else
Value += PsxRates[(AttackRate ^ 0x7f) - 0x10 + 32];
if( Value < 0 )
{
if (Value < 0) {
// We hit the ceiling.
Phase++;
Value = ADSR_MAX_VOL;
@ -92,19 +88,18 @@ bool V_ADSR::Calculate()
s32 suslev = ((0x80000000 / 0x10) * (SustainLevel + 1)) - 1;
if( Value <= suslev )
{
if (Value <= suslev) {
if (Value < 0)
Value = 0;
Phase++;
}
}
break;
} break;
case 3: // sustain
{
// 0x7f disables sustain (infinite sustain)
if( SustainRate == 0x7f ) return true;
if (SustainRate == 0x7f)
return true;
if (SustainMode & 2) // decreasing
{
@ -112,32 +107,26 @@ bool V_ADSR::Calculate()
{
u32 off = InvExpOffsets[(Value >> 28) & 7];
Value -= PsxRates[(SustainRate ^ 0x7f) - 0x1b + off + 32];
}
else // linear
} else // linear
Value -= PsxRates[(SustainRate ^ 0x7f) - 0xf + 32];
if( Value <= 0 )
{
if (Value <= 0) {
Value = 0;
Phase++;
}
}
else // increasing
{
} else { // increasing
if ((SustainMode & 4) && (Value >= 0x60000000))
Value += PsxRates[(SustainRate ^ 0x7f) - 0x18 + 32];
else
// linear / Pseudo below 75% (they're the same)
Value += PsxRates[(SustainRate ^ 0x7f) - 0x10 + 32];
if( Value < 0 )
{
if (Value < 0) {
Value = ADSR_MAX_VOL;
Phase++;
}
}
}
break;
} break;
case 4: // sustain end
Value = (SustainMode & 2) ? 0 : ADSR_MAX_VOL;
@ -150,16 +139,13 @@ bool V_ADSR::Calculate()
{
u32 off = InvExpOffsets[(Value >> 28) & 7];
Value -= PsxRates[((ReleaseRate ^ 0x1f) * 4) - 0x18 + off + 32];
}
else // linear
{
} else { // linear
//Value-=PsxRates[((ReleaseRate^0x1f)*4)-0xc+32];
if (ReleaseRate != 0x1f)
Value -= (1 << (0x1f - ReleaseRate));
}
if( Value <= 0 )
{
if (Value <= 0) {
Value = 0;
Phase++;
}
@ -187,35 +173,31 @@ bool V_ADSR::Calculate()
void V_VolumeSlide::Update()
{
if( !(Mode & VOLFLAG_SLIDE_ENABLE) ) return;
if (!(Mode & VOLFLAG_SLIDE_ENABLE))
return;
// Volume slides use the same basic logic as ADSR, but simplified (single-stage
// instead of multi-stage)
if( Increment == 0x7f ) return;
if (Increment == 0x7f)
return;
s32 value = abs(Value);
if (Mode & VOLFLAG_DECREMENT)
{
if (Mode & VOLFLAG_DECREMENT) {
// Decrement
if(Mode & VOLFLAG_EXPONENTIAL)
{
if (Mode & VOLFLAG_EXPONENTIAL) {
u32 off = InvExpOffsets[(value >> 28) & 7];
value -= PsxRates[(Increment ^ 0x7f) - 0x1b + off + 32];
}
else
} else
value -= PsxRates[(Increment ^ 0x7f) - 0xf + 32];
if (value < 0)
{
if (value < 0) {
value = 0;
Mode = 0; // disable slide
}
}
else
{
} else {
// Increment
// Pseudo-exponential increments, as done by the SPU2 (really!)
// Above 75% slides slow, below 75% slides fast. It's exponential, pseudo'ly speaking.

View File

@ -23,12 +23,15 @@ char s[4096];
FILE *spu2Log = NULL;
void FileLog(const char *fmt, ...) {
void FileLog(const char *fmt, ...)
{
#ifdef SPU2_LOG
va_list list;
if(!AccessLog()) return;
if(!spu2Log) return;
if (!AccessLog())
return;
if (!spu2Log)
return;
va_start(list, fmt);
vsprintf(s, fmt, list);
@ -51,8 +54,10 @@ void FileLog(const char *fmt, ...) {
// while ConLog doesn't print anything if messages to console are disabled at the GUI,
// it's still better to outright not call it on tight loop scenarios, by testing MsgToConsole() (which is inline and very quick).
// Else, there's some (small) overhead in calling and returning from ConLog.
void ConLog(const char *fmt, ...) {
if(!MsgToConsole()) return;
void ConLog(const char *fmt, ...)
{
if (!MsgToConsole())
return;
va_list list;
va_start(list, fmt);
@ -62,8 +67,7 @@ void ConLog(const char *fmt, ...) {
fputs(s, stderr);
fflush(stderr);
if(spu2Log)
{
if (spu2Log) {
fputs(s, spu2Log);
fflush(spu2Log);
}
@ -97,31 +101,26 @@ void DoFullDump()
FILE *dump;
u8 c = 0, v = 0;
if(MemDump())
{
if (MemDump()) {
dump = fopen(wxString(MemDumpFileName).ToUTF8(), "wb");
if (dump)
{
if (dump) {
fwrite(_spu2mem, 0x200000, 1, dump);
fclose(dump);
}
}
if(RegDump())
{
if (RegDump()) {
dump = fopen(wxString(RegDumpFileName).ToUTF8(), "wb");
if (dump)
{
if (dump) {
fwrite(spu2regs, 0x2000, 1, dump);
fclose(dump);
}
}
if(!CoresDump()) return;
if (!CoresDump())
return;
dump = fopen(wxString(CoresDumpFileName).ToUTF8(), "wt");
if (dump)
{
for(c=0;c<2;c++)
{
if (dump) {
for (c = 0; c < 2; c++) {
fprintf(dump, "#### CORE %d DUMP.\n", c);
Cores[c].MasterVol.DebugDump(dump, "Master");
@ -162,8 +161,7 @@ void DoFullDump()
fprintf(dump, " - ENDX: %x\n", Cores[c].Regs.VMIXER);
fprintf(dump, " - STATX: %x\n", Cores[c].Regs.VMIXEL);
fprintf(dump, " - ATTR: %x\n", Cores[c].Regs.VMIXER);
for(v=0;v<24;v++)
{
for (v = 0; v < 24; v++) {
fprintf(dump, "Voice %d:\n", v);
Cores[c].Voices[v].Volume.DebugDump(dump, "");
@ -211,10 +209,8 @@ void DoFullDump()
}
dump = fopen("logs/effects.txt", "wt");
if (dump)
{
for(c=0;c<2;c++)
{
if (dump) {
for (c = 0; c < 2; c++) {
fprintf(dump, "#### CORE %d EFFECTS PROCESSOR DUMP.\n", c);
fprintf(dump, " - IN_COEF_L: %x\n", Cores[c].Revb.IN_COEF_R);

View File

@ -32,28 +32,27 @@ extern FILE* OpenDump( const wxString& logfile );
namespace WaveDump
{
enum CoreSourceType
{
enum CoreSourceType {
// Core's input stream, usually pulled from ADMA streams.
CoreSrc_Input = 0
CoreSrc_Input = 0,
// Output of the actual 24 input voices which have dry output enabled.
, CoreSrc_DryVoiceMix
CoreSrc_DryVoiceMix,
// Output of the actual 24 input voices that have wet output enabled.
, CoreSrc_WetVoiceMix
CoreSrc_WetVoiceMix,
// Wet mix including inputs and externals, prior to the application of reverb.
, CoreSrc_PreReverb
CoreSrc_PreReverb,
// Wet mix after reverb has turned it into a pile of garbly gook.
, CoreSrc_PostReverb
CoreSrc_PostReverb,
// Final output of the core. For core 0, it's the feed into Core1.
// For Core1, it's the feed into SndOut.
, CoreSrc_External
CoreSrc_External,
, CoreSrc_Count
CoreSrc_Count
};
extern void Open();

View File

@ -41,17 +41,17 @@ static const u8 sLogTable[256] = {
0xDA, 0xDC, 0xDC, 0xDC, 0xDC, 0xDC, 0xDC, 0xDE, 0xDE, 0xDE, 0xDE, 0xDE, 0xDE, 0xE0, 0xE0, 0xE0,
};
DPLII::DPLII( s32 lowpass_freq, s32 samplerate ) :
LAccum( 0 ),
RAccum( 0 ),
ANum( 0 ),
lpf_l( lowpass_freq, samplerate ),
lpf_r( lowpass_freq, samplerate ),
bufdone( 1 ),
Gfl( 0 ),
Gfr( 0 ),
LMax( 0 ),
RMax( 0 )
DPLII::DPLII(s32 lowpass_freq, s32 samplerate)
: LAccum(0)
, RAccum(0)
, ANum(0)
, lpf_l(lowpass_freq, samplerate)
, lpf_r(lowpass_freq, samplerate)
, bufdone(1)
, Gfl(0)
, Gfr(0)
, LMax(0)
, RMax(0)
{
memset(LBuff, 0, sizeof(LBuff));
memset(RBuff, 0, sizeof(RBuff));
@ -64,12 +64,9 @@ void DPLII::Convert( s16 *obuffer, s32 ValL, s32 ValR )
{
ValL >>= 2;
ValR >>= 2;
if(PlayMode&4)
{
if (PlayMode & 4) {
spdif_get_samples(spdif_data);
}
else
{
} else {
spdif_data[0] = 0;
spdif_data[1] = 0;
spdif_data[2] = 0;
@ -83,12 +80,13 @@ void DPLII::Convert( s16 *obuffer, s32 ValL, s32 ValR )
s32 XL = abs(ValL >> 8);
s32 XR = abs(ValR >> 8);
if(XL>LMax) LMax = XL;
if(XR>RMax) RMax = XR;
if (XL > LMax)
LMax = XL;
if (XR > RMax)
RMax = XR;
ANum++;
if(ANum>=128)
{
if (ANum >= 128) {
ANum = 0;
LAccum = 1 + ((LAccum * 224 + LMax * 31) >> 8);
RAccum = 1 + ((RAccum * 224 + RMax * 31) >> 8);
@ -103,14 +101,17 @@ void DPLII::Convert( s16 *obuffer, s32 ValL, s32 ValR )
Tfl = Tfl * 255 / gMax;
Tfr = Tfr * 255 / gMax;
if(Tfl>255) Tfl=255;
if(Tfr>255) Tfr=255;
if(Tfl<1) Tfl=1;
if(Tfr<1) Tfr=1;
if (Tfl > 255)
Tfl = 255;
if (Tfr > 255)
Tfr = 255;
if (Tfl < 1)
Tfl = 1;
if (Tfr < 1)
Tfr = 1;
Gfl = (Gfl * 200 + Tfl * 56) >> 8;
Gfr = (Gfr * 200 + Tfr * 56) >> 8;
}
s32 L, R, C, LFE, SL, SR, LL, LR;

View File

@ -32,7 +32,8 @@ static FILE *REGWRTLogFile[2] = {0,0};
void DMALogOpen()
{
if(!DMALog()) return;
if (!DMALog())
return;
DMA4LogFile = OpenBinaryLog(DMA4LogFileName);
DMA7LogFile = OpenBinaryLog(DMA7LogFileName);
ADMA4LogFile = OpenBinaryLog(L"adma4.raw");
@ -40,28 +41,39 @@ void DMALogOpen()
ADMAOutLogFile = OpenBinaryLog(L"admaOut.raw");
}
void DMA4LogWrite(void *lpData, u32 ulSize) {
if(!DMALog()) return;
if (!DMA4LogFile) return;
void DMA4LogWrite(void *lpData, u32 ulSize)
{
if (!DMALog())
return;
if (!DMA4LogFile)
return;
fwrite(lpData, ulSize, 1, DMA4LogFile);
}
void DMA7LogWrite(void *lpData, u32 ulSize) {
if(!DMALog()) return;
if (!DMA7LogFile) return;
void DMA7LogWrite(void *lpData, u32 ulSize)
{
if (!DMALog())
return;
if (!DMA7LogFile)
return;
fwrite(lpData, ulSize, 1, DMA7LogFile);
}
void ADMAOutLogWrite(void *lpData, u32 ulSize) {
if(!DMALog()) return;
if (!ADMAOutLogFile) return;
void ADMAOutLogWrite(void *lpData, u32 ulSize)
{
if (!DMALog())
return;
if (!ADMAOutLogFile)
return;
fwrite(lpData, ulSize, 1, ADMAOutLogFile);
}
void RegWriteLog(u32 core, u16 value)
{
if(!DMALog()) return;
if (!REGWRTLogFile[core]) return;
if (!DMALog())
return;
if (!REGWRTLogFile[core])
return;
fwrite(&value, 2, 1, REGWRTLogFile[core]);
}
@ -78,7 +90,8 @@ void DMALogClose()
void V_Core::LogAutoDMA(FILE *fp)
{
if( !DMALog() || !fp || !DMAPtr ) return;
if (!DMALog() || !fp || !DMAPtr)
return;
fwrite(DMAPtr + InputDataProgress, 0x400, 1, fp);
}
@ -93,17 +106,14 @@ void V_Core::AutoDMAReadBuffer(int mode) //mode: 0= split stereo; 1 = do not spl
// to NULL and we ignore it here. (used to work in old VM editions of PCSX2 with fixed
// addressing, but new PCSX2s have dynamic memory addressing).
if(mode)
{
if (mode) {
if (DMAPtr != NULL)
//memcpy((ADMATempBuffer+(spos<<1)),DMAPtr+InputDataProgress,0x400);
memcpy(GetMemPtr(0x2000 + (Index << 10) + spos), DMAPtr + InputDataProgress, 0x400);
MADR += 0x400;
InputDataLeft -= 0x200;
InputDataProgress += 0x200;
}
else
{
} else {
if (DMAPtr != NULL)
//memcpy((ADMATempBuffer+spos),DMAPtr+InputDataProgress,0x200);
memcpy(GetMemPtr(0x2000 + (Index << 10) + spos), DMAPtr + InputDataProgress, 0x200);
@ -128,27 +138,21 @@ void V_Core::StartADMAWrite(u16 *pMem, u32 sz)
#ifndef ENABLE_NEW_IOPDMA_SPU2
int size = (sz) & (~511);
if(MsgAutoDMA()) ConLog("* SPU2-X: DMA%c AutoDMA Transfer of %d bytes to %x (%02x %x %04x).\n",
if (MsgAutoDMA())
ConLog("* SPU2-X: DMA%c AutoDMA Transfer of %d bytes to %x (%02x %x %04x).\n",
GetDmaIndexChar(), size << 1, TSA, DMABits, AutoDMACtrl, (~Regs.ATTR) & 0x7fff);
InputDataProgress = 0;
if((AutoDMACtrl&(Index+1))==0)
{
if ((AutoDMACtrl & (Index + 1)) == 0) {
TSA = 0x2000 + (Index << 10);
DMAICounter = size;
}
else if(size>=512)
{
} else if (size >= 512) {
InputDataLeft = size;
if(AdmaInProgress==0)
{
if (AdmaInProgress == 0) {
#ifdef PCM24_S1_INTERLEAVE
if((Index==1)&&((PlayMode&8)==8))
{
if ((Index == 1) && ((PlayMode & 8) == 8)) {
AutoDMAReadBuffer(Index, 1);
}
else
{
} else {
AutoDMAReadBuffer(Index, 0);
}
#else
@ -163,9 +167,7 @@ void V_Core::StartADMAWrite(u16 *pMem, u32 sz)
}
AdmaInProgress = 1;
}
else
{
} else {
InputDataLeft = 0;
DMAICounter = 1;
}
@ -203,8 +205,7 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
ConLog("* SPU2 DMA Write > Misaligned source. Core: %d IOP: %p TSA: 0x%x Size: 0x%x\n", Index, (void*)pMem, TSA, size);
}*/
if(TSA & 7)
{
if (TSA & 7) {
ConLog("* SPU2 DMA Write > Misaligned target. Core: %d IOP: %p TSA: 0x%x Size: 0x%x\n", Index, (void *)pMem, TSA, size);
}
}
@ -218,8 +219,7 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
u32 buff1end = TSA + size;
u32 buff2end = 0;
if( buff1end > 0x100000 )
{
if (buff1end > 0x100000) {
buff2end = buff1end - 0x100000;
buff1end = 0x100000;
}
@ -229,8 +229,7 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
PcmCacheEntry *cacheLine = &pcm_cache_data[cacheIdxStart];
PcmCacheEntry &cacheEnd = pcm_cache_data[cacheIdxEnd];
do
{
do {
cacheLine->Validated = false;
cacheLine++;
} while (cacheLine != &cacheEnd);
@ -247,8 +246,7 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
u32 TDA;
if( buff2end > 0 )
{
if (buff2end > 0) {
// second branch needs copied:
// It starts at the beginning of memory and moves forward to buff2end
@ -268,8 +266,7 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
// Note: Because this buffer wraps, we use || instead of &&
#if NO_BIOS_HACKFIX
for( int i=0; i<2; i++ )
{
for (int i = 0; i < 2; i++) {
// Start is exclusive and end is inclusive... maybe? The end is documented to be inclusive,
// which suggests that memory access doesn't trigger interrupts, incrementing registers does
// (which would mean that if TSA=IRQA an interrupt doesn't fire... I guess?)
@ -279,8 +276,7 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
// understanding would trigger the interrupt early causing it to switch buffers again immediately
// and an interrupt never fires again, leaving the voices looping the same samples forever.
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA || Cores[i].IRQA <= TDA))
{
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA || Cores[i].IRQA <= TDA)) {
//ConLog("DMAwrite Core %d: IRQ Called (IRQ passed). IRQA = %x Cycles = %d\n", i, Cores[i].IRQA, Cycles );
SetIrqCall(i);
}
@ -291,9 +287,7 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
SetIrqCall(Index);
}
#endif
}
else
{
} else {
// Buffer doesn't wrap/overflow!
// Just set the TDA and check for an IRQ...
@ -303,17 +297,14 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
// Important: Test both core IRQ settings for either DMA!
#if NO_BIOS_HACKFIX
for( int i=0; i<2; i++ )
{
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA && Cores[i].IRQA <= TDA))
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA && Cores[i].IRQA <= TDA)) {
//ConLog("DMAwrite Core %d: IRQ Called (IRQ passed). IRQA = %x Cycles = %d\n", i, Cores[i].IRQA, Cycles );
SetIrqCall(i);
}
}
#else
if( IRQEnable && (IRQA > TSA) && (IRQA <= TDA) )
{
if (IRQEnable && (IRQA > TSA) && (IRQA <= TDA)) {
SetIrqCall(Index);
}
#endif
@ -331,8 +322,7 @@ void V_Core::DoDMAread(u16* pMem, u32 size)
u32 buff1end = TSA + size;
u32 buff2end = 0;
if( buff1end > 0x100000 )
{
if (buff1end > 0x100000) {
buff2end = buff1end - 0x100000;
buff1end = 0x100000;
}
@ -346,8 +336,7 @@ void V_Core::DoDMAread(u16* pMem, u32 size)
u32 TDA;
if( buff2end > 0 )
{
if (buff2end > 0) {
// second branch needs cleared:
// It starts at the beginning of memory and moves forward to buff2end
@ -359,16 +348,12 @@ void V_Core::DoDMAread(u16* pMem, u32 size)
// Important: Test both core IRQ settings for either DMA!
// Note: Because this buffer wraps, we use || instead of &&
for( int i=0; i<2; i++ )
{
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA || Cores[i].IRQA <= TDA))
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA || Cores[i].IRQA <= TDA)) {
SetIrqCall(i);
}
}
}
else
{
} else {
// Buffer doesn't wrap/overflow!
// Just set the TDA and check for an IRQ...
@ -377,10 +362,8 @@ void V_Core::DoDMAread(u16* pMem, u32 size)
// Flag interrupt? If IRQA occurs between start and dest, flag it.
// Important: Test both core IRQ settings for either DMA!
for( int i=0; i<2; i++ )
{
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA && Cores[i].IRQA <= TDA))
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA && Cores[i].IRQA <= TDA)) {
SetIrqCall(i);
}
}
@ -409,14 +392,12 @@ void V_Core::DoDMAwrite(u16* pMem, u32 size)
return;
}
if( IsDevBuild )
{
if (IsDevBuild) {
DebugCores[Index].lastsize = size;
DebugCores[Index].dmaFlag = 2;
}
if(MsgToConsole())
{
if (MsgToConsole()) {
if (TSA > 0xfffff) {
ConLog("* SPU2-X: Transfer Start Address out of bounds. TSA is %x\n", TSA);
}
@ -426,14 +407,12 @@ void V_Core::DoDMAwrite(u16* pMem, u32 size)
bool adma_enable = ((AutoDMACtrl & (Index + 1)) == (Index + 1));
if(adma_enable)
{
if (adma_enable) {
TSA &= 0x1fff;
StartADMAWrite(pMem, size);
}
else
{
if(MsgDMA()) ConLog("* SPU2-X: DMA%c Transfer of %d bytes to %x (%02x %x %04x). IRQE = %d IRQA = %x \n",
} else {
if (MsgDMA())
ConLog("* SPU2-X: DMA%c Transfer of %d bytes to %x (%02x %x %04x). IRQE = %d IRQA = %x \n",
GetDmaIndexChar(), size << 1, TSA, DMABits, AutoDMACtrl, (~Regs.ATTR) & 0x7fff,
Cores[0].IRQEnable, Cores[0].IRQA);
@ -456,8 +435,7 @@ s32 V_Core::NewDmaRead(u32* data, u32 bytesLeft, u32* bytesProcessed)
u32 buff1end = TSA + bytesLeft;
u32 buff2end = 0;
if( buff1end > 0x100000 )
{
if (buff1end > 0x100000) {
buff2end = buff1end - 0x100000;
buff1end = 0x100000;
}
@ -471,8 +449,7 @@ s32 V_Core::NewDmaRead(u32* data, u32 bytesLeft, u32* bytesProcessed)
u32 TDA;
if( buff2end > 0 )
{
if (buff2end > 0) {
// second branch needs cleared:
// It starts at the beginning of memory and moves forward to buff2end
@ -484,16 +461,12 @@ s32 V_Core::NewDmaRead(u32* data, u32 bytesLeft, u32* bytesProcessed)
// Important: Test both core IRQ settings for either DMA!
// Note: Because this buffer wraps, we use || instead of &&
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && (Cores[i].IRQA > TSA || Cores[i].IRQA <= TDA) )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA || Cores[i].IRQA <= TDA)) {
SetIrqCall(i);
}
}
}
else
{
} else {
// Buffer doesn't wrap/overflow!
// Just set the TDA and check for an IRQ...
@ -502,10 +475,8 @@ s32 V_Core::NewDmaRead(u32* data, u32 bytesLeft, u32* bytesProcessed)
// Flag interrupt? If IRQA occurs between start and dest, flag it.
// Important: Test both core IRQ settings for either DMA!
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && (Cores[i].IRQA > TSA) && (Cores[i].IRQA <= TDA) )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > TSA) && (Cores[i].IRQA <= TDA)) {
SetIrqCall(i);
}
}
@ -527,8 +498,7 @@ s32 V_Core::NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed)
bool DmaStarting = !DmaStarted;
DmaStarted = true;
if(bytesLeft<2)
{
if (bytesLeft < 2) {
// execute interrupt code early
NewDmaInterrupt();
@ -536,8 +506,7 @@ s32 V_Core::NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed)
return 0;
}
if( IsDevBuild )
{
if (IsDevBuild) {
DebugCores[Index].lastsize = bytesLeft;
DebugCores[Index].dmaFlag = 1;
}
@ -546,16 +515,15 @@ s32 V_Core::NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed)
bool adma_enable = ((AutoDMACtrl & (Index + 1)) == (Index + 1));
if(adma_enable)
{
if (adma_enable) {
TSA &= 0x1fff;
if(MsgAutoDMA() && DmaStarting) ConLog("* SPU2-X: DMA%c AutoDMA Transfer of %d bytes to %x (%02x %x %04x).\n",
if (MsgAutoDMA() && DmaStarting)
ConLog("* SPU2-X: DMA%c AutoDMA Transfer of %d bytes to %x (%02x %x %04x).\n",
GetDmaIndexChar(), bytesLeft << 1, TSA, DMABits, AutoDMACtrl, (~Regs.ATTR) & 0x7fff);
u32 processed = 0;
while((AutoDmaFree>0)&&(bytesLeft>=0x400))
{
while ((AutoDmaFree > 0) && (bytesLeft >= 0x400)) {
// copy block
LogAutoDMA(Index ? ADMA7LogFile : ADMA4LogFile);
@ -578,16 +546,12 @@ s32 V_Core::NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed)
u32 dummyTSA = 0x2000 + (Index << 10) + InputPosWrite;
u32 dummyTDA = 0x2000 + (Index << 10) + InputPosWrite + 0x200;
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && (Cores[i].IRQA > dummyTSA) && (Cores[i].IRQA <= dummyTDA) )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > dummyTSA) && (Cores[i].IRQA <= dummyTDA)) {
SetIrqCall(i);
}
}
}
else
{
} else {
//memcpy((ADMATempBuffer+InputPosWrite),mptr,0x200);
memcpy(GetMemPtr(0x2000 + (Index << 10) + InputPosWrite), mptr, 0x200);
mptr += 0x100;
@ -598,10 +562,8 @@ s32 V_Core::NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed)
u32 dummyTSA = 0x2000 + (Index << 10) + InputPosWrite;
u32 dummyTDA = 0x2000 + (Index << 10) + InputPosWrite + 0x100;
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && (Cores[i].IRQA > dummyTSA) && (Cores[i].IRQA <= dummyTDA) )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > dummyTSA) && (Cores[i].IRQA <= dummyTDA)) {
SetIrqCall(i);
}
}
@ -616,14 +578,11 @@ s32 V_Core::NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed)
dummyTSA = 0x2200 + (Index << 10) + InputPosWrite;
dummyTDA = 0x2200 + (Index << 10) + InputPosWrite + 0x100;
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && (Cores[i].IRQA > dummyTSA) && (Cores[i].IRQA <= dummyTDA) )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA > dummyTSA) && (Cores[i].IRQA <= dummyTDA)) {
SetIrqCall(i);
}
}
}
// See ReadInput at mixer.cpp for explanation on the commented out lines
//
@ -634,20 +593,16 @@ s32 V_Core::NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed)
bytesLeft -= 0x400;
}
if(processed==0)
{
if (processed == 0) {
*bytesProcessed = 0;
return 768 * 15; // pause a bit
}
else
{
} else {
*bytesProcessed = processed;
return 0; // auto pause
}
}
else
{
if(MsgDMA() && DmaStarting) ConLog("* SPU2-X: DMA%c Transfer of %d bytes to %x (%02x %x %04x).\n",
} else {
if (MsgDMA() && DmaStarting)
ConLog("* SPU2-X: DMA%c Transfer of %d bytes to %x (%02x %x %04x).\n",
GetDmaIndexChar(), bytesLeft, TSA, DMABits, AutoDMACtrl, (~Regs.ATTR) & 0x7fff);
if (bytesLeft > 2048)

View File

@ -49,8 +49,7 @@ protected:
fprintf(stderr, "* SPU2-X:Iz in your internal callback.\n");
avail = snd_pcm_avail_update(handle);
while (avail >= (int)period_time )
{
while (avail >= (int)period_time) {
StereoOut16 buff[PacketsPerBuffer * SndOutPacketSize];
StereoOut16 *p1 = buff;
@ -73,8 +72,7 @@ protected:
//pxAssume( data->handle == snd_async_handler_get_pcm(pcm_call) );
// Not sure if we just need an assert, or something like this:
if (data->handle != snd_async_handler_get_pcm(pcm_call))
{
if (data->handle != snd_async_handler_get_pcm(pcm_call)) {
fprintf(stderr, "* SPU2-X: Failed to handle sound.\n");
return;
}
@ -83,7 +81,6 @@ protected:
}
public:
s32 Init()
{
//fprintf(stderr,"* SPU2-X: Initing Alsa\n");
@ -105,15 +102,13 @@ public:
int err;
err = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC /*| SND_PCM_NONBLOCK*/);
if(err < 0)
{
if (err < 0) {
fprintf(stderr, "Audio open error: %s\n", snd_strerror(err));
return -1;
}
err = snd_pcm_nonblock(handle, 0);
if(err < 0)
{
if (err < 0) {
fprintf(stderr, "Can't set blocking mode: %s\n", snd_strerror(err));
return -1;
}
@ -122,35 +117,30 @@ public:
snd_pcm_sw_params_alloca(&swparams);
err = snd_pcm_hw_params_any(handle, hwparams);
if (err < 0)
{
if (err < 0) {
fprintf(stderr, "Broken configuration for this PCM: %s\n", snd_strerror(err));
return -1;
}
err = snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0)
{
if (err < 0) {
fprintf(stderr, "Access type not available: %s\n", snd_strerror(err));
return -1;
}
err = snd_pcm_hw_params_set_format(handle, hwparams, format);
if (err < 0)
{
if (err < 0) {
fprintf(stderr, "Sample format not available: %s\n", snd_strerror(err));
return -1;
}
err = snd_pcm_hw_params_set_channels(handle, hwparams, pchannels);
if (err < 0)
{
if (err < 0) {
fprintf(stderr, "Channels count not available: %s\n", snd_strerror(err));
return -1;
}
err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &pspeed, 0);
if (err < 0)
{
if (err < 0) {
fprintf(stderr, "Rate not available: %s\n", snd_strerror(err));
return -1;
}
@ -162,37 +152,34 @@ public:
}
err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0);
if (err < 0)
{
if (err < 0) {
fprintf(stderr, "Period time error: %s\n", snd_strerror(err));
return -1;
}
err = snd_pcm_hw_params(handle, hwparams);
if (err < 0)
{
if (err < 0) {
fprintf(stderr, "Unable to install hw params: %s\n", snd_strerror(err));
return -1;
}
snd_pcm_status_alloca(&status);
err = snd_pcm_status(handle, status);
if(err < 0)
{
if (err < 0) {
fprintf(stderr, "Unable to get status: %s\n", snd_strerror(err));
return -1;
}
// Bind our asynchronous callback magic:
if (handle == NULL) fprintf(stderr, "No handle.");
if (handle == NULL)
fprintf(stderr, "No handle.");
//fprintf(stderr,"* SPU2-X:Iz setting your internal callback.\n");
// The external handler never seems to get called after this.
snd_async_add_pcm_handler(&pcm_callback, handle, ExternalCallback, this);
err = snd_pcm_start(handle);
if(err < 0)
{
if (err < 0) {
fprintf(stderr, "Pcm start failed: %s\n", snd_strerror(err));
return -1;
}
@ -206,7 +193,8 @@ public:
void Close()
{
//fprintf(stderr,"* SPU2-X: Closing Alsa\n");
if(handle == NULL) return;
if (handle == NULL)
return;
snd_pcm_drop(handle);
snd_pcm_close(handle);
@ -226,15 +214,15 @@ public:
int GetEmptySampleCount()
{
if(handle == NULL)
{
if (handle == NULL) {
fprintf(stderr, "Handle is NULL!\n");
return 0;
}
// Returns the amount of free buffer space, in samples.
int l = snd_pcm_avail_update(handle);
if( l < 0 ) return 0;
if (l < 0)
return 0;
return (l / 1000) * (SampleRate / 1000);
}

View File

@ -24,7 +24,8 @@
void initIni()
{
if (spuConfig == NULL) spuConfig = new wxFileConfig(L"", L"", path, L"", wxCONFIG_USE_LOCAL_FILE);
if (spuConfig == NULL)
spuConfig = new wxFileConfig(L"", L"", path, L"", wxCONFIG_USE_LOCAL_FILE);
}
void setIni(const wchar_t *Section)

View File

@ -86,8 +86,7 @@ void ReadSettings()
{
// For some reason this can be called before we know what ini file we're writing to.
// Lets not try to read it if that happens.
if (!pathSet)
{
if (!pathSet) {
FileLog("Read called without the path set.\n");
return;
}
@ -96,7 +95,8 @@ void ReadSettings()
EffectsDisabled = CfgReadBool(L"MIXING", L"Disable_Effects", false);
postprocess_filter_dealias = CfgReadBool(L"MIXING", L"DealiasFilter", false);
FinalVolume = ((float)CfgReadInt(L"MIXING", L"FinalVolume", 100)) / 100;
if ( FinalVolume > 1.0f) FinalVolume = 1.0f;
if (FinalVolume > 1.0f)
FinalVolume = 1.0f;
AdvancedVolumeControl = CfgReadBool(L"MIXING", L"AdvancedVolumeControl", false);
VolumeAdjustCdb = CfgReadFloat(L"MIXING", L"VolumeAdjustC(dB)", 0);
@ -126,14 +126,18 @@ void ReadSettings()
#ifdef __linux__
CfgReadStr(L"PORTAUDIO", L"HostApi", temp, L"ALSA");
OutputAPI = -1;
if (temp == L"ALSA") OutputAPI = 0;
if (temp == L"OSS") OutputAPI = 1;
if (temp == L"JACK") OutputAPI = 2;
if (temp == L"ALSA")
OutputAPI = 0;
if (temp == L"OSS")
OutputAPI = 1;
if (temp == L"JACK")
OutputAPI = 2;
#else
CfgReadStr(L"PORTAUDIO", L"HostApi", temp, L"OSS");
OutputAPI = -1;
if (temp == L"OSS") OutputAPI = 0;
if (temp == L"OSS")
OutputAPI = 0;
#endif
#ifdef __linux__
@ -171,8 +175,7 @@ void ReadSettings()
void WriteSettings()
{
if (!pathSet)
{
if (!pathSet) {
FileLog("Write called without the path set.\n");
return;
}
@ -362,8 +365,7 @@ void DisplayDialog()
return_value = gtk_dialog_run(GTK_DIALOG(dialog));
if (return_value == GTK_RESPONSE_ACCEPT)
{
if (return_value == GTK_RESPONSE_ACCEPT) {
DebugEnabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(debug_check));
postprocess_filter_dealias = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dealias_filter));
if (gtk_combo_box_get_active(GTK_COMBO_BOX(int_box)) != -1)
@ -379,15 +381,25 @@ void DisplayDialog()
OutputAPI = gtk_combo_box_get_active(GTK_COMBO_BOX(api_box));
#ifdef __linux__
switch (OutputAPI) {
case 0: PortaudioOut->SetApiSettings(L"ALSA"); break;
case 1: PortaudioOut->SetApiSettings(L"OSS"); break;
case 2: PortaudioOut->SetApiSettings(L"JACK"); break;
default: PortaudioOut->SetApiSettings(L"Unknown");
case 0:
PortaudioOut->SetApiSettings(L"ALSA");
break;
case 1:
PortaudioOut->SetApiSettings(L"OSS");
break;
case 2:
PortaudioOut->SetApiSettings(L"JACK");
break;
default:
PortaudioOut->SetApiSettings(L"Unknown");
}
#else
switch (OutputAPI) {
case 0: PortaudioOut->SetApiSettings(L"OSS"); break;
default: PortaudioOut->SetApiSettings(L"Unknown");
case 0:
PortaudioOut->SetApiSettings(L"OSS");
break;
default:
PortaudioOut->SetApiSettings(L"Unknown");
}
#endif
}
@ -411,7 +423,6 @@ void DisplayDialog()
#else
void DisplayDialog()
{
}
#endif

View File

@ -75,7 +75,8 @@ FILE* OpenDump( const wxString& logfile )
return wxFopen(Path::Combine(DumpsFolder, logfile), L"w");
}
namespace DebugConfig {
namespace DebugConfig
{
static const wchar_t *Section = L"DEBUG";
static void set_default_filenames()
@ -151,7 +152,6 @@ void WriteSettings()
CfgWriteStr(Section, L"Info_Dump_Filename", CoresDumpFileName);
CfgWriteStr(Section, L"Mem_Dump_Filename", MemDumpFileName);
CfgWriteStr(Section, L"Reg_Dump_Filename", RegDumpFileName);
}
#ifdef __unix__
@ -263,8 +263,7 @@ void DisplayDialog()
return_value = gtk_dialog_run(GTK_DIALOG(dialog));
if (return_value == GTK_RESPONSE_ACCEPT)
{
if (return_value == GTK_RESPONSE_ACCEPT) {
_MsgToConsole = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(msg_console_check));
_MsgKeyOnOff = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(msg_key_check));
_MsgVoiceOff = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(msg_voice_check));
@ -289,7 +288,6 @@ void DisplayDialog()
#else
void DisplayDialog()
{
}
#endif
}

View File

@ -150,11 +150,10 @@ namespace SoundtouchCfg
return_value = gtk_dialog_run(GTK_DIALOG(dialog));
if (return_value == GTK_RESPONSE_ACCEPT)
{
SequenceLenMS = gtk_range_get_value(GTK_RANGE(seq_slide));;
SeekWindowMS = gtk_range_get_value(GTK_RANGE(seek_slide));;
OverlapMS = gtk_range_get_value(GTK_RANGE(over_slide));;
if (return_value == GTK_RESPONSE_ACCEPT) {
SequenceLenMS = gtk_range_get_value(GTK_RANGE(seq_slide));
SeekWindowMS = gtk_range_get_value(GTK_RANGE(seek_slide));
OverlapMS = gtk_range_get_value(GTK_RANGE(over_slide));
}
gtk_widget_destroy(dialog);
@ -164,12 +163,10 @@ namespace SoundtouchCfg
#else
void DisplayDialog()
{
}
void restore_defaults()
{
}
#endif
}

View File

@ -32,7 +32,8 @@ void SysMessage(const char *fmt, ...)
vsprintf(msg, fmt, list);
va_end(list);
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
@ -71,4 +72,3 @@ s32 DspLoadLibrary(wchar_t* fileName, int modnum)
{
return 0;
}

View File

@ -20,8 +20,8 @@
#include <math.h>
#include <float.h>
template< typename FloatType > __forceinline
LowPassFilter<FloatType>::LowPassFilter( FloatType freq, FloatType srate )
template <typename FloatType>
__forceinline LowPassFilter<FloatType>::LowPassFilter(FloatType freq, FloatType srate)
{
typedef FloatType FT;
@ -61,8 +61,8 @@ LowPassFilter<FloatType>::LowPassFilter( FloatType freq, FloatType srate )
}
// Processes a single sample into the LPF.
template< typename FloatType > __forceinline
FloatType LowPassFilter<FloatType>::sample( FloatType inval )
template <typename FloatType>
__forceinline FloatType LowPassFilter<FloatType>::sample(FloatType inval)
{
const FloatType out = (coef[0] * inval) + d[0];
d[0] = (coef[1] * inval) + (coef[5] * out) + d[1];
@ -73,13 +73,13 @@ FloatType LowPassFilter<FloatType>::sample( FloatType inval )
return out;
}
LowPassFilter32::LowPassFilter32( float freq, float srate ) :
impl_lpf( freq, srate )
LowPassFilter32::LowPassFilter32(float freq, float srate)
: impl_lpf(freq, srate)
{
}
LowPassFilter64::LowPassFilter64( double freq, double srate ) :
impl_lpf( freq, srate )
LowPassFilter64::LowPassFilter64(double freq, double srate)
: impl_lpf(freq, srate)
{
}

View File

@ -30,8 +30,7 @@ static const s32 tbl_XA_Factor[16][2] =
{60, 0},
{115, -52},
{98, -55},
{ 122, -60 }
};
{122, -60}};
// Performs a 64-bit multiplication between two values and returns the
@ -66,15 +65,15 @@ __forceinline
// inline. Gcc 4.5 has the experimental options -flto, -fwhopr and -fwhole-program to
// do it but it still experimental...
#endif
StereoOut32 clamp_mix( const StereoOut32& sample, u8 bitshift )
StereoOut32
clamp_mix(const StereoOut32 &sample, u8 bitshift)
{
// We should clampify between -0x8000 and 0x7fff, however some audio output
// modules or sound drivers could (will :p) overshoot with that. So giving it a small safety.
return StereoOut32(
GetClamped(sample.Left, -0x7f00 << bitshift, 0x7f00 << bitshift),
GetClamped( sample.Right, -0x7f00<<bitshift, 0x7f00<<bitshift )
);
GetClamped(sample.Right, -0x7f00 << bitshift, 0x7f00 << bitshift));
}
static void __forceinline XA_decode_block(s16 *buffer, const s16 *block, s32 &prev1, s32 &prev2)
@ -90,8 +89,7 @@ static void __forceinline XA_decode_block(s16* buffer, const s16* block, s32& pr
const s8 *blockbytes = (s8 *)&block[1];
const s8 *blockend = &blockbytes[13];
for(; blockbytes<=blockend; ++blockbytes)
{
for (; blockbytes <= blockend; ++blockbytes) {
s32 data = ((*blockbytes) << 28) & 0xF0000000;
s32 pcm = (data >> shift) + (((pred1 * prev1) + (pred2 * prev2) + 32) >> 6);
@ -116,10 +114,8 @@ static void __forceinline IncrementNextA(V_Core& thiscore, uint voiceidx)
// Important! Both cores signal IRQ when an address is read, regardless of
// which core actually reads the address.
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && (vc.NextA==Cores[i].IRQA ) )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (vc.NextA == Cores[i].IRQA)) {
//if( IsDevBuild )
// ConLog(" * SPU2 Core %d: IRQ Requested (IRQA (%05X) passed; voice %d).\n", i, Cores[i].IRQA, thiscore.Index * 24 + voiceidx);
@ -153,33 +149,28 @@ static __forceinline s32 GetNextDataBuffered( V_Core& thiscore, uint voiceidx )
{
V_Voice &vc(thiscore.Voices[voiceidx]);
if( (vc.SCurrent&3) == 0 )
{
if ((vc.SCurrent & 3) == 0) {
IncrementNextA(thiscore, voiceidx);
if ((vc.NextA & 7) == 0) // vc.SCurrent == 24 equivalent
{
if(vc.LoopFlags & XAFLAG_LOOP_END)
{
if (vc.LoopFlags & XAFLAG_LOOP_END) {
thiscore.Regs.ENDX |= (1 << voiceidx);
vc.NextA = vc.LoopStartA | 1;
if (!(vc.LoopFlags & XAFLAG_LOOP))
{
if (!(vc.LoopFlags & XAFLAG_LOOP)) {
vc.Stop();
if( IsDevBuild )
{
if(MsgVoiceOff()) ConLog("* SPU2-X: Voice Off by EndPoint: %d \n", voiceidx);
if (IsDevBuild) {
if (MsgVoiceOff())
ConLog("* SPU2-X: Voice Off by EndPoint: %d \n", voiceidx);
}
}
}
else
} else
vc.NextA++; // no, don't IncrementNextA here. We haven't read the header yet.
}
}
if( vc.SCurrent == 28 )
{
if (vc.SCurrent == 28) {
vc.SCurrent = 0;
// We'll need the loop flags and buffer pointers regardless of cache status:
@ -198,8 +189,7 @@ static __forceinline s32 GetNextDataBuffered( V_Core& thiscore, uint voiceidx )
PcmCacheEntry &cacheLine = pcm_cache_data[cacheIdx];
vc.SBuffer = cacheLine.Sampledata;
if( cacheLine.Validated )
{
if (cacheLine.Validated) {
// Cached block! Read from the cache directly.
// Make sure to propagate the prev1/prev2 ADPCM:
@ -210,15 +200,12 @@ static __forceinline s32 GetNextDataBuffered( V_Core& thiscore, uint voiceidx )
if (IsDevBuild)
g_counter_cache_hits++;
}
else
{
} else {
// Only flag the cache if it's a non-dynamic memory range.
if (vc.NextA >= SPU2_DYN_MEMLINE)
cacheLine.Validated = true;
if( IsDevBuild )
{
if (IsDevBuild) {
if (vc.NextA < SPU2_DYN_MEMLINE)
g_counter_cache_ignores++;
else
@ -240,17 +227,14 @@ static __forceinline void GetNextDataDummy(V_Core& thiscore, uint voiceidx)
if ((vc.NextA & 7) == 0) // vc.SCurrent == 24 equivalent
{
if(vc.LoopFlags & XAFLAG_LOOP_END)
{
if (vc.LoopFlags & XAFLAG_LOOP_END) {
thiscore.Regs.ENDX |= (1 << voiceidx);
vc.NextA = vc.LoopStartA | 1;
}
else
} else
vc.NextA++; // no, don't IncrementNextA here. We haven't read the header yet.
}
if (vc.SCurrent == 28)
{
if (vc.SCurrent == 28) {
for (int i = 0; i < 2; i++)
if (Cores[i].IRQEnable && Cores[i].IRQA == (vc.NextA & 0xFFFF8))
SetIrqCall(i);
@ -306,16 +290,14 @@ static __forceinline StereoOut32 ApplyVolume( const StereoOut32& data, const V_V
{
return StereoOut32(
ApplyVolume(data.Left, volume.Left),
ApplyVolume( data.Right, volume.Right )
);
ApplyVolume(data.Right, volume.Right));
}
static __forceinline StereoOut32 ApplyVolume(const StereoOut32 &data, const V_VolumeSlideLR &volume)
{
return StereoOut32(
ApplyVolume(data.Left, volume.Left.Value),
ApplyVolume( data.Right, volume.Right.Value )
);
ApplyVolume(data.Right, volume.Right.Value));
}
static void __forceinline UpdatePitch(uint coreidx, uint voiceidx)
@ -340,17 +322,15 @@ static __forceinline void CalculateADSR( V_Core& thiscore, uint voiceidx )
{
V_Voice &vc(thiscore.Voices[voiceidx]);
if( vc.ADSR.Phase==0 )
{
if (vc.ADSR.Phase == 0) {
vc.ADSR.Value = 0;
return;
}
if( !vc.ADSR.Calculate() )
{
if( IsDevBuild )
{
if(MsgVoiceOff()) ConLog("* SPU2-X: Voice Off by ADSR: %d \n", voiceidx);
if (!vc.ADSR.Calculate()) {
if (IsDevBuild) {
if (MsgVoiceOff())
ConLog("* SPU2-X: Voice Off by ADSR: %d \n", voiceidx);
}
vc.Stop();
}
@ -362,8 +342,7 @@ static __forceinline void CalculateADSR( V_Core& thiscore, uint voiceidx )
Tension: 65535 is high, 32768 is normal, 0 is low
*/
template <s32 i_tension>
__forceinline
static s32 HermiteInterpolate(
__forceinline static s32 HermiteInterpolate(
s32 y0, // 16.0
s32 y1, // 16.0
s32 y2, // 16.0
@ -386,8 +365,7 @@ static s32 HermiteInterpolate(
return (val + (y1 << 1));
}
__forceinline
static s32 CatmullRomInterpolate(
__forceinline static s32 CatmullRomInterpolate(
s32 y0, // 16.0
s32 y1, // 16.0
s32 y2, // 16.0
@ -412,8 +390,7 @@ static s32 CatmullRomInterpolate(
return (a0 + val);
}
__forceinline
static s32 CubicInterpolate(
__forceinline static s32 CubicInterpolate(
s32 y0, // 16.0
s32 y1, // 16.0
s32 y2, // 16.0
@ -440,10 +417,8 @@ static __forceinline s32 GetVoiceValues( V_Core& thiscore, uint voiceidx )
{
V_Voice &vc(thiscore.Voices[voiceidx]);
while( vc.SP > 0 )
{
if( InterpType >= 2 )
{
while (vc.SP > 0) {
if (InterpType >= 2) {
vc.PV4 = vc.PV3;
vc.PV3 = vc.PV2;
}
@ -454,14 +429,18 @@ static __forceinline s32 GetVoiceValues( V_Core& thiscore, uint voiceidx )
const s32 mu = vc.SP + 4096;
switch( InterpType )
{
case 0: return vc.PV1<<1;
case 1: return (vc.PV1<<1) - (( (vc.PV2 - vc.PV1) * vc.SP)>>11);
switch (InterpType) {
case 0:
return vc.PV1 << 1;
case 1:
return (vc.PV1 << 1) - (((vc.PV2 - vc.PV1) * vc.SP) >> 11);
case 2: return CubicInterpolate (vc.PV4, vc.PV3, vc.PV2, vc.PV1, mu);
case 3: return HermiteInterpolate<16384> (vc.PV4, vc.PV3, vc.PV2, vc.PV1, mu);
case 4: return CatmullRomInterpolate (vc.PV4, vc.PV3, vc.PV2, vc.PV1, mu);
case 2:
return CubicInterpolate(vc.PV4, vc.PV3, vc.PV2, vc.PV1, mu);
case 3:
return HermiteInterpolate<16384>(vc.PV4, vc.PV3, vc.PV2, vc.PV1, mu);
case 4:
return CatmullRomInterpolate(vc.PV4, vc.PV3, vc.PV2, vc.PV1, mu);
jNO_DEFAULT;
}
@ -501,10 +480,8 @@ static __forceinline s32 GetNoiseValues( V_Core& thiscore, uint voiceidx )
static __forceinline void spu2M_WriteFast(u32 addr, s16 value)
{
// Fixes some of the oldest hangs in pcsx2's history! :p
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && Cores[i].IRQA == addr )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && Cores[i].IRQA == addr) {
//printf("Core %d special write IRQ Called (IRQ passed). IRQA = %x\n",i,addr);
SetIrqCall(i);
}
@ -536,26 +513,33 @@ static __forceinline StereoOut32 MixVoice( uint coreidx, uint voiceidx )
// have to run through all the motions of updating the voice regardless of it's
// audible status. Otherwise IRQs might not trigger and emulation might fail.
if( vc.ADSR.Phase > 0 )
{
if (vc.ADSR.Phase > 0) {
UpdatePitch(coreidx, voiceidx);
s32 Value = 0;
if (vc.Noise)
Value = GetNoiseValues(thiscore, voiceidx);
else
{
else {
// Optimization : Forceinline'd Templated Dispatch Table. Any halfwit compiler will
// turn this into a clever jump dispatch table (no call/rets, no compares, uber-efficient!)
switch( Interpolation )
{
case 0: Value = GetVoiceValues<0>( thiscore, voiceidx ); break;
case 1: Value = GetVoiceValues<1>( thiscore, voiceidx ); break;
case 2: Value = GetVoiceValues<2>( thiscore, voiceidx ); break;
case 3: Value = GetVoiceValues<3>( thiscore, voiceidx ); break;
case 4: Value = GetVoiceValues<4>( thiscore, voiceidx ); break;
switch (Interpolation) {
case 0:
Value = GetVoiceValues<0>(thiscore, voiceidx);
break;
case 1:
Value = GetVoiceValues<1>(thiscore, voiceidx);
break;
case 2:
Value = GetVoiceValues<2>(thiscore, voiceidx);
break;
case 3:
Value = GetVoiceValues<3>(thiscore, voiceidx);
break;
case 4:
Value = GetVoiceValues<4>(thiscore, voiceidx);
break;
jNO_DEFAULT;
}
@ -573,13 +557,11 @@ static __forceinline StereoOut32 MixVoice( uint coreidx, uint voiceidx )
// Store Value for eventual modulation later
// Pseudonym's Crest calculation idea. Actually calculates a crest, unlike the old code which was just peak.
if(vc.PV1 < vc.NextCrest)
{
if (vc.PV1 < vc.NextCrest) {
vc.OutX = MulShr32(vc.NextCrest, vc.ADSR.Value);
vc.NextCrest = -0x8000;
}
if(vc.PV1 > vc.PV2)
{
if (vc.PV1 > vc.PV2) {
vc.NextCrest = vc.PV1;
}
@ -588,19 +570,17 @@ static __forceinline StereoOut32 MixVoice( uint coreidx, uint voiceidx )
// Write-back of raw voice data (post ADSR applied)
if (voiceidx==1) spu2M_WriteFast( ( (0==coreidx) ? 0x400 : 0xc00 ) + OutPos, vc.OutX );
else if (voiceidx==3) spu2M_WriteFast( ( (0==coreidx) ? 0x600 : 0xe00 ) + OutPos, vc.OutX );
if (voiceidx == 1)
spu2M_WriteFast(((0 == coreidx) ? 0x400 : 0xc00) + OutPos, vc.OutX);
else if (voiceidx == 3)
spu2M_WriteFast(((0 == coreidx) ? 0x600 : 0xe00) + OutPos, vc.OutX);
return ApplyVolume(StereoOut32(Value, Value), vc.Volume);
}
else
{
} else {
// Continue processing voice, even if it's "off". Or else we miss interrupts! (Fatal Frame engine died because of this.)
if (NEVER_SKIP_VOICES
|| (*GetMemPtr(vc.NextA & 0xFFFF8) >> 8 & 3) != 3 || vc.LoopStartA != (vc.NextA & ~7) // not in a tight loop
if (NEVER_SKIP_VOICES || (*GetMemPtr(vc.NextA & 0xFFFF8) >> 8 & 3) != 3 || vc.LoopStartA != (vc.NextA & ~7) // not in a tight loop
|| (Cores[0].IRQEnable && (Cores[0].IRQA & ~7) == vc.LoopStartA) // or should be interrupting regularly
|| (Cores[1].IRQEnable && (Cores[1].IRQA & ~7) == vc.LoopStartA)
|| !(thiscore.Regs.ENDX & 1 << voiceidx)) // or isn't currently flagged as having passed the endpoint
|| (Cores[1].IRQEnable && (Cores[1].IRQA & ~7) == vc.LoopStartA) || !(thiscore.Regs.ENDX & 1 << voiceidx)) // or isn't currently flagged as having passed the endpoint
{
UpdatePitch(coreidx, voiceidx);
@ -609,8 +589,10 @@ static __forceinline StereoOut32 MixVoice( uint coreidx, uint voiceidx )
}
// Write-back of raw voice data (some zeros since the voice is "dead")
if (voiceidx==1) spu2M_WriteFast( ( (0==coreidx) ? 0x400 : 0xc00 ) + OutPos, 0 );
else if (voiceidx==3) spu2M_WriteFast( ( (0==coreidx) ? 0x600 : 0xe00 ) + OutPos, 0 );
if (voiceidx == 1)
spu2M_WriteFast(((0 == coreidx) ? 0x400 : 0xc00) + OutPos, 0);
else if (voiceidx == 3)
spu2M_WriteFast(((0 == coreidx) ? 0x600 : 0xe00) + OutPos, 0);
return StereoOut32(0, 0);
}
@ -622,8 +604,7 @@ static __forceinline void MixCoreVoices( VoiceMixSet& dest, const uint coreidx )
{
V_Core &thiscore(Cores[coreidx]);
for( uint voiceidx=0; voiceidx<V_Core::NumVoices; ++voiceidx )
{
for (uint voiceidx = 0; voiceidx < V_Core::NumVoices; ++voiceidx) {
StereoOut32 VVal(MixVoice(coreidx, voiceidx));
// Note: Results from MixVoice are ranged at 16 bits.
@ -657,8 +638,7 @@ StereoOut32 V_Core::Mix( const VoiceMixSet& inVoices, const StereoOut32& Input,
StereoOut32 TD(
Input.Left & DryGate.InpL,
Input.Right & DryGate.InpR
);
Input.Right & DryGate.InpR);
// Mix in the Voice data
TD.Left += Voices.Dry.Left & DryGate.SndL;
@ -670,7 +650,8 @@ StereoOut32 V_Core::Mix( const VoiceMixSet& inVoices, const StereoOut32& Input,
// User-level Effects disabling. Nice speedup but breaks games that depend on
// reverb IRQs (very few -- if you find one name it here!).
if( EffectsDisabled ) return TD;
if (EffectsDisabled)
return TD;
// ----------------------------------------------------------------------------
// Reverberation Effects Processing
@ -694,7 +675,8 @@ StereoOut32 V_Core::Mix( const VoiceMixSet& inVoices, const StereoOut32& Input,
// ToDo:
// Bad EndA causes memory corruption. Bad for us, unknown on PS2!
if (!FxEnable || EffectsEndA >= 0x100000) return TD;
if (!FxEnable || EffectsEndA >= 0x100000)
return TD;
StereoOut32 TW;
@ -753,14 +735,18 @@ StereoOut32 Apply_Frequency_Response_Filter(StereoOut32 &SoundStream)
in = l;
out = FRF.ha0 * in + FRF.ha1 * FRF.History_One_In.Left + FRF.ha2 * FRF.History_Two_In.Left - FRF.hb1 * FRF.History_One_Out.Left - FRF.hb2 * FRF.History_Two_Out.Left;
FRF.History_Two_In.Left = FRF.History_One_In.Left; FRF.History_One_In.Left = in;
FRF.History_Two_Out.Left = FRF.History_One_Out.Left; FRF.History_One_Out.Left = out;
FRF.History_Two_In.Left = FRF.History_One_In.Left;
FRF.History_One_In.Left = in;
FRF.History_Two_Out.Left = FRF.History_One_Out.Left;
FRF.History_One_Out.Left = out;
l = out;
in = r;
out = FRF.ha0 * in + FRF.ha1 * FRF.History_One_In.Right + FRF.ha2 * FRF.History_Two_In.Right - FRF.hb1 * FRF.History_One_Out.Right - FRF.hb2 * FRF.History_Two_Out.Right;
FRF.History_Two_In.Right = FRF.History_One_In.Right; FRF.History_One_In.Right = in;
FRF.History_Two_Out.Right = FRF.History_One_Out.Right; FRF.History_One_Out.Right = out;
FRF.History_Two_In.Right = FRF.History_One_In.Right;
FRF.History_One_In.Right = in;
FRF.History_Two_Out.Right = FRF.History_One_Out.Right;
FRF.History_One_Out.Right = out;
r = out;
//clamp_mix(l);
@ -801,7 +787,8 @@ static int p_cachestat_counter=0;
#ifndef __POSIX__
__forceinline
#endif
void Mix()
void
Mix()
{
// Note: Playmode 4 is SPDIF, which overrides other inputs.
StereoOut32 InputData[2] =
@ -813,8 +800,7 @@ void Mix()
/*(PlayMode&4) ? StereoOut32::Empty : */ ApplyVolume(Cores[0].ReadInput(), Cores[0].InpVol),
// CDDA is on Core 1:
(PlayMode&8) ? StereoOut32::Empty : ApplyVolume( Cores[1].ReadInput(), Cores[1].InpVol )
};
(PlayMode & 8) ? StereoOut32::Empty : ApplyVolume(Cores[1].ReadInput(), Cores[1].InpVol)};
WaveDump::WriteCore(0, CoreSrc_Input, InputData[0]);
WaveDump::WriteCore(1, CoreSrc_Input, InputData[1]);
@ -828,8 +814,7 @@ void Mix()
if ((PlayMode & 4) || (Cores[0].Mute != 0))
Ext = StereoOut32::Empty;
else
{
else {
Ext = clamp_mix(ApplyVolume(Ext, Cores[0].MasterVol));
}
@ -842,16 +827,13 @@ void Mix()
Ext = ApplyVolume(Ext, Cores[1].ExtVol);
StereoOut32 Out(Cores[1].Mix(VoiceData[1], InputData[1], Ext));
if( PlayMode & 8 )
{
if (PlayMode & 8) {
// Experimental CDDA support
// The CDDA overrides all other mixer output. It's a direct feed!
Out = Cores[1].ReadInput_HiFi();
//WaveLog::WriteCore( 1, "CDDA-32", OutL, OutR );
}
else
{
} else {
Out.Left = MulShr32(Out.Left << (SndOutVolumeShift + 1), Cores[1].MasterVol.Left.Value);
Out.Right = MulShr32(Out.Right << (SndOutVolumeShift + 1), Cores[1].MasterVol.Right.Value);
@ -859,8 +841,7 @@ void Mix()
if (postprocess_filter_enabled)
#endif
{
if(postprocess_filter_dealias)
{
if (postprocess_filter_dealias) {
// Dealias filter emphasizes the highs too much.
Out = Apply_Dealias_Filter(Out);
}
@ -886,15 +867,15 @@ void Mix()
// Update AutoDMA output positioning
OutPos++;
if (OutPos>=0x200) OutPos=0;
if (OutPos >= 0x200)
OutPos = 0;
if( IsDevBuild )
{
if (IsDevBuild) {
p_cachestat_counter++;
if(p_cachestat_counter > (48000*10) )
{
if (p_cachestat_counter > (48000 * 10)) {
p_cachestat_counter = 0;
if( MsgCache() ) ConLog( " * SPU2 > CacheStats > Hits: %d Misses: %d Ignores: %d\n",
if (MsgCache())
ConLog(" * SPU2 > CacheStats > Hits: %d Misses: %d Ignores: %d\n",
g_counter_cache_hits,
g_counter_cache_misses,
g_counter_cache_ignores);

View File

@ -29,15 +29,15 @@ struct StereoOut32
s32 Left;
s32 Right;
StereoOut32() :
Left( 0 ),
Right( 0 )
StereoOut32()
: Left(0)
, Right(0)
{
}
StereoOut32( s32 left, s32 right ) :
Left( left ),
Right( right )
StereoOut32(s32 left, s32 right)
: Left(left)
, Right(right)
{
}
@ -50,8 +50,7 @@ struct StereoOut32
{
return StereoOut32(
Left * factor,
Right * factor
);
Right * factor);
}
StereoOut32 &operator*=(const int &factor)
@ -65,8 +64,7 @@ struct StereoOut32
{
return StereoOut32(
Left + right.Left,
Right + right.Right
);
Right + right.Right);
}
StereoOut32 operator/(int src) const
@ -106,30 +104,29 @@ struct FrequencyResponseFilter
float la0, la1, la2, lb1, lb2;
float ha0, ha1, ha2, hb1, hb2;
FrequencyResponseFilter() :
History_One_In( 0, 0 ),
History_One_Out( 0, 0 ),
History_Two_In( 0, 0 ),
History_Two_Out( 0, 0 ),
lx1 ( 0 ),
lx2 ( 0 ),
ly1 ( 0 ),
ly2 ( 0 ),
FrequencyResponseFilter()
: History_One_In(0, 0)
, History_One_Out(0, 0)
, History_Two_In(0, 0)
, History_Two_Out(0, 0)
, lx1(0)
, lx2(0)
, ly1(0)
, ly2(0)
la0 ( 1.00320890889339290000f ),
la1 ( -1.97516434134506300000f ),
la2 ( 0.97243484967313087000f ),
lb1 ( -1.97525280404731810000f ),
lb2 ( 0.97555529586426892000f ),
, la0(1.00320890889339290000f)
, la1(-1.97516434134506300000f)
, la2(0.97243484967313087000f)
, lb1(-1.97525280404731810000f)
, lb2(0.97555529586426892000f)
ha0 ( 1.52690772687271160000f ),
ha1 ( -1.62653918974914990000f ), //-1.72 = "common equilizer curve" --____--
ha2 ( 0.57997976029249387000f ),
hb1 ( -0.80955590379048203000f ),
hb2 ( 0.28990420120653748000f )
, ha0(1.52690772687271160000f)
, ha1(-1.62653918974914990000f) //-1.72 = "common equilizer curve" --____--
, ha2(0.57997976029249387000f)
, hb1(-0.80955590379048203000f)
, hb2(0.28990420120653748000f)
{
}
};
extern void Mix();

View File

@ -45,12 +45,9 @@ u32 lClocks = 0;
HINSTANCE hInstance;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
if( dwReason == DLL_PROCESS_ATTACH )
{
if (dwReason == DLL_PROCESS_ATTACH) {
hInstance = hinstDLL;
}
else if( dwReason == DLL_PROCESS_DETACH )
{
} else if (dwReason == DLL_PROCESS_DETACH) {
// TODO : perform shutdown procedure, just in case PCSX2 itself failed
// to for some reason..
}
@ -101,11 +98,10 @@ static void InitLibraryName()
#else
""
#endif
,SVN_REV, SVN_MODS ? "m" : ""
);
,
SVN_REV, SVN_MODS ? "m" : "");
#endif
#endif
}
//static bool cpu_detected = false;
@ -129,44 +125,49 @@ static bool CheckSSE()
#endif
}
EXPORT_C_(u32) PS2EgetLibType()
EXPORT_C_(u32)
PS2EgetLibType()
{
return PS2E_LT_SPU2;
}
EXPORT_C_(char*) PS2EgetLibName()
EXPORT_C_(char *)
PS2EgetLibName()
{
InitLibraryName();
return libraryName;
}
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type)
{
return (PS2E_SPU2_VERSION << 16) | (VersionInfo::Release << 8) | VersionInfo::Revision;
}
EXPORT_C_(void) SPU2configure()
EXPORT_C_(void)
SPU2configure()
{
if( !CheckSSE() ) return;
if (!CheckSSE())
return;
configure();
}
EXPORT_C_(void) SPU2about()
EXPORT_C_(void)
SPU2about()
{
AboutBox();
}
EXPORT_C_(s32) SPU2test()
EXPORT_C_(s32)
SPU2test()
{
if( !CheckSSE() ) return -1;
if (!CheckSSE())
return -1;
#ifdef _WIN32
if (IsWindows8OrGreater())
{
for (int n = 0; mods[n] != nullptr; ++n)
{
if (mods[n] == XAudio2_27_Out)
{
if (IsWindows8OrGreater()) {
for (int n = 0; mods[n] != nullptr; ++n) {
if (mods[n] == XAudio2_27_Out) {
mods[n] = XAudio2Out;
break;
}
@ -175,8 +176,7 @@ EXPORT_C_(s32) SPU2test()
#endif
ReadSettings();
if( SndBuffer::Test() != 0 )
{
if (SndBuffer::Test() != 0) {
// TODO : Implement a proper dialog that allows the user to test different audio out drivers.
const wchar_t *wtf = mods[OutputModule]->GetIdent();
SysMessage(L"The '%s' driver test failed. Please configure\na different SoundOut module and try again.", wtf);
@ -195,31 +195,37 @@ void (* _irqcallback)();
void (*dma4callback)();
void (*dma7callback)();
EXPORT_C_(u32) CALLBACK SPU2ReadMemAddr(int core)
EXPORT_C_(u32)
CALLBACK SPU2ReadMemAddr(int core)
{
return Cores[core].MADR;
}
EXPORT_C_(void) CALLBACK SPU2WriteMemAddr(int core,u32 value)
EXPORT_C_(void)
CALLBACK SPU2WriteMemAddr(int core, u32 value)
{
Cores[core].MADR = value;
}
EXPORT_C_(void) CALLBACK SPU2setDMABaseAddr(uptr baseaddr)
EXPORT_C_(void)
CALLBACK SPU2setDMABaseAddr(uptr baseaddr)
{
DMABaseAddr = (u16 *)baseaddr;
}
EXPORT_C_(void) CALLBACK SPU2setSettingsDir(const char* dir)
EXPORT_C_(void)
CALLBACK SPU2setSettingsDir(const char *dir)
{
CfgSetSettingsDir(dir);
}
EXPORT_C_(void) CALLBACK SPU2setLogDir(const char* dir)
EXPORT_C_(void)
CALLBACK SPU2setLogDir(const char *dir)
{
CfgSetLogDir(dir);
}
EXPORT_C_(s32) SPU2dmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed)
EXPORT_C_(s32)
SPU2dmaRead(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed)
{
if (channel == 4)
return Cores[0].NewDmaRead(data, bytesLeft, bytesProcessed);
@ -227,7 +233,8 @@ EXPORT_C_(s32) SPU2dmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesPro
return Cores[1].NewDmaRead(data, bytesLeft, bytesProcessed);
}
EXPORT_C_(s32) SPU2dmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed)
EXPORT_C_(s32)
SPU2dmaWrite(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed)
{
if (channel == 4)
return Cores[0].NewDmaWrite(data, bytesLeft, bytesProcessed);
@ -235,7 +242,8 @@ EXPORT_C_(s32) SPU2dmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesPr
return Cores[1].NewDmaWrite(data, bytesLeft, bytesProcessed);
}
EXPORT_C_(void) SPU2dmaInterrupt(s32 channel)
EXPORT_C_(void)
SPU2dmaInterrupt(s32 channel)
{
if (channel == 4)
return Cores[0].NewDmaInterrupt();
@ -244,12 +252,14 @@ EXPORT_C_(void) SPU2dmaInterrupt(s32 channel)
}
#ifdef ENABLE_NEW_IOPDMA_SPU2
EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)())
EXPORT_C_(void)
SPU2irqCallback(void (*SPU2callback)())
{
_irqcallback = SPU2callback;
}
#else
EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)())
EXPORT_C_(void)
SPU2irqCallback(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)())
{
_irqcallback = SPU2callback;
dma4callback = DMA4callback;
@ -257,17 +267,21 @@ EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),vo
}
#endif
EXPORT_C_(void) CALLBACK SPU2readDMA4Mem(u16 *pMem, u32 size) // size now in 16bit units
EXPORT_C_(void)
CALLBACK SPU2readDMA4Mem(u16 *pMem, u32 size) // size now in 16bit units
{
if( cyclePtr != NULL ) TimeUpdate( *cyclePtr );
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
FileLog("[%10d] SPU2 readDMA4Mem size %x\n", Cycles, size << 1);
Cores[0].DoDMAread(pMem, size);
}
EXPORT_C_(void) CALLBACK SPU2writeDMA4Mem(u16* pMem, u32 size) // size now in 16bit units
EXPORT_C_(void)
CALLBACK SPU2writeDMA4Mem(u16 *pMem, u32 size) // size now in 16bit units
{
if( cyclePtr != NULL ) TimeUpdate( *cyclePtr );
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
FileLog("[%10d] SPU2 writeDMA4Mem size %x at address %x\n", Cycles, size << 1, Cores[0].TSA);
#ifdef S2R_ENABLE
@ -277,31 +291,37 @@ EXPORT_C_(void) CALLBACK SPU2writeDMA4Mem(u16* pMem, u32 size) // size now in 16
Cores[0].DoDMAwrite(pMem, size);
}
EXPORT_C_(void) CALLBACK SPU2interruptDMA4()
EXPORT_C_(void)
CALLBACK SPU2interruptDMA4()
{
FileLog("[%10d] SPU2 interruptDMA4\n", Cycles);
Cores[0].Regs.STATX |= 0x80;
//Cores[0].Regs.ATTR &= ~0x30;
}
EXPORT_C_(void) CALLBACK SPU2interruptDMA7()
EXPORT_C_(void)
CALLBACK SPU2interruptDMA7()
{
FileLog("[%10d] SPU2 interruptDMA7\n", Cycles);
Cores[1].Regs.STATX |= 0x80;
//Cores[1].Regs.ATTR &= ~0x30;
}
EXPORT_C_(void) CALLBACK SPU2readDMA7Mem(u16* pMem, u32 size)
EXPORT_C_(void)
CALLBACK SPU2readDMA7Mem(u16 *pMem, u32 size)
{
if( cyclePtr != NULL ) TimeUpdate( *cyclePtr );
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
FileLog("[%10d] SPU2 readDMA7Mem size %x\n", Cycles, size << 1);
Cores[1].DoDMAread(pMem, size);
}
EXPORT_C_(void) CALLBACK SPU2writeDMA7Mem(u16* pMem, u32 size)
EXPORT_C_(void)
CALLBACK SPU2writeDMA7Mem(u16 *pMem, u32 size)
{
if( cyclePtr != NULL ) TimeUpdate( *cyclePtr );
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
FileLog("[%10d] SPU2 writeDMA7Mem size %x at address %x\n", Cycles, size << 1, Cores[1].TSA);
#ifdef S2R_ENABLE
@ -311,7 +331,8 @@ EXPORT_C_(void) CALLBACK SPU2writeDMA7Mem(u16* pMem, u32 size)
Cores[1].DoDMAwrite(pMem, size);
}
EXPORT_C_(void) SPU2reset()
EXPORT_C_(void)
SPU2reset()
{
memset(spu2regs, 0, 0x010000);
memset(_spu2mem, 0, 0x200000);
@ -320,12 +341,12 @@ EXPORT_C_(void) SPU2reset()
Cores[1].Init(1);
}
EXPORT_C_(s32) SPU2init()
EXPORT_C_(s32)
SPU2init()
{
assert(regtable[0x400] == NULL);
if (IsInitialized)
{
if (IsInitialized) {
printf(" * SPU2-X: Already initialized - Ignoring SPU2init signal.");
return 0;
}
@ -335,8 +356,7 @@ EXPORT_C_(s32) SPU2init()
ReadSettings();
#ifdef SPU2_LOG
if(AccessLog())
{
if (AccessLog()) {
spu2Log = OpenLog(AccessLogFileName);
setvbuf(spu2Log, NULL, _IONBF, 0);
FileLog("SPU2init\n");
@ -356,17 +376,16 @@ EXPORT_C_(s32) SPU2init()
pcm_cache_data = (PcmCacheEntry *)calloc(pcm_BlockCount, sizeof(PcmCacheEntry));
if( (spu2regs == NULL) || (_spu2mem == NULL) || (pcm_cache_data == NULL) )
{
SysMessage("SPU2-X: Error allocating Memory\n"); return -1;
if ((spu2regs == NULL) || (_spu2mem == NULL) || (pcm_cache_data == NULL)) {
SysMessage("SPU2-X: Error allocating Memory\n");
return -1;
}
// Patch up a copy of regtable that directly maps "NULLs" to SPU2 memory.
memcpy(regtable, regtable_original, sizeof(regtable));
for(uint mem=0;mem<0x800;mem++)
{
for (uint mem = 0; mem < 0x800; mem++) {
u16 *ptr = regtable[mem >> 1];
if (!ptr) {
regtable[mem >> 1] = &(spu2Ru16(mem));
@ -394,21 +413,17 @@ static INT_PTR CALLBACK DebugProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lPara
{
int wmId;
switch(uMsg)
{
switch (uMsg) {
case WM_PAINT:
return FALSE;
case WM_INITDIALOG:
{
case WM_INITDIALOG: {
debugDialogOpen = true;
}
break;
} break;
case WM_COMMAND:
wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
switch (wmId) {
case IDOK:
case IDCANCEL:
debugDialogOpen = false;
@ -427,9 +442,11 @@ static INT_PTR CALLBACK DebugProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lPara
#endif
uptr gsWindowHandle = 0;
EXPORT_C_(s32) SPU2open(void *pDsp)
EXPORT_C_(s32)
SPU2open(void *pDsp)
{
if( IsOpened ) return 0;
if (IsOpened)
return 0;
FileLog("[%10d] SPU2 Open\n", Cycles);
@ -440,17 +457,13 @@ EXPORT_C_(s32) SPU2open(void *pDsp)
#ifdef _MSC_VER
#ifdef PCSX2_DEVBUILD // Define may not be needed but not tested yet. Better make sure.
if( IsDevBuild && VisualDebug() )
{
if(debugDialogOpen==0)
{
if (IsDevBuild && VisualDebug()) {
if (debugDialogOpen == 0) {
hDebugDialog = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_DEBUG), 0, DebugProc, 0);
ShowWindow(hDebugDialog, SW_SHOWNORMAL);
debugDialogOpen = 1;
}
}
else if(debugDialogOpen)
{
} else if (debugDialogOpen) {
DestroyWindow(hDebugDialog);
debugDialogOpen = 0;
}
@ -460,17 +473,14 @@ EXPORT_C_(s32) SPU2open(void *pDsp)
IsOpened = true;
lClocks = (cyclePtr != NULL) ? *cyclePtr : 0;
try
{
try {
SndBuffer::Init();
#ifndef __POSIX__
DspLoadLibrary(dspPlugin, dspPluginModule);
#endif
WaveDump::Open();
}
catch( std::exception& ex )
{
} catch (std::exception &ex) {
fprintf(stderr, "SPU2-X Error: Could not initialize device, or something.\nReason: %s", ex.what());
SPU2close();
return -1;
@ -478,9 +488,11 @@ EXPORT_C_(s32) SPU2open(void *pDsp)
return 0;
}
EXPORT_C_(void) SPU2close()
EXPORT_C_(void)
SPU2close()
{
if( !IsOpened ) return;
if (!IsOpened)
return;
IsOpened = false;
FileLog("[%10d] SPU2 Close\n", Cycles);
@ -492,9 +504,11 @@ EXPORT_C_(void) SPU2close()
SndBuffer::Cleanup();
}
EXPORT_C_(void) SPU2shutdown()
EXPORT_C_(void)
SPU2shutdown()
{
if(!IsInitialized) return;
if (!IsInitialized)
return;
IsInitialized = false;
ConLog("* SPU2-X: Shutting down.\n");
@ -525,13 +539,16 @@ EXPORT_C_(void) SPU2shutdown()
#ifdef SPU2_LOG
if(!AccessLog()) return;
if (!AccessLog())
return;
FileLog("[%10d] SPU2shutdown\n", Cycles);
if(spu2Log) fclose(spu2Log);
if (spu2Log)
fclose(spu2Log);
#endif
}
EXPORT_C_(void) SPU2setClockPtr(u32 *ptr)
EXPORT_C_(void)
SPU2setClockPtr(u32 *ptr)
{
cyclePtr = ptr;
}
@ -541,35 +558,30 @@ static u32 lastTicks;
static bool lState[6];
#endif
EXPORT_C_(void) SPU2async(u32 cycles)
EXPORT_C_(void)
SPU2async(u32 cycles)
{
DspUpdate();
if(cyclePtr != NULL)
{
if (cyclePtr != NULL) {
TimeUpdate(*cyclePtr);
}
else
{
} else {
pClocks += cycles;
TimeUpdate(pClocks);
}
#ifdef DEBUG_KEYS
u32 curTicks = GetTickCount();
if((curTicks - lastTicks) >= 50)
{
if ((curTicks - lastTicks) >= 50) {
int oldI = Interpolation;
bool cState[6];
for(int i=0;i<6;i++)
{
for (int i = 0; i < 6; i++) {
cState[i] = !!(GetAsyncKeyState(VK_NUMPAD0 + i) & 0x8000);
if ((cState[i] && !lState[i]) && i != 5)
Interpolation = i;
if((cState[i] && !lState[i]) && i == 5)
{
if ((cState[i] && !lState[i]) && i == 5) {
postprocess_filter_enabled = !postprocess_filter_enabled;
printf("Post process filters %s \n", postprocess_filter_enabled ? "enabled" : "disabled");
}
@ -577,17 +589,27 @@ EXPORT_C_(void) SPU2async(u32 cycles)
lState[i] = cState[i];
}
if(Interpolation != oldI)
{
if (Interpolation != oldI) {
printf("Interpolation set to %d", Interpolation);
switch(Interpolation)
{
case 0: printf(" - Nearest.\n"); break;
case 1: printf(" - Linear.\n"); break;
case 2: printf(" - Cubic.\n"); break;
case 3: printf(" - Hermite.\n"); break;
case 4: printf(" - Catmull-Rom.\n"); break;
default: printf(" (unknown).\n"); break;
switch (Interpolation) {
case 0:
printf(" - Nearest.\n");
break;
case 1:
printf(" - Linear.\n");
break;
case 2:
printf(" - Cubic.\n");
break;
case 3:
printf(" - Hermite.\n");
break;
case 4:
printf(" - Catmull-Rom.\n");
break;
default:
printf(" (unknown).\n");
break;
}
}
@ -596,34 +618,31 @@ EXPORT_C_(void) SPU2async(u32 cycles)
#endif
}
EXPORT_C_(u16) SPU2read(u32 rmem)
EXPORT_C_(u16)
SPU2read(u32 rmem)
{
// if(!replay_mode)
// s2r_readreg(Cycles,rmem);
u16 ret=0xDEAD; u32 core=0, mem=rmem&0xFFFF, omem=mem;
if (mem & 0x400) { omem^=0x400; core=1; }
if(omem == 0x1f9001AC)
{
ret = Cores[core].DmaRead();
u16 ret = 0xDEAD;
u32 core = 0, mem = rmem & 0xFFFF, omem = mem;
if (mem & 0x400) {
omem ^= 0x400;
core = 1;
}
else
{
if (omem == 0x1f9001AC) {
ret = Cores[core].DmaRead();
} else {
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
if (rmem>>16 == 0x1f80)
{
if (rmem >> 16 == 0x1f80) {
ret = Cores[0].ReadRegPS1(rmem);
}
else if (mem >= 0x800)
{
} else if (mem >= 0x800) {
ret = spu2Ru16(mem);
ConLog("* SPU2-X: Read from reg>=0x800: %x value %x\n", mem, ret);
}
else
{
} else {
ret = *(regtable[(mem >> 1)]);
//FileLog("[%10d] SPU2 read mem %x (core %d, register %x): %x\n",Cycles, mem, core, (omem & 0x7ff), ret);
SPU2writeLog("read", rmem, ret);
@ -633,7 +652,8 @@ EXPORT_C_(u16) SPU2read(u32 rmem)
return ret;
}
EXPORT_C_(void) SPU2write(u32 rmem, u16 value)
EXPORT_C_(void)
SPU2write(u32 rmem, u16 value)
{
#ifdef S2R_ENABLE
if (!replay_mode)
@ -649,8 +669,7 @@ EXPORT_C_(void) SPU2write(u32 rmem, u16 value)
if (rmem >> 16 == 0x1f80)
Cores[0].WriteRegPS1(rmem, value);
else
{
else {
SPU2writeLog("write", rmem, value);
SPU2_FastWrite(rmem, value);
}
@ -659,7 +678,8 @@ EXPORT_C_(void) SPU2write(u32 rmem, u16 value)
// if start is 1, starts recording spu2 data, else stops
// returns a non zero value if successful
// for now, pData is not used
EXPORT_C_(int) SPU2setupRecording(int start, void* pData)
EXPORT_C_(int)
SPU2setupRecording(int start, void *pData)
{
if (start == 0)
RecordStop();
@ -669,35 +689,34 @@ EXPORT_C_(int) SPU2setupRecording(int start, void* pData)
return 0;
}
EXPORT_C_(s32) SPU2freeze(int mode, freezeData *data)
EXPORT_C_(s32)
SPU2freeze(int mode, freezeData *data)
{
pxAssume(data != NULL);
if ( !data )
{
if (!data) {
printf("SPU2-X savestate null pointer!\n");
return -1;
}
if( mode == FREEZE_SIZE )
{
if (mode == FREEZE_SIZE) {
data->size = Savestate::SizeIt();
return 0;
}
pxAssume(mode == FREEZE_LOAD || mode == FREEZE_SAVE);
if( data->data == NULL )
{
if (data->data == NULL) {
printf("SPU2-X savestate null pointer!\n");
return -1;
}
Savestate::DataBlock &spud = (Savestate::DataBlock &)*(data->data);
switch( mode )
{
case FREEZE_LOAD: return Savestate::ThawIt( spud );
case FREEZE_SAVE: return Savestate::FreezeIt( spud );
switch (mode) {
case FREEZE_LOAD:
return Savestate::ThawIt(spud);
case FREEZE_SAVE:
return Savestate::FreezeIt(spud);
jNO_DEFAULT;
}

View File

@ -33,37 +33,57 @@
// We have our own versions that have the DLLExport attribute configured:
EXPORT_C_(s32) SPU2init();
EXPORT_C_(void) SPU2reset();
EXPORT_C_(s32) SPU2open(void *pDsp);
EXPORT_C_(void) SPU2close();
EXPORT_C_(void) SPU2shutdown();
EXPORT_C_(void) SPU2write(u32 mem, u16 value);
EXPORT_C_(u16) SPU2read(u32 mem);
EXPORT_C_(s32)
SPU2init();
EXPORT_C_(void)
SPU2reset();
EXPORT_C_(s32)
SPU2open(void *pDsp);
EXPORT_C_(void)
SPU2close();
EXPORT_C_(void)
SPU2shutdown();
EXPORT_C_(void)
SPU2write(u32 mem, u16 value);
EXPORT_C_(u16)
SPU2read(u32 mem);
#ifdef ENABLE_NEW_IOPDMA_SPU2
EXPORT_C_(s32) SPU2dmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed);
EXPORT_C_(s32) SPU2dmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed);
EXPORT_C_(void) SPU2dmaInterrupt(s32 channel);
EXPORT_C_(s32)
SPU2dmaRead(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed);
EXPORT_C_(s32)
SPU2dmaWrite(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed);
EXPORT_C_(void)
SPU2dmaInterrupt(s32 channel);
// dma irq callbacks not needed anymore, they are handled by the dmac
EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)());
EXPORT_C_(void)
SPU2irqCallback(void (*SPU2callback)());
#else
// These defines are useless and gcc-4.6 complain about redefinition
// so we remove them on linux
#ifndef __POSIX__
EXPORT_C_(void) SPU2readDMA4Mem(u16 *pMem, u32 size);
EXPORT_C_(void) SPU2writeDMA4Mem(u16 *pMem, u32 size);
EXPORT_C_(void) SPU2interruptDMA4();
EXPORT_C_(void) SPU2readDMA7Mem(u16* pMem, u32 size);
EXPORT_C_(void) SPU2writeDMA7Mem(u16 *pMem, u32 size);
EXPORT_C_(void) SPU2interruptDMA7();
EXPORT_C_(void)
SPU2readDMA4Mem(u16 *pMem, u32 size);
EXPORT_C_(void)
SPU2writeDMA4Mem(u16 *pMem, u32 size);
EXPORT_C_(void)
SPU2interruptDMA4();
EXPORT_C_(void)
SPU2readDMA7Mem(u16 *pMem, u32 size);
EXPORT_C_(void)
SPU2writeDMA7Mem(u16 *pMem, u32 size);
EXPORT_C_(void)
SPU2interruptDMA7();
// all addresses passed by dma will be pointers to the array starting at baseaddr
// This function is necessary to successfully save and reload the spu2 state
EXPORT_C_(u32) SPU2ReadMemAddr(int core);
EXPORT_C_(void) SPU2WriteMemAddr(int core,u32 value);
EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)());
EXPORT_C_(u32)
SPU2ReadMemAddr(int core);
EXPORT_C_(void)
SPU2WriteMemAddr(int core, u32 value);
EXPORT_C_(void)
SPU2irqCallback(void (*SPU2callback)(), void (*DMA4callback)(), void (*DMA7callback)());
#endif
#endif
@ -71,15 +91,22 @@ EXPORT_C_(void) SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),vo
// if start is 1, starts recording spu2 data, else stops
// returns a non zero value if successful
// for now, pData is not used
EXPORT_C_(int) SPU2setupRecording(int start, void* pData);
EXPORT_C_(int)
SPU2setupRecording(int start, void *pData);
EXPORT_C_(void) SPU2setClockPtr(u32* ptr);
EXPORT_C_(void)
SPU2setClockPtr(u32 *ptr);
EXPORT_C_(void) SPU2async(u32 cycles);
EXPORT_C_(s32) SPU2freeze(int mode, freezeData *data);
EXPORT_C_(void) SPU2configure();
EXPORT_C_(void) SPU2about();
EXPORT_C_(s32) SPU2test();
EXPORT_C_(void)
SPU2async(u32 cycles);
EXPORT_C_(s32)
SPU2freeze(int mode, freezeData *data);
EXPORT_C_(void)
SPU2configure();
EXPORT_C_(void)
SPU2about();
EXPORT_C_(s32)
SPU2test();
#include "Spu2replay.h"

View File

@ -31,7 +31,8 @@
//
StereoOut32 V_Core::ReadInput_HiFi()
{
if (psxmode)ConLog("ReadInput_HiFi!!!!!\n");
if (psxmode)
ConLog("ReadInput_HiFi!!!!!\n");
InputPosRead &= ~1;
//
//#ifdef PCM24_S1_INTERLEAVE
@ -48,11 +49,9 @@ StereoOut32 V_Core::ReadInput_HiFi()
StereoOut32 retval(
(s32 &)(*GetMemPtr(0x2000 + (Index << 10) + InputPosRead)),
(s32&)(*GetMemPtr(0x2200 + (Index<<10) + InputPosRead))
);
(s32 &)(*GetMemPtr(0x2200 + (Index << 10) + InputPosRead)));
if( Index == 1 )
{
if (Index == 1) {
// CDDA Mode:
// give 30 bit data (SndOut downsamples the rest of the way)
// HACKFIX: 28 bits seems better according to rama. I should take some time and do some
@ -66,15 +65,13 @@ StereoOut32 V_Core::ReadInput_HiFi()
// Why does CDDA mode check for InputPos == 0x100? In the old code, SPDIF mode did not but CDDA did.
// One of these seems wrong, they should be the same. Since standard ADMA checks too I'm assuming that as default. -- air
if( (InputPosRead==0x100) || (InputPosRead>=0x200) )
{
if ((InputPosRead == 0x100) || (InputPosRead >= 0x200)) {
#ifdef ENABLE_NEW_IOPDMA_SPU2
// WARNING: Assumes this to be in the same thread as the dmas
AutoDmaFree += 0x200;
#else
AdmaInProgress = 0;
if(InputDataLeft >= 0x200)
{
if (InputDataLeft >= 0x200) {
#ifdef PCM24_S1_INTERLEAVE
AutoDMAReadBuffer(1);
#else
@ -84,22 +81,25 @@ StereoOut32 V_Core::ReadInput_HiFi()
TSA = (Index << 10) + InputPosRead;
if (InputDataLeft < 0x200)
{
if (InputDataLeft < 0x200) {
FileLog("[%10d] %s AutoDMA%c block end.\n", (Index == 1) ? "CDDA" : "SPDIF", Cycles, GetDmaIndexChar());
if( IsDevBuild )
{
if(InputDataLeft > 0)
{
if(MsgAutoDMA()) ConLog("WARNING: adma buffer didn't finish with a whole block!!\n");
if (IsDevBuild) {
if (InputDataLeft > 0) {
if (MsgAutoDMA())
ConLog("WARNING: adma buffer didn't finish with a whole block!!\n");
}
}
InputDataLeft = 0;
// Hack, kinda. We call the interrupt early here, since PCSX2 doesn't like them delayed.
//DMAICounter = 1;
if(Index == 0) { if(dma4callback) dma4callback(); }
else { if(dma7callback) dma7callback(); }
if (Index == 0) {
if (dma4callback)
dma4callback();
} else {
if (dma7callback)
dma7callback();
}
}
}
#endif
@ -112,8 +112,7 @@ StereoOut32 V_Core::ReadInput()
{
StereoOut32 retval;
if( (Index!=1) || ((PlayMode&2)==0) )
{
if ((Index != 1) || ((PlayMode & 2) == 0)) {
for (int i = 0; i < 2; i++)
if (Cores[i].IRQEnable && 0x2000 + (Index << 10) + InputPosRead == (Cores[i].IRQA & 0xfffffdff))
SetIrqCall(i);
@ -124,8 +123,7 @@ StereoOut32 V_Core::ReadInput()
//);
retval = StereoOut32(
(s32)(*GetMemPtr(0x2000 + (Index << 10) + InputPosRead)),
(s32)(*GetMemPtr(0x2200 + (Index<<10) + InputPosRead))
);
(s32)(*GetMemPtr(0x2200 + (Index << 10) + InputPosRead)));
}
#ifdef PCSX2_DEVBUILD
@ -135,15 +133,13 @@ StereoOut32 V_Core::ReadInput()
InputPosRead++;
if (AutoDMACtrl & (Index + 1) && (InputPosRead == 0x100 || InputPosRead == 0x200))
{
if (AutoDMACtrl & (Index + 1) && (InputPosRead == 0x100 || InputPosRead == 0x200)) {
#ifdef ENABLE_NEW_IOPDMA_SPU2
// WARNING: Assumes this to be in the same thread as the dmas
AutoDmaFree += 0x200;
#else
AdmaInProgress = 0;
if(InputDataLeft >= 0x200)
{
if (InputDataLeft >= 0x200) {
//u8 k=InputDataLeft>=InputDataProgress;
AutoDMAReadBuffer(0);
@ -151,24 +147,27 @@ StereoOut32 V_Core::ReadInput()
AdmaInProgress = 1;
TSA = (Index << 10) + InputPosRead;
if (InputDataLeft < 0x200)
{
if (InputDataLeft < 0x200) {
AutoDMACtrl |= ~3;
if( IsDevBuild )
{
if (IsDevBuild) {
FileLog("[%10d] AutoDMA%c block end.\n", Cycles, GetDmaIndexChar());
if(InputDataLeft>0)
{
if(MsgAutoDMA()) ConLog("WARNING: adma buffer didn't finish with a whole block!!\n");
if (InputDataLeft > 0) {
if (MsgAutoDMA())
ConLog("WARNING: adma buffer didn't finish with a whole block!!\n");
}
}
InputDataLeft = 0;
// Hack, kinda. We call the interrupt early here, since PCSX2 doesn't like them delayed.
//DMAICounter = 1;
if(Index == 0) { if(dma4callback) dma4callback(); }
else { if(dma7callback) dma7callback(); }
if (Index == 0) {
if (dma4callback)
dma4callback();
} else {
if (dma7callback)
dma7callback();
}
}
}
#endif

View File

@ -31,12 +31,16 @@ __forceinline void _RegLog_( const char* action, int level, const char *RName, u
void SPU2writeLog(const char *action, u32 rmem, u16 value)
{
if( !IsDevBuild ) return;
if (!IsDevBuild)
return;
//u32 vx=0, vc=0;
u32 core = 0, omem, mem;
omem = mem = rmem & 0x7FF; //FFFF;
if (mem & 0x400) { omem^=0x400; core=1; }
if (mem & 0x400) {
omem ^= 0x400;
core = 1;
}
if (omem < 0x0180) // Voice Params (VP)
{
@ -45,8 +49,7 @@ void SPU2writeLog( const char* action, u32 rmem, u16 value )
char dest[192];
sprintf(dest, "Voice %d %s", voice, ParamNames[param]);
RegLog(2, dest, rmem, core, value);
}
else if ((omem >= 0x01C0) && (omem < 0x02E0)) // Voice Addressing Params (VA)
} else if ((omem >= 0x01C0) && (omem < 0x02E0)) // Voice Addressing Params (VA)
{
const u32 voice = ((omem - 0x01C0) / 12);
const u32 address = ((omem - 0x01C0) % 12) >> 1;
@ -54,38 +57,75 @@ void SPU2writeLog( const char* action, u32 rmem, u16 value )
char dest[192];
sprintf(dest, "Voice %d %s", voice, AddressNames[address]);
RegLog(2, dest, rmem, core, value);
} else if ((mem >= 0x0760) && (mem < 0x07b0)) {
omem = mem;
core = 0;
if (mem >= 0x0788) {
omem -= 0x28;
core = 1;
}
else if ((mem >= 0x0760) && (mem < 0x07b0))
{
omem=mem; core=0;
if (mem >= 0x0788) {omem-=0x28; core=1;}
switch(omem)
{
case REG_P_EVOLL: RegLog(2,"EVOLL",rmem,core,value); break;
case REG_P_EVOLR: RegLog(2,"EVOLR",rmem,core,value); break;
case REG_P_AVOLL: if (core) { RegLog(2,"AVOLL",rmem,core,value); } break;
case REG_P_AVOLR: if (core) { RegLog(2,"AVOLR",rmem,core,value); } break;
case REG_P_BVOLL: RegLog(2,"BVOLL",rmem,core,value); break;
case REG_P_BVOLR: RegLog(2,"BVOLR",rmem,core,value); break;
case REG_P_MVOLXL: RegLog(2,"MVOLXL",rmem,core,value); break;
case REG_P_MVOLXR: RegLog(2,"MVOLXR",rmem,core,value); break;
case R_IIR_ALPHA: RegLog(2,"IIR_ALPHA",rmem,core,value); break;
case R_ACC_COEF_A: RegLog(2,"ACC_COEF_A",rmem,core,value); break;
case R_ACC_COEF_B: RegLog(2,"ACC_COEF_B",rmem,core,value); break;
case R_ACC_COEF_C: RegLog(2,"ACC_COEF_C",rmem,core,value); break;
case R_ACC_COEF_D: RegLog(2,"ACC_COEF_D",rmem,core,value); break;
case R_IIR_COEF: RegLog(2,"IIR_COEF",rmem,core,value); break;
case R_FB_ALPHA: RegLog(2,"FB_ALPHA",rmem,core,value); break;
case R_FB_X: RegLog(2,"FB_X",rmem,core,value); break;
case R_IN_COEF_L: RegLog(2,"IN_COEF_L",rmem,core,value); break;
case R_IN_COEF_R: RegLog(2,"IN_COEF_R",rmem,core,value); break;
switch (omem) {
case REG_P_EVOLL:
RegLog(2, "EVOLL", rmem, core, value);
break;
case REG_P_EVOLR:
RegLog(2, "EVOLR", rmem, core, value);
break;
case REG_P_AVOLL:
if (core) {
RegLog(2, "AVOLL", rmem, core, value);
}
break;
case REG_P_AVOLR:
if (core) {
RegLog(2, "AVOLR", rmem, core, value);
}
else if ((mem>=0x07C0) && (mem<0x07CE))
{
switch(mem)
{
break;
case REG_P_BVOLL:
RegLog(2, "BVOLL", rmem, core, value);
break;
case REG_P_BVOLR:
RegLog(2, "BVOLR", rmem, core, value);
break;
case REG_P_MVOLXL:
RegLog(2, "MVOLXL", rmem, core, value);
break;
case REG_P_MVOLXR:
RegLog(2, "MVOLXR", rmem, core, value);
break;
case R_IIR_ALPHA:
RegLog(2, "IIR_ALPHA", rmem, core, value);
break;
case R_ACC_COEF_A:
RegLog(2, "ACC_COEF_A", rmem, core, value);
break;
case R_ACC_COEF_B:
RegLog(2, "ACC_COEF_B", rmem, core, value);
break;
case R_ACC_COEF_C:
RegLog(2, "ACC_COEF_C", rmem, core, value);
break;
case R_ACC_COEF_D:
RegLog(2, "ACC_COEF_D", rmem, core, value);
break;
case R_IIR_COEF:
RegLog(2, "IIR_COEF", rmem, core, value);
break;
case R_FB_ALPHA:
RegLog(2, "FB_ALPHA", rmem, core, value);
break;
case R_FB_X:
RegLog(2, "FB_X", rmem, core, value);
break;
case R_IN_COEF_L:
RegLog(2, "IN_COEF_L", rmem, core, value);
break;
case R_IN_COEF_R:
RegLog(2, "IN_COEF_R", rmem, core, value);
break;
}
} else if ((mem >= 0x07C0) && (mem < 0x07CE)) {
switch (mem) {
case SPDIF_OUT:
RegLog(2, "SPDIF_OUT", rmem, -1, value);
break;
@ -93,32 +133,34 @@ void SPU2writeLog( const char* action, u32 rmem, u16 value )
RegLog(2, "SPDIF_IRQINFO", rmem, -1, value);
break;
case 0x7c4:
if(Spdif.Unknown1 != value) ConLog("* SPU2-X: SPDIF Unknown Register 1 set to %04x\n",value);
if (Spdif.Unknown1 != value)
ConLog("* SPU2-X: SPDIF Unknown Register 1 set to %04x\n", value);
RegLog(2, "SPDIF_UNKNOWN1", rmem, -1, value);
break;
case SPDIF_MODE:
if(Spdif.Mode != value) ConLog("* SPU2-X: SPDIF Mode set to %04x\n",value);
if (Spdif.Mode != value)
ConLog("* SPU2-X: SPDIF Mode set to %04x\n", value);
RegLog(2, "SPDIF_MODE", rmem, -1, value);
break;
case SPDIF_MEDIA:
if(Spdif.Media != value) ConLog("* SPU2-X: SPDIF Media set to %04x\n",value);
if (Spdif.Media != value)
ConLog("* SPU2-X: SPDIF Media set to %04x\n", value);
RegLog(2, "SPDIF_MEDIA", rmem, -1, value);
break;
case 0x7ca:
if(Spdif.Unknown2 != value) ConLog("* SPU2-X: SPDIF Unknown Register 2 set to %04x\n",value);
if (Spdif.Unknown2 != value)
ConLog("* SPU2-X: SPDIF Unknown Register 2 set to %04x\n", value);
RegLog(2, "SPDIF_UNKNOWN2", rmem, -1, value);
break;
case SPDIF_PROTECT:
if(Spdif.Protection != value) ConLog("* SPU2-X: SPDIF Copy set to %04x\n",value);
if (Spdif.Protection != value)
ConLog("* SPU2-X: SPDIF Copy set to %04x\n", value);
RegLog(2, "SPDIF_PROTECT", rmem, -1, value);
break;
}
UpdateSpdifMode();
}
else
{
switch(omem)
{
} else {
switch (omem) {
case REG_C_ATTR:
RegLog(4, "ATTR", rmem, core, value);
break;
@ -247,8 +289,8 @@ void SPU2writeLog( const char* action, u32 rmem, u16 value )
LOG_REVB_REG(MIX_DEST_B1, "MIX_DEST_B1")
default:
RegLog(2,"UNKNOWN",rmem,core,value); spu2Ru16(mem) = value;
RegLog(2, "UNKNOWN", rmem, core, value);
spu2Ru16(mem) = value;
}
}
}

View File

@ -24,7 +24,8 @@
PCORE(c, Voices[v].p)
#define PVC(c, v) \
PVCP(c,v,Volume.Left.Reg_VOL), \
PVCP(c, v, Volume.Left.Reg_VOL) \
, \
PVCP(c, v, Volume.Right.Reg_VOL), \
PVCP(c, v, Pitch), \
PVCP(c, v, ADSR.regADSR1), \
@ -299,5 +300,4 @@ u16 const* const regtable_original[0x401] =
PRAW(0x7F0), PRAW(0x7F2), PRAW(0x7F4), PRAW(0x7F6),
PRAW(0x7F8), PRAW(0x7FA), PRAW(0x7FC), PRAW(0x7FE),
NULL
};
NULL};

View File

@ -31,8 +31,7 @@ __forceinline s32 V_Core::RevbGetIndexer( s32 offset )
// Fast and simple single step wrapping, made possible by the preparation of the
// effects buffer addresses.
if( pos > EffectsEndA )
{
if (pos > EffectsEndA) {
pos -= EffectsEndA + 1;
pos += EffectsStartA;
}
@ -46,10 +45,10 @@ void V_Core::Reverb_AdvanceBuffer()
if (RevBuffers.NeedsUpdated)
UpdateEffectsBufferSize();
if( (Cycles & 1) && (EffectsBufferSize > 0) )
{
if ((Cycles & 1) && (EffectsBufferSize > 0)) {
ReverbX += 1;
if( ReverbX >= (u32)EffectsBufferSize ) ReverbX = 0;
if (ReverbX >= (u32)EffectsBufferSize)
ReverbX = 0;
}
}
@ -68,8 +67,7 @@ StereoOut32 V_Core::DoReverb( const StereoOut32& Input )
static const s32 downcoeffs[8] =
{
855, 3562, 7263, 10163,
10163, 7263, 3562, 855
};
10163, 7263, 3562, 855};
#endif
downbuf[dbpos] = Input;
@ -78,17 +76,13 @@ StereoOut32 V_Core::DoReverb( const StereoOut32& Input )
// Reverb processing occurs at 24khz, so we skip processing every other sample,
// and use the previous calculation for this core instead.
if( (Cycles&1) == 0 )
{
if ((Cycles & 1) == 0) {
// Important: Factor silence into the upsampler here, otherwise the reverb engine
// develops a nasty feedback loop.
upbuf[ubpos] = StereoOut32::Empty;
}
else
{
if( EffectsBufferSize <= 0 )
{
} else {
if (EffectsBufferSize <= 0) {
ubpos = (ubpos + 1) & 7;
return StereoOut32::Empty;
}
@ -140,10 +134,8 @@ StereoOut32 V_Core::DoReverb( const StereoOut32& Input )
// within that zone then the "bulk" of the test is skipped, so this should only
// be a slowdown on a few evil games.
for( int i=0; i<2; i++ )
{
if( Cores[i].IRQEnable && ((Cores[i].IRQA >= EffectsStartA) && (Cores[i].IRQA <= EffectsEndA)) )
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && ((Cores[i].IRQA >= EffectsStartA) && (Cores[i].IRQA <= EffectsEndA))) {
if ((Cores[i].IRQA == src_a0) || (Cores[i].IRQA == src_a1) ||
(Cores[i].IRQA == src_b0) || (Cores[i].IRQA == src_b1) ||
@ -162,8 +154,7 @@ StereoOut32 V_Core::DoReverb( const StereoOut32& Input )
(Cores[i].IRQA == fb_src_b0) || (Cores[i].IRQA == fb_src_b1) ||
(Cores[i].IRQA == mix_dest_a0) || (Cores[i].IRQA == mix_dest_a1) ||
(Cores[i].IRQA == mix_dest_b0) || (Cores[i].IRQA == mix_dest_b1) )
{
(Cores[i].IRQA == mix_dest_b0) || (Cores[i].IRQA == mix_dest_b1)) {
//printf("Core %d IRQ Called (Reverb). IRQA = %x\n",i,addr);
SetIrqCall(i);
}
@ -176,8 +167,7 @@ StereoOut32 V_Core::DoReverb( const StereoOut32& Input )
StereoOut32 INPUT_SAMPLE;
for( int x=0; x<8; ++x )
{
for (int x = 0; x < 8; ++x) {
INPUT_SAMPLE.Left += (downbuf[(dbpos + x) & 7].Left * downcoeffs[x]);
INPUT_SAMPLE.Right += (downbuf[(dbpos + x) & 7].Right * downcoeffs[x]);
}
@ -213,15 +203,13 @@ StereoOut32 V_Core::DoReverb( const StereoOut32& Input )
((_spu2mem[acc_src_a0] * Revb.ACC_COEF_A) >> 15) +
((_spu2mem[acc_src_b0] * Revb.ACC_COEF_B) >> 15) +
((_spu2mem[acc_src_c0] * Revb.ACC_COEF_C) >> 15) +
((_spu2mem[acc_src_d0] * Revb.ACC_COEF_D) >> 15)
);
((_spu2mem[acc_src_d0] * Revb.ACC_COEF_D) >> 15));
const s32 ACC1 = clamp_mix(
((_spu2mem[acc_src_a1] * Revb.ACC_COEF_A) >> 15) +
((_spu2mem[acc_src_b1] * Revb.ACC_COEF_B) >> 15) +
((_spu2mem[acc_src_c1] * Revb.ACC_COEF_C) >> 15) +
((_spu2mem[acc_src_d1] * Revb.ACC_COEF_D) >> 15)
);
((_spu2mem[acc_src_d1] * Revb.ACC_COEF_D) >> 15));
// The following code differs from Neill's doc as it uses the more natural single-mul
// interpolative, instead of the funky ^0x8000 stuff. (better result, faster)
@ -255,13 +243,10 @@ StereoOut32 V_Core::DoReverb( const StereoOut32& Input )
// retval.Right += (upbuf[(ubpos+x)&7].Right*downcoeffs[x]);
//}
if( (Cycles&1) == 0 )
{
if ((Cycles & 1) == 0) {
retval.Left = (upbuf[(ubpos + 5) & 7].Left + upbuf[(ubpos + 7) & 7].Left) >> 1;
retval.Right = (upbuf[(ubpos + 5) & 7].Right + upbuf[(ubpos + 7) & 7].Right) >> 1;
}
else
{
} else {
retval.Left = upbuf[(ubpos + 6) & 7].Left;
retval.Right = upbuf[(ubpos + 6) & 7].Right;
}

View File

@ -20,15 +20,15 @@
StereoOut32 StereoOut32::Empty(0, 0);
StereoOut32::StereoOut32( const StereoOut16& src ) :
Left( src.Left ),
Right( src.Right )
StereoOut32::StereoOut32(const StereoOut16 &src)
: Left(src.Left)
, Right(src.Right)
{
}
StereoOut32::StereoOut32( const StereoOutFloat& src ) :
Left( (s32)(src.Left * 2147483647.0f) ),
Right( (s32)(src.Right * 2147483647.0f) )
StereoOut32::StereoOut32(const StereoOutFloat &src)
: Left((s32)(src.Left * 2147483647.0f))
, Right((s32)(src.Right * 2147483647.0f))
{
}
@ -36,17 +36,14 @@ StereoOut16 StereoOut32::DownSample() const
{
return StereoOut16(
Left >> SndOutVolumeShift,
Right >> SndOutVolumeShift
);
Right >> SndOutVolumeShift);
}
StereoOut32 StereoOut16::UpSample() const
{
return StereoOut32(
Left << SndOutVolumeShift,
Right << SndOutVolumeShift
);
Right << SndOutVolumeShift);
}
@ -104,8 +101,7 @@ SndOutModule* mods[]=
int FindOutputModuleById(const wchar_t *omodid)
{
int modcnt = 0;
while( mods[modcnt] != NULL )
{
while (mods[modcnt] != NULL) {
if (wcscmp(mods[modcnt]->GetIdent(), omodid) == 0)
break;
++modcnt;
@ -135,15 +131,13 @@ bool SndBuffer::CheckUnderrunStatus( int& nSamples, int& quietSampleCount )
quietSampleCount = 0;
int data = _GetApproximateDataInBuffer();
if( m_underrun_freeze )
{
if (m_underrun_freeze) {
int toFill = m_size / ((SynchMode == 2) ? 32 : 400); // TimeStretch and Async off?
toFill = GetAlignedBufferSize(toFill);
// toFill is now aligned to a SndOutPacket
if( data < toFill )
{
if (data < toFill) {
quietSampleCount = nSamples;
return false;
}
@ -152,9 +146,7 @@ bool SndBuffer::CheckUnderrunStatus( int& nSamples, int& quietSampleCount )
if (MsgOverruns())
ConLog(" * SPU2 > Underrun compensation (%d packets buffered)\n", toFill / SndOutPacketSize);
lastPct = 0.0; // normalize timestretcher
}
else if( data < nSamples )
{
} else if (data < nSamples) {
nSamples = data;
quietSampleCount = SndOutPacketSize - data;
m_underrun_freeze = true;
@ -207,16 +199,13 @@ void SndBuffer::_ReadSamples_Internal(StereoOut32 *bData, int nSamples)
void SndBuffer::_WriteSamples_Safe(StereoOut32 *bData, int nSamples)
{
// WARNING: This code assumes there's only ONE writing process.
if( (m_size - m_wpos) < nSamples)
{
if ((m_size - m_wpos) < nSamples) {
int b1 = m_size - m_wpos;
int b2 = nSamples - b1;
_WriteSamples_Internal(bData, b1);
_WriteSamples_Internal(bData + b1, b2);
}
else
{
} else {
_WriteSamples_Internal(bData, nSamples);
}
}
@ -224,16 +213,13 @@ void SndBuffer::_WriteSamples_Safe(StereoOut32 *bData, int nSamples)
void SndBuffer::_ReadSamples_Safe(StereoOut32 *bData, int nSamples)
{
// WARNING: This code assumes there's only ONE reading process.
if( (m_size - m_rpos) < nSamples)
{
if ((m_size - m_rpos) < nSamples) {
int b1 = m_size - m_rpos;
int b2 = nSamples - b1;
_ReadSamples_Internal(bData, b1);
_ReadSamples_Internal(bData + b1, b2);
}
else
{
} else {
_ReadSamples_Internal(bData, nSamples);
}
}
@ -242,7 +228,8 @@ void SndBuffer::_ReadSamples_Safe(StereoOut32* bData, int nSamples)
// for shifting the values to where they need to be manually. The fixed point depth of
// the sample output is determined by the SndOutVolumeShift, which is the number of bits
// to shift right to get a 16 bit result.
template<typename T> void SndBuffer::ReadSamples(T* bData)
template <typename T>
void SndBuffer::ReadSamples(T *bData)
{
int nSamples = SndOutPacketSize;
@ -260,8 +247,7 @@ template<typename T> void SndBuffer::ReadSamples(T* bData)
// set buffer length in duration.
int quietSamples;
if( CheckUnderrunStatus( nSamples, quietSamples ) )
{
if (CheckUnderrunStatus(nSamples, quietSamples)) {
pxAssume(nSamples <= SndOutPacketSize);
// WARNING: This code assumes there's only ONE reading process.
@ -270,8 +256,7 @@ template<typename T> void SndBuffer::ReadSamples(T* bData)
if (b1 > nSamples)
b1 = nSamples;
if (AdvancedVolumeControl)
{
if (AdvancedVolumeControl) {
// First part
for (int i = 0; i < b1; i++)
bData[i].AdjustFrom(m_buffer[i + m_rpos]);
@ -280,9 +265,7 @@ template<typename T> void SndBuffer::ReadSamples(T* bData)
int b2 = nSamples - b1;
for (int i = 0; i < b2; i++)
bData[i + b1].AdjustFrom(m_buffer[i]);
}
else
{
} else {
// First part
for (int i = 0; i < b1; i++)
bData[i].ResampleFrom(m_buffer[i + m_rpos]);
@ -339,8 +322,7 @@ void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
// so that the overall audio synchronization is better.
int free = m_size - _GetApproximateDataInBuffer(); // -1, but the <= handles that
if( free <= nSamples )
{
if (free <= nSamples) {
// Disabled since the lock-free queue can't handle changing the read end from the write thread
#if 0
// Buffer overrun!
@ -378,8 +360,7 @@ void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
void SndBuffer::Init()
{
if( mods[OutputModule] == NULL )
{
if (mods[OutputModule] == NULL) {
_InitFail();
return;
}
@ -391,8 +372,7 @@ void SndBuffer::Init()
m_rpos = 0;
m_wpos = 0;
try
{
try {
const float latencyMS = SndOutLatencyMS * 16;
m_size = GetAlignedBufferSize((int)(latencyMS * SampleRate / 1000.0f));
m_buffer = new StereoOut32[m_size];
@ -400,9 +380,7 @@ void SndBuffer::Init()
sndTempBuffer = new StereoOut32[SndOutPacketSize];
sndTempBuffer16 = new StereoOut16[SndOutPacketSize * 2]; // in case of leftovers.
}
catch( std::bad_alloc& )
{
} catch (std::bad_alloc &) {
// out of memory exception (most likely)
SysMessage("Out of memory error occurred while initializing SPU2.");
@ -420,7 +398,8 @@ void SndBuffer::Init()
soundtouchInit(); // initializes the timestretching
// initialize module
if( mods[OutputModule]->Init() == -1 ) _InitFail();
if (mods[OutputModule]->Init() == -1)
_InitFail();
}
void SndBuffer::Cleanup()
@ -450,7 +429,8 @@ void SndBuffer::Write( const StereoOut32& Sample )
// Log final output to wavefile.
WaveDump::WriteCore(1, CoreSrc_External, Sample.DownSample());
if( WavRecordEnabled ) RecordWrite( Sample.DownSample() );
if (WavRecordEnabled)
RecordWrite(Sample.DownSample());
if (mods[OutputModule] == &NullOut) // null output doesn't need buffering or stretching! :p
return;
@ -458,29 +438,31 @@ void SndBuffer::Write( const StereoOut32& Sample )
sndTempBuffer[sndTempProgress++] = Sample;
// If we haven't accumulated a full packet yet, do nothing more:
if(sndTempProgress < SndOutPacketSize) return;
if (sndTempProgress < SndOutPacketSize)
return;
sndTempProgress = 0;
//Don't play anything directly after loading a savestate, avoids static killing your speakers.
if ( ssFreeze > 0 )
{
if (ssFreeze > 0) {
ssFreeze--;
memset(sndTempBuffer, 0, sizeof(StereoOut32) * SndOutPacketSize); // Play silence
}
#ifndef __POSIX__
if( dspPluginEnabled )
{
if (dspPluginEnabled) {
// Convert in, send to winamp DSP, and convert out.
int ei = m_dsp_progress;
for( int i=0; i<SndOutPacketSize; ++i, ++ei ) { sndTempBuffer16[ei] = sndTempBuffer[i].DownSample(); }
for (int i = 0; i < SndOutPacketSize; ++i, ++ei) {
sndTempBuffer16[ei] = sndTempBuffer[i].DownSample();
}
m_dsp_progress += DspProcess((s16 *)sndTempBuffer16 + m_dsp_progress, SndOutPacketSize);
// Some ugly code to ensure full packet handling:
ei = 0;
while( m_dsp_progress >= SndOutPacketSize )
{
for( int i=0; i<SndOutPacketSize; ++i, ++ei ) { sndTempBuffer[i] = sndTempBuffer16[ei].UpSample(); }
while (m_dsp_progress >= SndOutPacketSize) {
for (int i = 0; i < SndOutPacketSize; ++i, ++ei) {
sndTempBuffer[i] = sndTempBuffer16[ei].UpSample();
}
if (SynchMode == 0) // TimeStrech on
timeStretchWrite();
@ -491,16 +473,13 @@ void SndBuffer::Write( const StereoOut32& Sample )
}
// copy any leftovers to the front of the dsp buffer.
if( m_dsp_progress > 0 )
{
if (m_dsp_progress > 0) {
memcpy(sndTempBuffer16, &sndTempBuffer16[ei],
sizeof(sndTempBuffer16[0]) * m_dsp_progress
);
sizeof(sndTempBuffer16[0]) * m_dsp_progress);
}
}
#endif
else
{
else {
if (SynchMode == 0) // TimeStrech on
timeStretchWrite();
else

View File

@ -64,21 +64,21 @@ struct StereoOut16
s16 Left;
s16 Right;
StereoOut16() :
Left( 0 ),
Right( 0 )
StereoOut16()
: Left(0)
, Right(0)
{
}
StereoOut16( const StereoOut32& src ) :
Left( (s16)src.Left ),
Right( (s16)src.Right )
StereoOut16(const StereoOut32 &src)
: Left((s16)src.Left)
, Right((s16)src.Right)
{
}
StereoOut16( s16 left, s16 right ) :
Left( left ),
Right( right )
StereoOut16(s16 left, s16 right)
: Left(left)
, Right(right)
{
}
@ -104,27 +104,27 @@ struct StereoOutFloat
float Left;
float Right;
StereoOutFloat() :
Left( 0 ),
Right( 0 )
StereoOutFloat()
: Left(0)
, Right(0)
{
}
explicit StereoOutFloat( const StereoOut32& src ) :
Left( src.Left / 2147483647.0f ),
Right( src.Right / 2147483647.0f )
explicit StereoOutFloat(const StereoOut32 &src)
: Left(src.Left / 2147483647.0f)
, Right(src.Right / 2147483647.0f)
{
}
explicit StereoOutFloat( s32 left, s32 right ) :
Left( left / 2147483647.0f ),
Right( right / 2147483647.0f )
explicit StereoOutFloat(s32 left, s32 right)
: Left(left / 2147483647.0f)
, Right(right / 2147483647.0f)
{
}
StereoOutFloat( float left, float right ) :
Left( left ),
Right( right )
StereoOutFloat(float left, float right)
: Left(left)
, Right(right)
{
}
};

View File

@ -80,6 +80,7 @@ private:
class ConvertedSampleReader : public SampleReader
{
int *written;
public:
ConvertedSampleReader(int *pWritten)
{
@ -132,8 +133,7 @@ public:
ReadSettings();
PaError err = Pa_Initialize();
if( err != paNoError )
{
if (err != paNoError) {
fprintf(stderr, "* SPU2-X: PortAudio error: %s\n", Pa_GetErrorText(err));
return -1;
}
@ -142,24 +142,19 @@ public:
int deviceIndex = -1;
fprintf(stderr, "* SPU2-X: Enumerating PortAudio devices:\n");
for(int i=0, j=0;i<Pa_GetDeviceCount();i++)
{
for (int i = 0, j = 0; i < Pa_GetDeviceCount(); i++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if(info->maxOutputChannels > 0)
{
if (info->maxOutputChannels > 0) {
const PaHostApiInfo *apiinfo = Pa_GetHostApiInfo(info->hostApi);
fprintf(stderr, " *** Device %d: '%s' (%s)", j, info->name, apiinfo->name);
if(apiinfo->type == m_ApiId)
{
if(m_Device == wxString::FromUTF8(info->name))
{
if (apiinfo->type == m_ApiId) {
if (m_Device == wxString::FromUTF8(info->name)) {
deviceIndex = i;
fprintf(stderr, " (selected)");
}
}
fprintf(stderr, "\n");
@ -168,20 +163,16 @@ public:
}
fflush(stderr);
if(deviceIndex<0 && m_ApiId>=0)
{
for(int i=0;i<Pa_GetHostApiCount();i++)
{
if (deviceIndex < 0 && m_ApiId >= 0) {
for (int i = 0; i < Pa_GetHostApiCount(); i++) {
const PaHostApiInfo *apiinfo = Pa_GetHostApiInfo(i);
if(apiinfo->type == m_ApiId)
{
if (apiinfo->type == m_ApiId) {
deviceIndex = apiinfo->defaultOutputDevice;
}
}
}
if(deviceIndex>=0)
{
if (deviceIndex >= 0) {
void *infoPtr = NULL;
const PaDeviceInfo *devinfo = Pa_GetDeviceInfo(deviceIndex);
@ -189,16 +180,24 @@ public:
int speakers;
switch (numSpeakers) // speakers = (numSpeakers + 1) *2; ?
{
case 0: speakers = 2; break; // Stereo
case 1: speakers = 4; break; // Quadrafonic
case 2: speakers = 6; break; // Surround 5.1
case 3: speakers = 8; break; // Surround 7.1
default: speakers = 2;
case 0:
speakers = 2;
break; // Stereo
case 1:
speakers = 4;
break; // Quadrafonic
case 2:
speakers = 6;
break; // Surround 5.1
case 3:
speakers = 8;
break; // Surround 7.1
default:
speakers = 2;
}
actualUsedChannels = std::min(speakers, devinfo->maxOutputChannels);
switch( actualUsedChannels )
{
switch (actualUsedChannels) {
case 2:
ConLog("* SPU2 > Using normal 2 speaker stereo output.\n");
ActualPaCallback = new ConvertedSampleReader<Stereo20Out32>(&writtenSoFar);
@ -221,8 +220,7 @@ public:
case 6:
case 7:
switch(dplLevel)
{
switch (dplLevel) {
case 0:
ConLog("* SPU2 > 5.1 speaker expansion enabled.\n");
ActualPaCallback = new ConvertedSampleReader<Stereo51Out32>(&writtenSoFar); //"normal" stereo upmix
@ -251,11 +249,9 @@ public:
sizeof(PaWasapiStreamInfo),
paWASAPI,
1,
paWinWasapiExclusive
};
paWinWasapiExclusive};
if((m_ApiId == paWASAPI) && m_WasapiExclusiveMode)
{
if ((m_ApiId == paWASAPI) && m_WasapiExclusiveMode) {
// Pass it the Exclusive mode enable flag
infoPtr = &info;
}
@ -272,8 +268,7 @@ public:
actualUsedChannels,
paInt32,
m_SuggestedLatencyMinimal ? (SndOutPacketSize / (float)SampleRate) : (m_SuggestedLatencyMS / 1000.0f),
infoPtr
};
infoPtr};
err = Pa_OpenStream(&stream,
NULL, &outParams, SampleRate,
@ -282,25 +277,21 @@ public:
PaCallback,
NULL);
}
else
{
} else {
err = Pa_OpenDefaultStream(&stream,
0, actualUsedChannels, paInt32, 48000,
SndOutPacketSize,
PaCallback,
NULL);
}
if( err != paNoError )
{
if (err != paNoError) {
fprintf(stderr, "* SPU2-X: PortAudio error: %s\n", Pa_GetErrorText(err));
Pa_Terminate();
return -1;
}
err = Pa_StartStream(stream);
if( err != paNoError )
{
if (err != paNoError) {
fprintf(stderr, "* SPU2-X: PortAudio error: %s\n", Pa_GetErrorText(err));
Pa_CloseStream(stream);
stream = NULL;
@ -314,12 +305,9 @@ public:
void Close()
{
PaError err;
if(started)
{
if(stream)
{
if(Pa_IsStreamActive(stream))
{
if (started) {
if (stream) {
if (Pa_IsStreamActive(stream)) {
err = Pa_StopStream(stream);
if (err != paNoError)
fprintf(stderr, "* SPU2-X: PortAudio error: %s\n", Pa_GetErrorText(err));
@ -346,16 +334,13 @@ public:
////////////////////////////////////////////////////////////////
#ifdef _WIN32
private:
bool _ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
int tSel = 0;
switch(uMsg)
{
case WM_INITDIALOG:
{
switch (uMsg) {
case WM_INITDIALOG: {
wchar_t temp[128];
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_RESETCONTENT, 0, 0);
@ -365,38 +350,31 @@ private:
SendMessage(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_RESETCONTENT, 0, 0);
SendMessageA(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_ADDSTRING, 0, (LPARAM) "Unspecified");
int idx = 0;
for(int i=0;i<Pa_GetHostApiCount();i++)
{
for (int i = 0; i < Pa_GetHostApiCount(); i++) {
const PaHostApiInfo *apiinfo = Pa_GetHostApiInfo(i);
if(apiinfo->deviceCount > 0)
{
if (apiinfo->deviceCount > 0) {
SendMessageA(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_ADDSTRING, 0, (LPARAM)apiinfo->name);
SendMessageA(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_SETITEMDATA, i + 1, apiinfo->type);
}
if(apiinfo->type == m_ApiId)
{
if (apiinfo->type == m_ApiId) {
idx = i + 1;
}
}
SendMessage(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_SETCURSEL, idx, 0);
if(idx > 0)
{
if (idx > 0) {
int api_idx = idx - 1;
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_RESETCONTENT, 0, 0);
SendMessageA(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_ADDSTRING, 0, (LPARAM) "Default Device");
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_SETITEMDATA, 0, 0);
int _idx = 0;
int i = 1;
for(int j=0;j<Pa_GetDeviceCount();j++)
{
for (int j = 0; j < Pa_GetDeviceCount(); j++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
if(info->hostApi == api_idx && info->maxOutputChannels > 0)
{
if (info->hostApi == api_idx && info->maxOutputChannels > 0) {
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_ADDSTRING, 0, (LPARAM)wxString::FromUTF8(info->name).wc_str());
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_SETITEMDATA, i, (LPARAM)info);
if(wxString::FromUTF8(info->name) == m_Device)
{
if (wxString::FromUTF8(info->name) == m_Device) {
_idx = i;
}
i++;
@ -416,20 +394,16 @@ private:
SET_CHECK(IDC_MANUAL, true);
SET_CHECK(IDC_EXCLUSIVE, m_WasapiExclusiveMode);
}
break;
} break;
case WM_COMMAND:
{
case WM_COMMAND: {
//wchar_t temp[128];
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDOK:
{
switch (wmId) {
case IDOK: {
int idx = (int)SendMessage(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_GETCURSEL, 0, 0);
m_ApiId = SendMessage(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_GETITEMDATA, idx, 0);
@ -442,25 +416,24 @@ private:
m_SuggestedLatencyMS = (int)SendMessage(GetDlgItem(hWnd, IDC_LATENCY), TBM_GETPOS, 0, 0);
if( m_SuggestedLatencyMS < 10 ) m_SuggestedLatencyMS = 10;
if( m_SuggestedLatencyMS > 200 ) m_SuggestedLatencyMS = 200;
if (m_SuggestedLatencyMS < 10)
m_SuggestedLatencyMS = 10;
if (m_SuggestedLatencyMS > 200)
m_SuggestedLatencyMS = 200;
m_SuggestedLatencyMinimal = SendMessage(GetDlgItem(hWnd, IDC_MINIMIZE), BM_GETCHECK, 0, 0) == BST_CHECKED;
m_WasapiExclusiveMode = SendMessage(GetDlgItem(hWnd, IDC_EXCLUSIVE), BM_GETCHECK, 0, 0) == BST_CHECKED;
EndDialog(hWnd, 0);
}
break;
} break;
case IDCANCEL:
EndDialog(hWnd, 0);
break;
case IDC_PA_HOSTAPI:
{
if(wmEvent == CBN_SELCHANGE)
{
case IDC_PA_HOSTAPI: {
if (wmEvent == CBN_SELCHANGE) {
int api_idx = (int)SendMessage(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_GETCURSEL, 0, 0) - 1;
int apiId = SendMessageA(GetDlgItem(hWnd, IDC_PA_HOSTAPI), CB_GETITEMDATA, api_idx, 0);
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_RESETCONTENT, 0, 0);
@ -468,11 +441,9 @@ private:
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_SETITEMDATA, 0, 0);
int idx = 0;
int i = 1;
for(int j=0;j<Pa_GetDeviceCount();j++)
{
for (int j = 0; j < Pa_GetDeviceCount(); j++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
if(info->hostApi == api_idx && info->maxOutputChannels > 0)
{
if (info->hostApi == api_idx && info->maxOutputChannels > 0) {
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_ADDSTRING, 0, (LPARAM)wxString::FromUTF8(info->name).wc_str());
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_SETITEMDATA, i, (LPARAM)info);
i++;
@ -480,21 +451,17 @@ private:
}
SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_SETCURSEL, idx, 0);
}
}
break;
} break;
default:
return FALSE;
}
}
break;
} break;
case WM_HSCROLL:
{
case WM_HSCROLL: {
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch(wmId)
{
switch (wmId) {
//case TB_ENDTRACK:
//case TB_THUMBPOSITION:
case TB_LINEUP:
@ -502,11 +469,12 @@ private:
case TB_PAGEUP:
case TB_PAGEDOWN:
wmEvent = (int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0);
case TB_THUMBTRACK:
{
case TB_THUMBTRACK: {
wchar_t temp[128];
if( wmEvent < 10 ) wmEvent = 10;
if( wmEvent > 200 ) wmEvent = 200;
if (wmEvent < 10)
wmEvent = 10;
if (wmEvent > 200)
wmEvent = 200;
SendMessage((HWND)lParam, TBM_SETPOS, TRUE, wmEvent);
swprintf_s(temp, L"%d ms", wmEvent);
SetWindowText(GetDlgItem(hWnd, IDC_LATENCY_LABEL), temp);
@ -515,8 +483,7 @@ private:
default:
return FALSE;
}
}
break;
} break;
default:
return FALSE;
@ -531,8 +498,7 @@ public:
virtual void Configure(uptr parent)
{
PaError err = Pa_Initialize(); // Initialization can be done multiple times, PA keeps a counter
if( err != paNoError )
{
if (err != paNoError) {
fprintf(stderr, "* SPU2-X: PortAudio error: %s\n", Pa_GetErrorText(err));
return;
}
@ -540,8 +506,7 @@ public:
INT_PTR ret;
ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_PORTAUDIO), (HWND)parent, (DLGPROC)ConfigProc, 1);
if(ret==-1)
{
if (ret == -1) {
MessageBox((HWND)parent, L"Error Opening the config dialog.", L"OMG ERROR!", MB_OK | MB_SETFOREGROUND);
return;
}
@ -602,49 +567,93 @@ public:
m_SuggestedLatencyMinimal = CfgReadBool(L"PORTAUDIO", L"Minimal_Suggested_Latency", true);
m_SuggestedLatencyMS = CfgReadInt(L"PORTAUDIO", L"Manual_Suggested_Latency_MS", 20);
if( m_SuggestedLatencyMS < 10 ) m_SuggestedLatencyMS = 10;
if( m_SuggestedLatencyMS > 200 ) m_SuggestedLatencyMS = 200;
if (m_SuggestedLatencyMS < 10)
m_SuggestedLatencyMS = 10;
if (m_SuggestedLatencyMS > 200)
m_SuggestedLatencyMS = 200;
}
void SetApiSettings(wxString api)
{
m_ApiId = -1;
if(api == L"InDevelopment") m_ApiId = paInDevelopment; /* use while developing support for a new host API */
if(api == L"DirectSound") m_ApiId = paDirectSound;
if(api == L"MME") m_ApiId = paMME;
if(api == L"ASIO") m_ApiId = paASIO;
if(api == L"SoundManager") m_ApiId = paSoundManager;
if(api == L"CoreAudio") m_ApiId = paCoreAudio;
if(api == L"OSS") m_ApiId = paOSS;
if(api == L"ALSA") m_ApiId = paALSA;
if(api == L"AL") m_ApiId = paAL;
if(api == L"BeOS") m_ApiId = paBeOS;
if(api == L"WDMKS") m_ApiId = paWDMKS;
if(api == L"JACK") m_ApiId = paJACK;
if(api == L"WASAPI") m_ApiId = paWASAPI;
if(api == L"AudioScienceHPI") m_ApiId = paAudioScienceHPI;
if (api == L"InDevelopment")
m_ApiId = paInDevelopment; /* use while developing support for a new host API */
if (api == L"DirectSound")
m_ApiId = paDirectSound;
if (api == L"MME")
m_ApiId = paMME;
if (api == L"ASIO")
m_ApiId = paASIO;
if (api == L"SoundManager")
m_ApiId = paSoundManager;
if (api == L"CoreAudio")
m_ApiId = paCoreAudio;
if (api == L"OSS")
m_ApiId = paOSS;
if (api == L"ALSA")
m_ApiId = paALSA;
if (api == L"AL")
m_ApiId = paAL;
if (api == L"BeOS")
m_ApiId = paBeOS;
if (api == L"WDMKS")
m_ApiId = paWDMKS;
if (api == L"JACK")
m_ApiId = paJACK;
if (api == L"WASAPI")
m_ApiId = paWASAPI;
if (api == L"AudioScienceHPI")
m_ApiId = paAudioScienceHPI;
}
void WriteSettings() const
{
wxString api;
switch(m_ApiId)
{
case paInDevelopment: api = L"InDevelopment"; break; /* use while developing support for a new host API */
case paDirectSound: api = L"DirectSound"; break;
case paMME: api = L"MME"; break;
case paASIO: api = L"ASIO"; break;
case paSoundManager: api = L"SoundManager"; break;
case paCoreAudio: api = L"CoreAudio"; break;
case paOSS: api = L"OSS"; break;
case paALSA: api = L"ALSA"; break;
case paAL: api = L"AL"; break;
case paBeOS: api = L"BeOS"; break;
case paWDMKS: api = L"WDMKS"; break;
case paJACK: api = L"JACK"; break;
case paWASAPI: api = L"WASAPI"; break;
case paAudioScienceHPI: api = L"AudioScienceHPI"; break;
default: api = L"Unknown";
switch (m_ApiId) {
case paInDevelopment:
api = L"InDevelopment";
break; /* use while developing support for a new host API */
case paDirectSound:
api = L"DirectSound";
break;
case paMME:
api = L"MME";
break;
case paASIO:
api = L"ASIO";
break;
case paSoundManager:
api = L"SoundManager";
break;
case paCoreAudio:
api = L"CoreAudio";
break;
case paOSS:
api = L"OSS";
break;
case paALSA:
api = L"ALSA";
break;
case paAL:
api = L"AL";
break;
case paBeOS:
api = L"BeOS";
break;
case paWDMKS:
api = L"WDMKS";
break;
case paJACK:
api = L"JACK";
break;
case paWASAPI:
api = L"WASAPI";
break;
case paAudioScienceHPI:
api = L"AudioScienceHPI";
break;
default:
api = L"Unknown";
}
CfgWriteStr(L"PORTAUDIO", L"HostApi", api);

View File

@ -29,7 +29,8 @@
#include <SDL_audio.h>
typedef StereoOut16 StereoOut_SDL;
namespace {
namespace
{
/* Since spu2 only ever outputs stereo, we don't worry about emitting surround sound
* even though SDL2 supports it */
const Uint8 channels = 2;
@ -44,7 +45,8 @@ namespace {
std::unique_ptr<StereoOut_SDL[]> buffer;
void callback_fillBuffer(void *userdata, Uint8 *stream, int len) {
void callback_fillBuffer(void *userdata, Uint8 *stream, int len)
{
Uint16 sdl_samples = samples;
#if SDL_MAJOR_VERSION >= 2
@ -63,11 +65,13 @@ namespace {
}
}
struct SDLAudioMod : public SndOutModule {
struct SDLAudioMod : public SndOutModule
{
static SDLAudioMod mod;
std::string m_api;
s32 Init() {
s32 Init()
{
ReadSettings();
#if SDL_MAJOR_VERSION >= 2
@ -122,7 +126,8 @@ struct SDLAudioMod : public SndOutModule {
const wchar_t *GetIdent() const { return L"SDLAudio"; }
const wchar_t *GetLongName() const { return L"SDL Audio"; }
void Close() {
void Close()
{
// Related to SDL_Init(SDL_INIT_AUDIO)
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
@ -134,17 +139,20 @@ struct SDLAudioMod : public SndOutModule {
void Configure(uptr parent) {}
void ReadSettings() {
void ReadSettings()
{
wxString api(L"EMPTYEMPTYEMPTY");
CfgReadStr(L"SDL", L"HostApi", api, L"pulseaudio");
SetApiSettings(api);
}
void WriteSettings() const {
void WriteSettings() const
{
CfgWriteStr(L"SDL", L"HostApi", wxString(m_api.c_str(), wxConvUTF8));
};
void SetApiSettings(wxString api) {
void SetApiSettings(wxString api)
{
#if SDL_MAJOR_VERSION >= 2
// Validate the api name
bool valid = false;
@ -166,8 +174,9 @@ struct SDLAudioMod : public SndOutModule {
private:
SDL_AudioSpec spec;
SDLAudioMod() : m_api("pulseaudio"),
spec({SampleRate, format, channels, 0,
SDLAudioMod()
: m_api("pulseaudio")
, spec({SampleRate, format, channels, 0,
desiredSamples, 0, 0, &callback_fillBuffer, nullptr})
{
// Number of samples must be a multiple of packet size.

View File

@ -50,14 +50,16 @@ int s2r_open(u32 ticks, char *filename)
void s2r_readreg(u32 ticks, u32 addr)
{
if(!s2rfile) return;
if (!s2rfile)
return;
s2r_write32(ticks);
EMITC(0, addr);
}
void s2r_writereg(u32 ticks, u32 addr, s16 value)
{
if(!s2rfile) return;
if (!s2rfile)
return;
s2r_write32(ticks);
EMITC(1, addr);
s2r_write16(value);
@ -66,7 +68,8 @@ void s2r_writereg(u32 ticks,u32 addr,s16 value)
void s2r_writedma4(u32 ticks, u16 *data, u32 len)
{
u32 i;
if(!s2rfile) return;
if (!s2rfile)
return;
s2r_write32(ticks);
EMITC(2, len);
for (i = 0; i < len; i++, data++)
@ -76,7 +79,8 @@ void s2r_writedma4(u32 ticks,u16*data,u32 len)
void s2r_writedma7(u32 ticks, u16 *data, u32 len)
{
u32 i;
if(!s2rfile) return;
if (!s2rfile)
return;
s2r_write32(ticks);
EMITC(3, len);
for (i = 0; i < len; i++, data++)
@ -85,7 +89,8 @@ void s2r_writedma7(u32 ticks,u16*data,u32 len)
void s2r_close()
{
if(!s2rfile) return;
if (!s2rfile)
return;
fclose(s2rfile);
}
@ -215,7 +220,8 @@ BOOL WINAPI HandlerRoutine(DWORD dwCtrlType)
#endif
#include "Windows/Dialogs.h"
EXPORT_C_(void) s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdShow)
EXPORT_C_(void)
s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdShow)
{
#ifndef ENABLE_NEW_IOPDMA_SPU2
int events = 0;
@ -228,12 +234,9 @@ EXPORT_C_(void) s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdS
conprintf("Playing %s file on %x...", filename, hwnd);
if (IsWindows8OrGreater())
{
for (int n = 0; mods[n] != nullptr; ++n)
{
if (mods[n] == XAudio2_27_Out)
{
if (IsWindows8OrGreater()) {
for (int n = 0; mods[n] != nullptr; ++n) {
if (mods[n] == XAudio2_27_Out) {
mods[n] = XAudio2Out;
break;
}
@ -245,14 +248,17 @@ EXPORT_C_(void) s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdS
// load file
FILE *file = fopen(filename, "rb");
if(!file)
{
if (!file) {
conprintf("Could not open the replay file.");
return;
}
// if successful, init the plugin
#define TryRead(dest,size,count,file) if(fread(dest,size,count,file)<count) { conprintf("Error reading from file."); goto Finish; /* Need to exit the while() loop and maybe also the switch */ }
#define TryRead(dest, size, count, file) \
if (fread(dest, size, count, file) < count) { \
conprintf("Error reading from file."); \
goto Finish; /* Need to exit the while() loop and maybe also the switch */ \
}
TryRead(&CurrentIOPCycle, 4, 1, file);
@ -269,8 +275,7 @@ EXPORT_C_(void) s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdS
SPU2async(0);
while(!feof(file) && Running)
{
while (!feof(file) && Running) {
u32 ccycle = 0;
u32 evid = 0;
u32 sval = 0;
@ -284,14 +289,12 @@ EXPORT_C_(void) s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdS
u32 TargetCycle = ccycle * 768;
while(TargetCycle > CurrentIOPCycle)
{
while (TargetCycle > CurrentIOPCycle) {
u32 delta = WaitSync(TargetCycle);
SPU2async(delta);
}
switch(evid)
{
switch (evid) {
case 0:
SPU2read(sval);
break;

View File

@ -108,7 +108,8 @@ unsigned int AVERAGING_WINDOW = 50.0 * targetIPS/750;
#define STRETCHER_RESET_THRESHOLD 5
int gRequestStretcherReset = STRETCHER_RESET_THRESHOLD;
//Adds a value to the running average buffer, and return the new running average.
float addToAvg(float val){
float addToAvg(float val)
{
static float avg_fullness[AVERAGING_BUFFER_SIZE];
static unsigned int nextAvgPos = 0;
static unsigned int available = 0; // Make sure we're not averaging AVERAGING_WINDOW items if we inserted less.
@ -122,8 +123,7 @@ float addToAvg(float val){
nextAvgPos = (nextAvgPos + 1U) % AVERAGING_BUFFER_SIZE;
unsigned int actualWindow = std::min(available, AVERAGING_WINDOW);
unsigned int first = (nextAvgPos - actualWindow + AVERAGING_BUFFER_SIZE)
% AVERAGING_BUFFER_SIZE;
unsigned int first = (nextAvgPos - actualWindow + AVERAGING_BUFFER_SIZE) % AVERAGING_BUFFER_SIZE;
// Possible optimization: if we know that actualWindow hasn't changed since
// last invocation, we could calculate the running average in O(1) instead of O(N)
@ -177,7 +177,8 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
if (delta.GetMilliseconds() > 500) {
int pot_targetIPS = 1000.0 / delta.GetMilliseconds().ToDouble() * iters;
if (!IsInRange(pot_targetIPS, int((float)targetIPS / 1.3f), int((float)targetIPS * 1.3f))) {
if(MsgOverruns()) ConLog("Stretcher: setting iters/sec from %d to %d\n", targetIPS, pot_targetIPS);
if (MsgOverruns())
ConLog("Stretcher: setting iters/sec from %d to %d\n", targetIPS, pot_targetIPS);
targetIPS = pot_targetIPS;
AVERAGING_WINDOW = GetClamped((int)(50.0f * (float)targetIPS / 750.0f), 3, (int)AVERAGING_BUFFER_SIZE);
}
@ -213,8 +214,7 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
if (IsInRange(tempoAdjust, 0.9f, 1.1f) && IsInRange(dynamicTargetFullness, baseTargetFullness * 0.9f, baseTargetFullness * 1.1f))
dynamicTargetFullness = baseTargetFullness;
if( !inside_hysteresis )
{
if (!inside_hysteresis) {
if (IsInRange(tempoAdjust, 1.0f / hys_ok_factor, hys_ok_factor))
hys_ok_count++;
else
@ -222,12 +222,13 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
if (hys_ok_count >= hys_min_ok_count) {
inside_hysteresis = true;
if(MsgOverruns()) ConLog("======> stretch: None (1:1)\n");
if (MsgOverruns())
ConLog("======> stretch: None (1:1)\n");
}
}
else if( !IsInRange( tempoAdjust, 1.0f/hys_bad_factor, hys_bad_factor ) ){
if(MsgOverruns()) ConLog("~~~~~~> stretch: Dynamic\n");
} else if (!IsInRange(tempoAdjust, 1.0f / hys_bad_factor, hys_bad_factor)) {
if (MsgOverruns())
ConLog("~~~~~~> stretch: Dynamic\n");
inside_hysteresis = false;
hys_ok_count = 0;
}
@ -243,9 +244,7 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
if (delta.GetMilliseconds() > 1000) { //report buffers state and tempo adjust every second
ConLog("buffers: %4d ms (%3.0f%%), tempo: %f, comp: %2.3f, iters: %d, (N-IPS:%d -> avg:%d, minokc:%d, div:%d) reset:%d\n",
(int)(data/48), (double)(100.0*bufferFullness/baseTargetFullness), (double)tempoAdjust, (double)(dynamicTargetFullness/baseTargetFullness), iters, (int)targetIPS
, AVERAGING_WINDOW, hys_min_ok_count, compensationDivider, gRequestStretcherReset
);
(int)(data / 48), (double)(100.0 * bufferFullness / baseTargetFullness), (double)tempoAdjust, (double)(dynamicTargetFullness / baseTargetFullness), iters, (int)targetIPS, AVERAGING_WINDOW, hys_min_ok_count, compensationDivider, gRequestStretcherReset);
last = unow;
iters = 0;
}
@ -284,8 +283,7 @@ void SndBuffer::UpdateTempoChangeSoundTouch()
tempoChange = pctChange * 0.75f;
if( statusPct * tempoChange < 0.0f )
{
if (statusPct * tempoChange < 0.0f) {
// only apply tempo change if it is in synch with the buffer status.
// In other words, if the buffer is high (over 0%), and is decreasing,
// ignore it. It'll just muck things up.
@ -323,8 +321,7 @@ void SndBuffer::UpdateTempoChangeSoundTouch()
if (cTempo < 0.965f || cTempo > 1.060f ||
pctChange < -0.38f || pctChange > 0.54f ||
statusPct < -0.42f || statusPct > 0.70f ||
eTempo < 0.89f || eTempo > 1.19f )
{
eTempo < 0.89f || eTempo > 1.19f) {
//printf("Emergency stretch: cTempo = %f eTempo = %f pctChange = %f statusPct = %f\n",cTempo,eTempo,pctChange,statusPct);
emergencyAdj = (pow(statusPct * statusWeight, 3.0f) * statusRange);
}
@ -357,15 +354,18 @@ void SndBuffer::UpdateTempoChangeSoundTouch()
// a nominal threshold. Keep this threshold check small, because it could
// cause some serious side effects otherwise. (enlarging the cTempo check above
// is usually better/safer)
if( newTempo < 0.970f || newTempo > 1.045f )
{
if (newTempo < 0.970f || newTempo > 1.045f) {
cTempo = (float)newcee;
if( newTempo < 0.10f ) newTempo = 0.10f;
else if( newTempo > 10.0f ) newTempo = 10.0f;
if (newTempo < 0.10f)
newTempo = 0.10f;
else if (newTempo > 10.0f)
newTempo = 10.0f;
if( cTempo < 0.15f ) cTempo = 0.15f;
else if( cTempo > 7.5f ) cTempo = 7.5f;
if (cTempo < 0.15f)
cTempo = 0.15f;
else if (cTempo > 7.5f)
cTempo = 7.5f;
pSoundTouch->setTempo(eTempo = (float)newTempo);
@ -377,20 +377,15 @@ void SndBuffer::UpdateTempoChangeSoundTouch()
(int)(newTempo * 100.0),
(int)(statusPct * 100.0)
);*/
}
else
{
} else {
// Nominal operation -- turn off stretching.
// note: eTempo 'slides' toward 1.0 for smoother audio and better
// protection against spikes.
if( cTempo != 1.0f )
{
if (cTempo != 1.0f) {
cTempo = 1.0f;
eTempo = (1.0f + eTempo) * 0.5f;
pSoundTouch->setTempo(eTempo);
}
else
{
} else {
if (eTempo != cTempo)
pSoundTouch->setTempo(eTempo = cTempo);
}
@ -403,20 +398,20 @@ void SndBuffer::UpdateTempoChangeAsyncMixing()
float statusPct = GetStatusPct();
lastPct = statusPct;
if( statusPct < -0.1f )
{
if (statusPct < -0.1f) {
TickInterval -= 4;
if( statusPct < -0.3f ) TickInterval = 64;
if( TickInterval < 64 ) TickInterval = 64;
if (statusPct < -0.3f)
TickInterval = 64;
if (TickInterval < 64)
TickInterval = 64;
//printf("-- %d, %f\n",TickInterval,statusPct);
}
else if( statusPct > 0.2f )
{
} else if (statusPct > 0.2f) {
TickInterval += 1;
if( TickInterval >= 7000 ) TickInterval = 7000;
if (TickInterval >= 7000)
TickInterval = 7000;
//printf("++ %d, %f\n",TickInterval,statusPct);
}
else TickInterval = 768;
} else
TickInterval = 768;
}
void SndBuffer::timeStretchUnderrun()
@ -426,7 +421,8 @@ void SndBuffer::timeStretchUnderrun()
cTempo -= (cTempo * 0.12f);
eTempo -= (eTempo * 0.30f);
if( eTempo < 0.1f ) eTempo = 0.1f;
if (eTempo < 0.1f)
eTempo = 0.1f;
// pSoundTouch->setTempo( eTempo );
//pSoundTouch->setTempoChange(-30); // temporary (until stretcher is called) slow down
}
@ -437,7 +433,8 @@ s32 SndBuffer::timeStretchOverrun()
// up audio playback.
cTempo += cTempo * 0.12f;
eTempo += eTempo * 0.40f;
if( eTempo > 7.5f ) eTempo = 7.5f;
if (eTempo > 7.5f)
eTempo = 7.5f;
//pSoundTouch->setTempo( eTempo );
//pSoundTouch->setTempoChange(30);// temporary (until stretcher is called) speed up
@ -482,8 +479,7 @@ void SndBuffer::timeStretchWrite()
int tempProgress;
while (tempProgress = pSoundTouch->receiveSamples((float *)sndTempBuffer, SndOutPacketSize),
tempProgress != 0 )
{
tempProgress != 0) {
// Hint: It's assumed that pSoundTouch will return chunks of 128 bytes (it always does as
// long as the SSE optimizations are enabled), which means we can do our own SSE opts here.
@ -496,7 +492,6 @@ void SndBuffer::timeStretchWrite()
#else
UpdateTempoChangeSoundTouch2();
#endif
}
void SndBuffer::soundtouchInit()
@ -525,7 +520,8 @@ void SndBuffer::soundtouchInit()
// reset timestretch management vars, and delay updates a bit:
void SndBuffer::soundtouchClearContents()
{
if( pSoundTouch == NULL ) return;
if (pSoundTouch == NULL)
return;
pSoundTouch->clear();
pSoundTouch->setTempo(1);

View File

@ -44,8 +44,7 @@ WavOutFile::WavOutFile(const char *fileName, int sampleRate, int bits, int chann
{
bytesWritten = 0;
fptr = fopen(fileName, "wb");
if (fptr == NULL)
{
if (fptr == NULL) {
string msg = "Error : Unable to open file \"";
msg += fileName;
msg += "\" for writing.";
@ -60,8 +59,7 @@ WavOutFile::WavOutFile(const char *fileName, int sampleRate, int bits, int chann
WavOutFile::~WavOutFile()
{
if (fptr)
{
if (fptr) {
finishHeader();
fclose(fptr);
}
@ -122,8 +120,7 @@ void WavOutFile::writeHeader()
// write the supplemented header in the beginning of the file
fseek(fptr, 0, SEEK_SET);
res = fwrite(&header, sizeof(header), 1, fptr);
if (res != 1)
{
if (res != 1) {
throw runtime_error("Error while writing to a wav file.");
}
@ -139,12 +136,12 @@ void WavOutFile::write(const short *buffer, int numElems)
// 16bit format & 16 bit samples
assert(header.format.bits_per_sample == 16);
if (numElems < 1) return; // nothing to do
if (numElems < 1)
return; // nothing to do
res = fwrite(buffer, 2, numElems, fptr);
if (res != numElems)
{
if (res != numElems) {
throw runtime_error("Error while writing to a wav file.");
}
bytesWritten += 2 * numElems;

View File

@ -107,7 +107,6 @@ public:
void write(const short *buffer, ///< Pointer to sample data buffer.
int numElems ///< How many array items are to be written to file.
);
};
#endif

View File

@ -38,20 +38,19 @@ namespace WaveDump
"WetVoiceMix",
"PreReverb",
"PostReverb",
"External"
};
"External"};
void Open()
{
if( !IsDevBuild ) return;
if( !WaveLog() ) return;
if (!IsDevBuild)
return;
if (!WaveLog())
return;
char wavfilename[256];
for( uint cidx=0; cidx<2; cidx++ )
{
for( int srcidx=0; srcidx<CoreSrc_Count; srcidx++ )
{
for (uint cidx = 0; cidx < 2; cidx++) {
for (int srcidx = 0; srcidx < CoreSrc_Count; srcidx++) {
safe_delete(m_CoreWav[cidx][srcidx]);
#ifdef __POSIX__
sprintf(wavfilename, "logs/spu2x-Core%d-%s.wav",
@ -61,12 +60,9 @@ namespace WaveDump
cidx, m_tbl_CoreOutputTypeNames[srcidx]);
#endif
try
{
try {
m_CoreWav[cidx][srcidx] = _new_WavOutFile(wavfilename);
}
catch( std::runtime_error& ex )
{
} catch (std::runtime_error &ex) {
printf("SPU2-X > %s.\n\tWave Log for this core source disabled.", ex.what());
m_CoreWav[cidx][srcidx] = NULL;
}
@ -76,11 +72,10 @@ namespace WaveDump
void Close()
{
if( !IsDevBuild ) return;
for( uint cidx=0; cidx<2; cidx++ )
{
for( int srcidx=0; srcidx<CoreSrc_Count; srcidx++ )
{
if (!IsDevBuild)
return;
for (uint cidx = 0; cidx < 2; cidx++) {
for (int srcidx = 0; srcidx < CoreSrc_Count; srcidx++) {
safe_delete(m_CoreWav[cidx][srcidx]);
}
}
@ -88,7 +83,8 @@ namespace WaveDump
void WriteCore(uint coreidx, CoreSourceType src, const StereoOut16 &sample)
{
if( !IsDevBuild ) return;
if (!IsDevBuild)
return;
if (m_CoreWav[coreidx][src] != NULL)
m_CoreWav[coreidx][src]->write((s16 *)&sample, 2);
}
@ -112,15 +108,12 @@ void RecordStart()
{
WavRecordEnabled = false;
try
{
try {
ScopedLock lock(WavRecordMutex);
safe_delete(m_wavrecord);
m_wavrecord = new WavOutFile("recording.wav", 48000, 16, 2);
WavRecordEnabled = true;
}
catch( std::runtime_error& )
{
} catch (std::runtime_error &) {
m_wavrecord = NULL; // not needed, but what the heck. :)
SysMessage("SPU2-X couldn't open file for recording: %s.\nRecording to wavfile disabled.", "recording.wav");
}
@ -136,6 +129,7 @@ void RecordStop()
void RecordWrite(const StereoOut16 &sample)
{
ScopedLock lock(WavRecordMutex);
if( m_wavrecord == NULL ) return;
if (m_wavrecord == NULL)
return;
m_wavrecord->write((s16 *)&sample, 2);
}

View File

@ -22,10 +22,8 @@
static LRESULT WINAPI AboutProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
switch (uMsg) {
case WM_INITDIALOG: {
wchar_t outstr[256];
if (IsDevBuild)
swprintf_s(outstr, L"Build %lld -- Compiled on " _T(__DATE__), SVN_REV);
@ -39,8 +37,7 @@ static LRESULT WINAPI AboutProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
return TRUE;
case WM_COMMAND:
switch( LOWORD(wParam) )
{
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hDlg, TRUE);
return TRUE;

View File

@ -117,11 +117,16 @@ bool CfgReadBool(const TCHAR *Section,const TCHAR* Name, bool Default)
return Default;
}
if(wcscmp(Data,L"1")==0) return true;
if(wcscmp(Data,L"Y")==0) return true;
if(wcscmp(Data,L"T")==0) return true;
if(wcscmp(Data,L"YES")==0) return true;
if(wcscmp(Data,L"TRUE")==0) return true;
if (wcscmp(Data, L"1") == 0)
return true;
if (wcscmp(Data, L"Y") == 0)
return true;
if (wcscmp(Data, L"T") == 0)
return true;
if (wcscmp(Data, L"YES") == 0)
return true;
if (wcscmp(Data, L"TRUE") == 0)
return true;
return false;
}
@ -171,8 +176,7 @@ void CfgReadStr(const TCHAR* Section, const TCHAR* Name, wxString& Data, const T
Data = workspace;
if(Data.empty())
{
if (Data.empty()) {
Data = Default;
CfgWriteStr(Section, Name, Default);
}
@ -187,6 +191,7 @@ bool CfgFindName( const TCHAR *Section, const TCHAR* Name)
GetPrivateProfileString(Section, Name, L"", Data, 24, CfgFile);
Data[23] = 0;
if(wcslen(Data)==0) return false;
if (wcslen(Data) == 0)
return false;
return true;
}

View File

@ -90,7 +90,8 @@ void ReadSettings()
EffectsDisabled = CfgReadBool(L"MIXING", L"Disable_Effects", false);
postprocess_filter_dealias = CfgReadBool(L"MIXING", L"DealiasFilter", false);
FinalVolume = ((float)CfgReadInt(L"MIXING", L"FinalVolume", 100)) / 100;
if ( FinalVolume > 1.0f) FinalVolume = 1.0f;
if (FinalVolume > 1.0f)
FinalVolume = 1.0f;
AdvancedVolumeControl = CfgReadBool(L"MIXING", L"AdvancedVolumeControl", false);
VolumeAdjustCdb = CfgReadFloat(L"MIXING", L"VolumeAdjustC(dB)", 0);
@ -154,8 +155,7 @@ void ReadSettings()
Clampify(SndOutLatencyMS, LATENCY_MIN, LATENCY_MAX);
if( mods[OutputModule] == NULL )
{
if (mods[OutputModule] == NULL) {
// Unsupported or legacy module.
fwprintf(stderr, L"* SPU2-X: Unknown output module '%s' specified in configuration file.\n", omodid);
fprintf(stderr, "* SPU2-X: Defaulting to DirectSound (%S).\n", DSoundOut->GetIdent());
@ -190,7 +190,8 @@ void WriteSettings()
CfgWriteInt(L"OUTPUT", L"DplDecodingLevel", dplLevel);
CfgWriteInt(L"DEBUG", L"DelayCycles", delayCycles);
if( Config_WaveOut.Device.empty() ) Config_WaveOut.Device = L"default";
if (Config_WaveOut.Device.empty())
Config_WaveOut.Device = L"default";
CfgWriteStr(L"WAVEOUT", L"Device", Config_WaveOut.Device);
CfgWriteInt(L"WAVEOUT", L"Buffer_Count", Config_WaveOut.NumBuffers);
@ -202,7 +203,6 @@ void WriteSettings()
DSoundOut->WriteSettings();
SoundtouchCfg::WriteSettings();
DebugConfig::WriteSettings();
}
BOOL CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -210,13 +210,11 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
int wmId, wmEvent;
wchar_t temp[384] = {0};
switch(uMsg)
{
switch (uMsg) {
case WM_PAINT:
return FALSE;
case WM_INITDIALOG:
{
case WM_INITDIALOG: {
SendDialogMsg(hWnd, IDC_INTERPOLATE, CB_RESETCONTENT, 0, 0);
SendDialogMsg(hWnd, IDC_INTERPOLATE, CB_ADDSTRING, 0, (LPARAM)L"0 - Nearest (fastest/bad quality)");
SendDialogMsg(hWnd, IDC_INTERPOLATE, CB_ADDSTRING, 0, (LPARAM)L"1 - Linear (simple/okay sound)");
@ -241,8 +239,7 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
SendDialogMsg(hWnd, IDC_OUTPUT, CB_RESETCONTENT, 0, 0);
int modidx = 0;
while( mods[modidx] != NULL )
{
while (mods[modidx] != NULL) {
swprintf_s(temp, 72, L"%d - %s", modidx, mods[modidx]->GetLongName());
SendDialogMsg(hWnd, IDC_OUTPUT, CB_ADDSTRING, 0, (LPARAM)temp);
++modidx;
@ -272,17 +269,14 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
SET_CHECK(IDC_DEALIASFILTER, postprocess_filter_dealias);
SET_CHECK(IDC_DEBUG_ENABLE, DebugEnabled);
SET_CHECK(IDC_DSP_ENABLE, dspPluginEnabled);
}
break;
} break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDOK:
{
switch (wmId) {
case IDOK: {
double res = ((int)SendDialogMsg(hWnd, IDC_LATENCY_SLIDER, TBM_GETPOS, 0, 0)) / 128.0;
SndOutLatencyMS = (int)pow(res, 3.0);
Clampify(SndOutLatencyMS, LATENCY_MIN, LATENCY_MAX);
@ -294,36 +288,30 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
WriteSettings();
EndDialog(hWnd, 0);
}
break;
} break;
case IDCANCEL:
EndDialog(hWnd, 0);
break;
case IDC_OUTCONF:
{
case IDC_OUTCONF: {
const int module = (int)SendMessage(GetDlgItem(hWnd, IDC_OUTPUT), CB_GETCURSEL, 0, 0);
if( mods[module] == NULL ) break;
mods[module]->Configure((uptr)hWnd);
}
if (mods[module] == NULL)
break;
mods[module]->Configure((uptr)hWnd);
} break;
case IDC_OPEN_CONFIG_DEBUG:
{
case IDC_OPEN_CONFIG_DEBUG: {
// Quick Hack -- DebugEnabled is re-loaded with the DebugConfig's API,
// so we need to override it here:
bool dbgtmp = DebugEnabled;
DebugConfig::OpenDialog();
DebugEnabled = dbgtmp;
}
break;
} break;
case IDC_SYNCHMODE:
{
if(wmEvent == CBN_SELCHANGE)
{
case IDC_SYNCHMODE: {
if (wmEvent == CBN_SELCHANGE) {
int sMode = (int)SendDialogMsg(hWnd, IDC_SYNCHMODE, CB_GETCURSEL, 0, 0);
double minlat = (sMode == 0) ? LATENCY_MIN_TS : LATENCY_MIN;
int minexp = (int)(pow(minlat + 1, 1.0 / 3.0) * 128.0);
@ -338,8 +326,7 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
bool soundtouch = sMode == 0;
EnableWindow(GetDlgItem(hWnd, IDC_OPEN_CONFIG_SOUNDTOUCH), soundtouch);
}
}
break;
} break;
case IDC_OPEN_CONFIG_SOUNDTOUCH:
@ -359,8 +346,7 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
}
break;
case WM_HSCROLL:
{
case WM_HSCROLL: {
wmEvent = LOWORD(wParam);
HWND hwndDlg = (HWND)lParam;
@ -369,8 +355,7 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
int curpos = HIWORD(wParam);
switch( wmEvent )
{
switch (wmEvent) {
//case TB_ENDTRACK:
//case TB_THUMBPOSITION:
case TB_LINEUP:
@ -382,21 +367,18 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
case TB_THUMBTRACK:
Clampify(curpos,
(int)SendMessage(hwndDlg, TBM_GETRANGEMIN, 0, 0),
(int)SendMessage(hwndDlg,TBM_GETRANGEMAX,0,0)
);
(int)SendMessage(hwndDlg, TBM_GETRANGEMAX, 0, 0));
SendMessage((HWND)lParam, TBM_SETPOS, TRUE, curpos);
if( hwndDlg == GetDlgItem( hWnd, IDC_LATENCY_SLIDER ) )
{
if (hwndDlg == GetDlgItem(hWnd, IDC_LATENCY_SLIDER)) {
double res = pow(curpos / 128.0, 3.0);
curpos = (int)res;
swprintf_s(temp, L"%d ms (avg)", curpos);
SetDlgItemText(hWnd, IDC_LATENCY_LABEL, temp);
}
if( hwndDlg == GetDlgItem( hWnd, IDC_VOLUME_SLIDER ) )
{
if (hwndDlg == GetDlgItem(hWnd, IDC_VOLUME_SLIDER)) {
swprintf_s(temp, L"%d%%", curpos);
SetDlgItemText(hWnd, IDC_VOLUME_LABEL, temp);
}
@ -405,8 +387,7 @@ BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
default:
return FALSE;
}
}
break;
} break;
default:
return FALSE;
@ -419,8 +400,7 @@ void configure()
INT_PTR ret;
ReadSettings();
ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(), (DLGPROC)ConfigProc, 1);
if(ret==-1)
{
if (ret == -1) {
MessageBox(GetActiveWindow(), L"Error Opening the config dialog.", L"OMG ERROR!", MB_OK | MB_SETFOREGROUND);
return;
}

View File

@ -79,7 +79,8 @@ FILE* OpenDump( const wxString& logfile )
return wxFopen(Path::Combine(DumpsFolder, logfile), L"w");
}
namespace DebugConfig {
namespace DebugConfig
{
static const wxChar *Section = L"DEBUG";
@ -115,8 +116,7 @@ void ReadSettings()
CfgReadStr(Section, L"Mem_Dump_Filename", MemDumpFileName, L"SPU2mem.dat");
CfgReadStr(Section, L"Reg_Dump_Filename", RegDumpFileName, L"SPU2regs.dat");
if( !LogLocationSetByPcsx2 )
{
if (!LogLocationSetByPcsx2) {
LogsFolder = CfgLogsFolder;
DumpsFolder = CfgLogsFolder;
}
@ -187,13 +187,11 @@ static BOOL CALLBACK DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
int wmId;
//wchar_t temp[384]={0};
switch(uMsg)
{
switch (uMsg) {
case WM_PAINT:
return FALSE;
case WM_INITDIALOG:
{
case WM_INITDIALOG: {
EnableControls(hWnd);
// Debugging / Logging Flags:
@ -214,14 +212,12 @@ static BOOL CALLBACK DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
SET_CHECK(IDC_DEBUG_VISUAL, _visual_debug_enabled);
ShowWindow(GetDlgItem(hWnd, IDC_MSG_PUBLIC_BUILD), !IsDevBuild);
}
break;
} break;
case WM_COMMAND:
wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
switch (wmId) {
case IDOK:
WriteSettings();
EndDialog(hWnd, 0);
@ -259,18 +255,15 @@ static BOOL CALLBACK DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
return FALSE;
}
return TRUE;
}
void OpenDialog()
{
INT_PTR ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CONFIG_DEBUG), GetActiveWindow(), (DLGPROC)DialogProc, 1);
if(ret == -1)
{
if (ret == -1) {
MessageBox(GetActiveWindow(), L"Error Opening the debug configuration dialog.", L"OMG ERROR!", MB_OK | MB_SETFOREGROUND);
return;
}
ReadSettings();
}
}

View File

@ -69,13 +69,11 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM
int wmId;
//wchar_t temp[384]={0};
switch(uMsg)
{
switch (uMsg) {
case WM_PAINT:
return FALSE;
case WM_INITDIALOG:
{
case WM_INITDIALOG: {
INIT_SLIDER(IDC_SEQLEN_SLIDER, SequenceLen_Min, SequenceLen_Max, 20, 5, 1);
INIT_SLIDER(IDC_SEEKWIN_SLIDER, SeekWindow_Min, SeekWindow_Max, 5, 2, 1);
INIT_SLIDER(IDC_OVERLAP_SLIDER, Overlap_Min, Overlap_Max, 3, 2, 1);
@ -88,8 +86,7 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM
case WM_COMMAND:
wmId = LOWORD(wParam);
// Parse the menu selections:
if( wmId == IDOK )
{
if (wmId == IDOK) {
SequenceLenMS = (int)SendDialogMsg(hWnd, IDC_SEQLEN_SLIDER, TBM_GETPOS, 0, 0);
SeekWindowMS = (int)SendDialogMsg(hWnd, IDC_SEEKWIN_SLIDER, TBM_GETPOS, 0, 0);
OverlapMS = (int)SendDialogMsg(hWnd, IDC_OVERLAP_SLIDER, TBM_GETPOS, 0, 0);
@ -97,9 +94,7 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM
ClampValues();
WriteSettings();
EndDialog(hWnd, 0);
}
else if( wmId == IDC_RESET_DEFAULTS )
{
} else if (wmId == IDC_RESET_DEFAULTS) {
SequenceLenMS = 30;
SeekWindowMS = 20;
OverlapMS = 10;
@ -109,9 +104,7 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM
SendDialogMsg(hWnd, IDC_OVERLAP_SLIDER, TBM_SETPOS, TRUE, OverlapMS);
AssignSliderValue((HWND)lParam, hWnd, SequenceLenMS);
}
else if( wmId == IDCANCEL )
{
} else if (wmId == IDCANCEL) {
EndDialog(hWnd, 0);
}
break;
@ -130,8 +123,7 @@ void SoundtouchCfg::OpenDialog( HWND hWnd )
{
INT_PTR ret;
ret = DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG_SOUNDTOUCH), hWnd, (DLGPROC)DialogProc);
if(ret==-1)
{
if (ret == -1) {
MessageBox(GetActiveWindow(), L"Error Opening the Soundtouch advanced dialog.", L"OMG ERROR!", MB_OK | MB_SETFOREGROUND);
return;
}

View File

@ -75,4 +75,3 @@ struct ds_device_data
GUID guid;
bool hasGuid;
};

View File

@ -50,15 +50,15 @@ HFONT hf = NULL;
int lCount = 0;
void UpdateDebugDialog()
{
if(!debugDialogOpen) return;
if (!debugDialogOpen)
return;
lCount++;
if (lCount >= (SampleRate / 100)) // Increase to SampleRate/200 for smooth display.
{
HDC hdc = GetDC(hDebugDialog);
if(!hf)
{
if (!hf) {
hf = CreateFont(12, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Lucida Console");
}
@ -67,13 +67,11 @@ void UpdateDebugDialog()
SelectObject(hdc, GetStockObject(DC_BRUSH));
SelectObject(hdc, GetStockObject(DC_PEN));
for(int c=0;c<2;c++)
{
for (int c = 0; c < 2; c++) {
V_Core &cx(Cores[c]);
V_CoreDebug &cd(DebugCores[c]);
for(int v=0;v<24;v++)
{
for (int v = 0; v < 24; v++) {
int cc = c * 2 + (v / 12);
int vv = v % 12;
int IX = 8 + 128 * cc;
@ -82,8 +80,7 @@ void UpdateDebugDialog()
V_VoiceDebug &vcd(cd.Voices[v]);
SetDCBrushColor(hdc, RGB(0, 0, 0));
if((vc.ADSR.Phase>0)&&(vc.ADSR.Phase<6))
{
if ((vc.ADSR.Phase > 0) && (vc.ADSR.Phase < 6)) {
SetDCBrushColor(hdc, RGB(0, 0, 128));
}
/*
@ -126,24 +123,19 @@ void UpdateDebugDialog()
FillRectangle(hdc, IX + 70, IY + 42 - peak, 4, peak);
if(vc.ADSR.Value>0)
{
if (vc.ADSR.Value > 0) {
if (vc.SBuffer)
for(int i=0;i<28;i++)
{
for (int i = 0; i < 28; i++) {
int val = ((int)vc.SBuffer[i] * 20) / 32768;
int y = 0;
if(val>0)
{
if (val > 0) {
y = val;
}
else
} else
val = -val;
if(val!=0)
{
if (val != 0) {
FillRectangle(hdc, IX + 90 + i, IY + 24 - y, 1, val);
}
}
@ -204,20 +196,16 @@ void UpdateDebugDialog()
SetTextColor(hdc, RGB(255, 255, 255));
SetDCBrushColor(hdc, RGB(255, 0, 0));
if(cx.FxEnable)
{
if (cx.FxEnable) {
FillRectangle(hdc, JX + 40, JY + 4, 10, 10);
}
if(cx.IRQEnable)
{
if (cx.IRQEnable) {
FillRectangle(hdc, JX + 40, JY + 18, 10, 10);
}
if(cx.AutoDMACtrl != 0)
{
if (cx.AutoDMACtrl != 0) {
FillRectangle(hdc, JX + 40, JY + 32, 10, 10);
for(int j=0;j<64;j++)
{
for (int j = 0; j < 64; j++) {
int i = j * 256 / 64;
int val = (cd.admaWaveformL[i] * 26) / 32768;
int y = 0;
@ -227,14 +215,12 @@ void UpdateDebugDialog()
else
val = -val;
if(val!=0)
{
if (val != 0) {
FillRectangle(hdc, JX + 60 + j, JY + 30 - y, 1, val);
}
}
for(int j=0;j<64;j++)
{
for (int j = 0; j < 64; j++) {
int i = j * 256 / 64;
int val = (cd.admaWaveformR[i] * 26) / 32768;
int y = 0;
@ -244,8 +230,7 @@ void UpdateDebugDialog()
else
val = -val;
if(val!=0)
{
if (val != 0) {
FillRectangle(hdc, JX + 136 + j, JY + 30 - y, 1, val);
}
}
@ -265,8 +250,7 @@ void UpdateDebugDialog()
}
MSG msg;
while(PeekMessage(&msg,hDebugDialog,0,0,PM_REMOVE))
{
while (PeekMessage(&msg, hDebugDialog, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

View File

@ -73,8 +73,7 @@ private:
{
static const int BufferSizeBytes = BufferSize * sizeof(T);
while( dsound_running )
{
while (dsound_running) {
u32 rv = WaitForMultipleObjects(m_NumBuffers, buffer_events, FALSE, 200);
T *p1, *oldp1;
@ -83,8 +82,7 @@ private:
u32 poffset = BufferSizeBytes * rv;
if( FAILED(buffer->Lock(poffset,BufferSizeBytes,(LPVOID*)&p1,&s1,&p2,&s2,0) ) )
{
if (FAILED(buffer->Lock(poffset, BufferSizeBytes, (LPVOID *)&p1, &s1, &p2, &s2, 0))) {
assert(0);
fputs("* SPU2-X: Directsound Warning > Buffer lock failure. You may need to increase\n\tyour configured DSound buffer count.\n", stderr);
continue;
@ -112,17 +110,14 @@ public:
//
GUID cGuid;
try
{
try {
if (m_Device.empty())
throw std::runtime_error("screw it");
if ((FAILED(GUIDFromString(m_Device, &cGuid))) ||
FAILED(DirectSoundCreate8(&cGuid, &dsound, NULL)))
throw std::runtime_error("try again?");
}
catch( std::runtime_error& )
{
} catch (std::runtime_error &) {
// if the GUID failed, just open up the default dsound driver:
if (FAILED(DirectSoundCreate8(NULL, &dsound, NULL)))
throw std::runtime_error("DirectSound failed to initialize!");
@ -167,10 +162,8 @@ public:
desc.dwFlags |= m_UseHardware ? DSBCAPS_LOCHARDWARE : DSBCAPS_LOCSOFTWARE;
desc.dwFlags |= m_DisableGlobalFocus ? DSBCAPS_STICKYFOCUS : DSBCAPS_GLOBALFOCUS;
if( FAILED(dsound->CreateSoundBuffer(&desc, &buffer_, 0) ) )
{
if( m_UseHardware )
{
if (FAILED(dsound->CreateSoundBuffer(&desc, &buffer_, 0))) {
if (m_UseHardware) {
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_LOCSOFTWARE;
desc.dwFlags |= m_DisableGlobalFocus ? DSBCAPS_STICKYFOCUS : DSBCAPS_GLOBALFOCUS;
@ -188,8 +181,7 @@ public:
DSBPOSITIONNOTIFY not[MAX_BUFFER_COUNT];
for(uint i=0;i<m_NumBuffers;i++)
{
for (uint i = 0; i < m_NumBuffers; i++) {
buffer_events[i] = CreateEvent(NULL, FALSE, FALSE, NULL);
not[i].dwOffset = (wfx.nBlockAlign + BufferSizeBytes * (i + 1)) % desc.dwBufferBytes;
not[i].hEventNotify = buffer_events[i];
@ -231,12 +223,10 @@ public:
//
// Clean up
//
if( buffer != NULL )
{
if (buffer != NULL) {
buffer->Stop();
for(u32 i=0;i<m_NumBuffers;i++)
{
for (u32 i = 0; i < m_NumBuffers; i++) {
if (buffer_events[i] != NULL)
CloseHandle(buffer_events[i]);
buffer_events[i] = NULL;
@ -251,23 +241,20 @@ public:
}
private:
bool _DSEnumCallback(LPGUID lpGuid, LPCTSTR lpcstrDescription, LPCTSTR lpcstrModule, LPVOID lpContext)
{
m_devices[ndevs].name = lpcstrDescription;
if(lpGuid)
{
if (lpGuid) {
m_devices[ndevs].guid = *lpGuid;
m_devices[ndevs].hasGuid = true;
}
else
{
} else {
m_devices[ndevs].hasGuid = false;
}
ndevs++;
if(ndevs<32) return TRUE;
if (ndevs < 32)
return TRUE;
return FALSE;
}
@ -276,10 +263,8 @@ private:
int wmId, wmEvent;
int tSel = 0;
switch(uMsg)
{
case WM_INITDIALOG:
{
switch (uMsg) {
case WM_INITDIALOG: {
wchar_t temp[128];
haveGuid = !FAILED(GUIDFromString(m_Device, &DevGuid));
@ -289,8 +274,7 @@ private:
DirectSoundEnumerate(DSEnumCallback, NULL);
tSel = -1;
for(int i=0;i<ndevs;i++)
{
for (int i = 0; i < ndevs; i++) {
SendMessage(GetDlgItem(hWnd, IDC_DS_DEVICE), CB_ADDSTRING, 0, (LPARAM)m_devices[i].name.wc_str());
if (haveGuid && IsEqualGUID(m_devices[i].guid, DevGuid) || tSel < 0 && !m_devices[i].hasGuid)
tSel = i;
@ -306,28 +290,21 @@ private:
SET_CHECK(IDC_GLOBALFOCUS_DISABLE, m_DisableGlobalFocus);
SET_CHECK(IDC_USE_HARDWARE, m_UseHardware);
}
break;
} break;
case WM_COMMAND:
{
case WM_COMMAND: {
wchar_t temp[128];
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDOK:
{
switch (wmId) {
case IDOK: {
int i = (int)SendMessage(GetDlgItem(hWnd, IDC_DS_DEVICE), CB_GETCURSEL, 0, 0);
if(!m_devices[i].hasGuid)
{
if (!m_devices[i].hasGuid) {
m_Device[0] = 0; // clear device name to ""
}
else
{
} else {
swprintf_s(temp, L"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
m_devices[i].guid.Data1,
m_devices[i].guid.Data2,
@ -339,19 +316,19 @@ private:
m_devices[i].guid.Data4[4],
m_devices[i].guid.Data4[5],
m_devices[i].guid.Data4[6],
m_devices[i].guid.Data4[7]
);
m_devices[i].guid.Data4[7]);
m_Device = temp;
}
m_NumBuffers = (int)SendMessage(GetDlgItem(hWnd, IDC_BUFFERS_SLIDER), TBM_GETPOS, 0, 0);
if( m_NumBuffers < 2 ) m_NumBuffers = 2;
if( m_NumBuffers > MAX_BUFFER_COUNT ) m_NumBuffers = MAX_BUFFER_COUNT;
if (m_NumBuffers < 2)
m_NumBuffers = 2;
if (m_NumBuffers > MAX_BUFFER_COUNT)
m_NumBuffers = MAX_BUFFER_COUNT;
EndDialog(hWnd, 0);
}
break;
} break;
case IDCANCEL:
EndDialog(hWnd, 0);
@ -363,15 +340,12 @@ private:
default:
return FALSE;
}
}
break;
} break;
case WM_HSCROLL:
{
case WM_HSCROLL: {
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch(wmId)
{
switch (wmId) {
//case TB_ENDTRACK:
//case TB_THUMBPOSITION:
case TB_LINEUP:
@ -379,11 +353,12 @@ private:
case TB_PAGEUP:
case TB_PAGEDOWN:
wmEvent = (int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0);
case TB_THUMBTRACK:
{
case TB_THUMBTRACK: {
wchar_t temp[128];
if( wmEvent < 2 ) wmEvent = 2;
if( wmEvent > MAX_BUFFER_COUNT ) wmEvent = MAX_BUFFER_COUNT;
if (wmEvent < 2)
wmEvent = 2;
if (wmEvent > MAX_BUFFER_COUNT)
wmEvent = MAX_BUFFER_COUNT;
SendMessage((HWND)lParam, TBM_SETPOS, TRUE, wmEvent);
swprintf_s(temp, L"%d (%d ms latency)", wmEvent, 1000 / (96000 / (wmEvent * BufferSize)));
SetWindowText(GetDlgItem(hWnd, IDC_LATENCY_LABEL), temp);
@ -392,8 +367,7 @@ private:
default:
return FALSE;
}
}
break;
} break;
default:
return FALSE;
@ -409,8 +383,7 @@ public:
{
INT_PTR ret;
ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DSOUND), (HWND)parent, (DLGPROC)ConfigProc, 1);
if(ret==-1)
{
if (ret == -1) {
MessageBox((HWND)parent, L"Error Opening the config dialog.", L"OMG ERROR!", MB_OK | MB_SETFOREGROUND);
return;
}

View File

@ -51,10 +51,10 @@ namespace Exception
}
virtual ~XAudio2Error() throw() {}
XAudio2Error(const HRESULT result, const std::string& msg) :
runtime_error(msg),
ErrorCode(result),
m_Message()
XAudio2Error(const HRESULT result, const std::string &msg)
: runtime_error(msg)
, ErrorCode(result)
, m_Message()
{
char omg[1024];
sprintf_s(omg, "%s (code 0x%x)\n\n%s", what(), ErrorCode, SomeKindaErrorString(ErrorCode));
@ -96,11 +96,11 @@ private:
{
}
BaseStreamingVoice(uint numChannels) :
m_nBuffers(Config_XAudio2.NumBuffers),
m_nChannels(numChannels),
m_BufferSize(SndOutPacketSize * m_nChannels * PacketsPerBuffer),
m_BufferSizeBytes(m_BufferSize * sizeof(s16))
BaseStreamingVoice(uint numChannels)
: m_nBuffers(Config_XAudio2.NumBuffers)
, m_nChannels(numChannels)
, m_BufferSize(SndOutPacketSize * m_nChannels * PacketsPerBuffer)
, m_BufferSizeBytes(m_BufferSize * sizeof(s16))
{
}
@ -156,21 +156,28 @@ private:
LeaveCriticalSection(&cs);
}
STDMETHOD_(void, OnVoiceProcessingPassStart) () {}
STDMETHOD_(void, OnVoiceProcessingPassStart) (UINT32) {}
STDMETHOD_(void, OnVoiceProcessingPassEnd) () {}
STDMETHOD_(void, OnStreamEnd) () {}
STDMETHOD_(void, OnBufferStart) (void*) {}
STDMETHOD_(void, OnLoopEnd) (void*) {}
STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) {}
STDMETHOD_(void, OnVoiceProcessingPassStart)
() {}
STDMETHOD_(void, OnVoiceProcessingPassStart)
(UINT32) {}
STDMETHOD_(void, OnVoiceProcessingPassEnd)
() {}
STDMETHOD_(void, OnStreamEnd)
() {}
STDMETHOD_(void, OnBufferStart)
(void *) {}
STDMETHOD_(void, OnLoopEnd)
(void *) {}
STDMETHOD_(void, OnVoiceError)
(THIS_ void *pBufferContext, HRESULT Error) {}
};
template <typename T>
class StreamingVoice : public BaseStreamingVoice
{
public:
StreamingVoice(IXAudio2* pXAudio2) :
BaseStreamingVoice(sizeof(T) / sizeof(s16))
StreamingVoice(IXAudio2 *pXAudio2)
: BaseStreamingVoice(sizeof(T) / sizeof(s16))
{
}
@ -191,19 +198,34 @@ private:
{
int chanMask = 0;
switch (m_nChannels) {
case 1: chanMask |= SPEAKER_FRONT_CENTER; break;
case 2: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
case 3: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY; break;
case 4: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
case 5: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
case 6: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY; break;
case 8: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT | SPEAKER_LOW_FREQUENCY; break;
case 1:
chanMask |= SPEAKER_FRONT_CENTER;
break;
case 2:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
break;
case 3:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY;
break;
case 4:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
break;
case 5:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
break;
case 6:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY;
break;
case 8:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT | SPEAKER_LOW_FREQUENCY;
break;
}
_init(pXAudio2, chanMask);
}
protected:
STDMETHOD_(void, OnBufferEnd) (void* context)
STDMETHOD_(void, OnBufferEnd)
(void *context)
{
EnterCriticalSection(&cs);
@ -226,7 +248,6 @@ private:
pSourceVoice->SubmitSourceBuffer(&buf);
LeaveCriticalSection(&cs);
}
};
HMODULE xAudio2DLL;
@ -236,7 +257,6 @@ private:
BaseStreamingVoice *voiceContext;
public:
s32 Init()
{
HRESULT hr;
@ -267,11 +287,20 @@ public:
int speakers;
switch (numSpeakers) // speakers = (numSpeakers + 1) *2; ?
{
case 0: speakers = 2; break; // Stereo
case 1: speakers = 4; break; // Quadrafonic
case 2: speakers = 6; break; // Surround 5.1
case 3: speakers = 8; break; // Surround 7.1
default: speakers = 2;
case 0:
speakers = 2;
break; // Stereo
case 1:
speakers = 4;
break; // Quadrafonic
case 2:
speakers = 6;
break; // Surround 5.1
case 3:
speakers = 8;
break; // Surround 7.1
default:
speakers = 2;
}
//
@ -371,7 +400,8 @@ public:
int GetEmptySampleCount()
{
if (voiceContext == NULL) return 0;
if (voiceContext == NULL)
return 0;
return voiceContext->GetEmptySampleCount();
}

View File

@ -29,8 +29,7 @@ namespace Exception
protected:
static const char *SomeKindaErrorString(HRESULT hr)
{
switch( hr )
{
switch (hr) {
case XAUDIO2_E_INVALID_CALL:
return "Invalid call for the XA2 object state.";
@ -50,10 +49,10 @@ namespace Exception
}
virtual ~XAudio2_27Error() throw() {}
XAudio2_27Error( const HRESULT result, const std::string& msg ) :
runtime_error( msg ),
ErrorCode( result ),
m_Message()
XAudio2_27Error(const HRESULT result, const std::string &msg)
: runtime_error(msg)
, ErrorCode(result)
, m_Message()
{
char omg[1024];
sprintf_s(omg, "%s (code 0x%x)\n\n%s", what(), ErrorCode, SomeKindaErrorString(ErrorCode));
@ -95,11 +94,11 @@ private:
{
}
BaseStreamingVoice( uint numChannels ) :
m_nBuffers( Config_XAudio2.NumBuffers ),
m_nChannels( numChannels ),
m_BufferSize( SndOutPacketSize * m_nChannels * PacketsPerBuffer ),
m_BufferSizeBytes( m_BufferSize * sizeof(s16) )
BaseStreamingVoice(uint numChannels)
: m_nBuffers(Config_XAudio2.NumBuffers)
, m_nChannels(numChannels)
, m_BufferSize(SndOutPacketSize * m_nChannels * PacketsPerBuffer)
, m_BufferSizeBytes(m_BufferSize * sizeof(s16))
{
}
@ -129,8 +128,7 @@ private:
//
HRESULT hr;
if (FAILED(hr = pXAudio2->CreateSourceVoice(&pSourceVoice, (WAVEFORMATEX *)&wfx,
XAUDIO2_VOICE_NOSRC, 1.0f, this ) ) )
{
XAUDIO2_VOICE_NOSRC, 1.0f, this))) {
throw Exception::XAudio2_27Error(hr, "XAudio2 CreateSourceVoice failure.");
}
@ -145,8 +143,7 @@ private:
// Start some buffers.
for( uint i=0; i<m_nBuffers; i++ )
{
for (uint i = 0; i < m_nBuffers; i++) {
XAUDIO2_BUFFER buf = {0};
buf.AudioBytes = m_BufferSizeBytes;
buf.pContext = &qbuffer[i * m_BufferSize];
@ -157,21 +154,28 @@ private:
LeaveCriticalSection(&cs);
}
STDMETHOD_(void, OnVoiceProcessingPassStart) () {}
STDMETHOD_(void, OnVoiceProcessingPassStart) (UINT32) { };
STDMETHOD_(void, OnVoiceProcessingPassEnd) () {}
STDMETHOD_(void, OnStreamEnd) () {}
STDMETHOD_(void, OnBufferStart) ( void* ) {}
STDMETHOD_(void, OnLoopEnd) ( void* ) {}
STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) { };
STDMETHOD_(void, OnVoiceProcessingPassStart)
() {}
STDMETHOD_(void, OnVoiceProcessingPassStart)
(UINT32){};
STDMETHOD_(void, OnVoiceProcessingPassEnd)
() {}
STDMETHOD_(void, OnStreamEnd)
() {}
STDMETHOD_(void, OnBufferStart)
(void *) {}
STDMETHOD_(void, OnLoopEnd)
(void *) {}
STDMETHOD_(void, OnVoiceError)
(THIS_ void *pBufferContext, HRESULT Error){};
};
template <typename T>
class StreamingVoice : public BaseStreamingVoice
{
public:
StreamingVoice( IXAudio2* pXAudio2 ) :
BaseStreamingVoice( sizeof(T) / sizeof( s16 ) )
StreamingVoice(IXAudio2 *pXAudio2)
: BaseStreamingVoice(sizeof(T) / sizeof(s16))
{
}
@ -191,27 +195,40 @@ private:
void Init(IXAudio2 *pXAudio2)
{
int chanMask = 0;
switch(m_nChannels)
{
case 1: chanMask |= SPEAKER_FRONT_CENTER; break;
case 2: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
case 3: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY; break;
case 4: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
case 5: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
case 6: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY; break;
case 8: chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT | SPEAKER_LOW_FREQUENCY; break;
switch (m_nChannels) {
case 1:
chanMask |= SPEAKER_FRONT_CENTER;
break;
case 2:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
break;
case 3:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY;
break;
case 4:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
break;
case 5:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
break;
case 6:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY;
break;
case 8:
chanMask |= SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT | SPEAKER_LOW_FREQUENCY;
break;
}
_init(pXAudio2, chanMask);
}
protected:
STDMETHOD_(void, OnBufferEnd) ( void* context )
STDMETHOD_(void, OnBufferEnd)
(void *context)
{
EnterCriticalSection(&cs);
// All of these checks are necessary because XAudio2 is wonky shizat.
if( pSourceVoice == NULL || context == NULL )
{
if (pSourceVoice == NULL || context == NULL) {
LeaveCriticalSection(&cs);
return;
}
@ -229,7 +246,6 @@ private:
pSourceVoice->SubmitSourceBuffer(&buf);
LeaveCriticalSection(&cs);
}
};
HMODULE xAudio2DLL;
@ -238,7 +254,6 @@ private:
BaseStreamingVoice *voiceContext;
public:
s32 Init()
{
HRESULT hr;
@ -264,14 +279,12 @@ public:
if (IsDebugBuild)
flags |= XAUDIO2_DEBUG_ENGINE;
try
{
try {
if (FAILED(hr = XAudio2Create(&pXAudio2, flags)))
throw Exception::XAudio2_27Error(hr,
"Failed to init XAudio2 engine. XA2 may not be available on your system.\n"
"Ensure that you have the latest DirectX runtimes installed, or use \n"
"DirectX / WaveOut drivers instead. Error Details:"
);
"DirectX / WaveOut drivers instead. Error Details:");
XAUDIO2_DEVICE_DETAILS deviceDetails;
pXAudio2->GetDeviceDetails(0, &deviceDetails);
@ -283,11 +296,20 @@ public:
int speakers;
switch (numSpeakers) // speakers = (numSpeakers + 1) *2; ?
{
case 0: speakers = 2; break; // Stereo
case 1: speakers = 4; break; // Quadrafonic
case 2: speakers = 6; break; // Surround 5.1
case 3: speakers = 8; break; // Surround 7.1
default: speakers = 2;
case 0:
speakers = 2;
break; // Stereo
case 1:
speakers = 4;
break; // Quadrafonic
case 2:
speakers = 6;
break; // Surround 5.1
case 3:
speakers = 8;
break; // Surround 7.1
default:
speakers = 2;
}
// Any windows driver should support stereo at the software level, I should think!
@ -296,15 +318,13 @@ public:
//
// Create a mastering voice
//
if ( FAILED(hr = pXAudio2->CreateMasteringVoice( &pMasteringVoice, speakers, SampleRate ) ) )
{
if (FAILED(hr = pXAudio2->CreateMasteringVoice(&pMasteringVoice, speakers, SampleRate))) {
SysMessage("Failed creating mastering voice: %#X\n", hr);
CoUninitialize();
return -1;
}
switch( speakers )
{
switch (speakers) {
case 2:
ConLog("* SPU2 > Using normal 2 speaker stereo output.\n");
voiceContext = new StreamingVoice<StereoOut16>(pXAudio2);
@ -327,8 +347,7 @@ public:
case 6:
case 7:
switch(dplLevel)
{
switch (dplLevel) {
case 0:
ConLog("* SPU2 > 5.1 speaker expansion enabled.\n");
voiceContext = new StreamingVoice<Stereo51Out16>(pXAudio2); //"normal" stereo upmix
@ -351,9 +370,7 @@ public:
}
voiceContext->Init(pXAudio2);
}
catch( Exception::XAudio2_27Error& ex )
{
} catch (Exception::XAudio2_27Error &ex) {
SysMessage(ex.CMessage());
pXAudio2.Release();
CoUninitialize();
@ -403,7 +420,8 @@ public:
int GetEmptySampleCount()
{
if( voiceContext == NULL ) return 0;
if (voiceContext == NULL)
return 0;
return voiceContext->GetEmptySampleCount();
}

View File

@ -47,12 +47,11 @@ private:
{
static const int BufferSizeBytes = BufferSize * sizeof(T);
while( waveout_running )
{
while (waveout_running) {
bool didsomething = false;
for(u32 i=0;i<numBuffers;i++)
{
if(!(whbuffer[i].dwFlags & WHDR_DONE) ) continue;
for (u32 i = 0; i < numBuffers; i++) {
if (!(whbuffer[i].dwFlags & WHDR_DONE))
continue;
WAVEHDR *buf = whbuffer + i;
@ -88,7 +87,8 @@ public:
MMRESULT woores;
if (Test()) return -1;
if (Test())
return -1;
// TODO : Use dsound to determine the speaker configuration, and expand audio from there.
@ -142,8 +142,7 @@ public:
qbuffer = new StereoOut16[BufferSize * numBuffers];
woores = waveOutOpen(&hwodevice, WAVE_MAPPER, &wformat, 0, 0, 0);
if (woores != MMSYSERR_NOERROR)
{
if (woores != MMSYSERR_NOERROR) {
waveOutGetErrorText(woores, (wchar_t *)&ErrText, 255);
SysMessage("WaveOut Error: %s", ErrText);
return -1;
@ -151,8 +150,7 @@ public:
const int BufferSizeBytes = wformat.nBlockAlign * BufferSize;
for(u32 i=0;i<numBuffers;i++)
{
for (u32 i = 0; i < numBuffers; i++) {
whbuffer[i].dwBufferLength = BufferSizeBytes;
whbuffer[i].dwBytesRecorded = BufferSizeBytes;
whbuffer[i].dwFlags = 0;
@ -191,8 +189,7 @@ public:
// Clean up
//
waveOutReset(hwodevice);
for(u32 i=0;i<numBuffers;i++)
{
for (u32 i = 0; i < numBuffers; i++) {
waveOutUnprepareHeader(hwodevice, &whbuffer[i], sizeof(WAVEHDR));
}
waveOutClose(hwodevice);
@ -201,13 +198,11 @@ public:
}
private:
static BOOL CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch(uMsg)
{
switch (uMsg) {
case WM_INITDIALOG:
wchar_t temp[128];
@ -221,14 +216,14 @@ private:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDOK:
{
switch (wmId) {
case IDOK: {
Config_WaveOut.NumBuffers = (int)SendMessage(GetDlgItem(hWnd, IDC_BUFFERS_SLIDER), TBM_GETPOS, 0, 0);
if( Config_WaveOut.NumBuffers < 3 ) Config_WaveOut.NumBuffers = 3;
if( Config_WaveOut.NumBuffers > MAX_BUFFER_COUNT ) Config_WaveOut.NumBuffers = MAX_BUFFER_COUNT;
if (Config_WaveOut.NumBuffers < 3)
Config_WaveOut.NumBuffers = 3;
if (Config_WaveOut.NumBuffers > MAX_BUFFER_COUNT)
Config_WaveOut.NumBuffers = MAX_BUFFER_COUNT;
}
EndDialog(hWnd, 0);
break;
@ -252,8 +247,10 @@ private:
case TB_PAGEDOWN:
wmEvent = (int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0);
case TB_THUMBTRACK:
if( wmEvent < 3 ) wmEvent = 3;
if( wmEvent > MAX_BUFFER_COUNT ) wmEvent = MAX_BUFFER_COUNT;
if (wmEvent < 3)
wmEvent = 3;
if (wmEvent > MAX_BUFFER_COUNT)
wmEvent = MAX_BUFFER_COUNT;
SendMessage((HWND)lParam, TBM_SETPOS, TRUE, wmEvent);
swprintf_s(temp, L"%d (%d ms latency)", wmEvent, 1000 / (96000 / (wmEvent * BufferSize)));
SetWindowText(GetDlgItem(hWnd, IDC_LATENCY_LABEL), temp);
@ -274,8 +271,7 @@ public:
{
INT_PTR ret;
ret = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_WAVEOUT), (HWND)parent, (DLGPROC)ConfigProc, 1);
if(ret==-1)
{
if (ret == -1) {
MessageBox((HWND)parent, L"Error Opening the config dialog.", L"OMG ERROR!", MB_OK | MB_SETFOREGROUND);
return;
}
@ -284,7 +280,8 @@ public:
s32 Test() const
{
if (waveOutGetNumDevs() == 0) {
SysMessage("No waveOut Devices Present\n"); return -1;
SysMessage("No waveOut Devices Present\n");
return -1;
}
return 0;
}
@ -292,8 +289,7 @@ public:
int GetEmptySampleCount()
{
int result = 0;
for(int i=0;i<MAX_BUFFER_COUNT;i++)
{
for (int i = 0; i < MAX_BUFFER_COUNT; i++) {
result += (whbuffer[i].dwFlags & WHDR_DONE) ? BufferSize : 0;
}
return result;

View File

@ -44,10 +44,10 @@ HRESULT GUIDFromString(const wchar_t *str, LPGUID guid)
&guid_u8[4],
&guid_u8[5],
&guid_u8[6],
&guid_u8[7]
);
&guid_u8[7]);
if(r!=11) return -1;
if (r != 11)
return -1;
guid->Data1 = guid_u32;
guid->Data2 = guid_u16[0];
@ -65,8 +65,7 @@ HRESULT GUIDFromString(const wchar_t *str, LPGUID guid)
__forceinline void Verifyc(HRESULT hr, const char *fn)
{
if(FAILED(hr))
{
if (FAILED(hr)) {
assert(0);
throw std::runtime_error("DirectSound returned an error from %s");
}
@ -95,8 +94,7 @@ BOOL DoHandleScrollMessage( HWND hwndDisplay, WPARAM wParam, LPARAM lParam )
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch(wmId)
{
switch (wmId) {
//case TB_ENDTRACK:
//case TB_THUMBPOSITION:
case TB_LINEUP:
@ -119,4 +117,3 @@ int GetSliderValue( HWND hWnd, int idc )
int retval = (int)SendMessage(GetDlgItem(hWnd, idc), TBM_GETPOS, 0, 0);
return GetClamped(retval, 0, 512);
}

View File

@ -32,8 +32,15 @@
extern HINSTANCE hInstance;
#define SET_CHECK(idc, value) SendMessage(GetDlgItem(hWnd, idc), BM_SETCHECK, ((value) == 0) ? BST_UNCHECKED : BST_CHECKED, 0)
#define HANDLE_CHECK(idc,hvar) case idc: (hvar) = !(hvar); SendMessage(GetDlgItem(hWnd,idc),BM_SETCHECK,(hvar)?BST_CHECKED:BST_UNCHECKED,0); break
#define HANDLE_CHECKNB(idc,hvar)case idc: (hvar) = !(hvar); SendMessage(GetDlgItem(hWnd,idc),BM_SETCHECK,(hvar)?BST_CHECKED:BST_UNCHECKED,0)
#define HANDLE_CHECK(idc, hvar) \
case idc: \
(hvar) = !(hvar); \
SendMessage(GetDlgItem(hWnd, idc), BM_SETCHECK, (hvar) ? BST_CHECKED : BST_UNCHECKED, 0); \
break
#define HANDLE_CHECKNB(idc, hvar) \
case idc: \
(hvar) = !(hvar); \
SendMessage(GetDlgItem(hWnd, idc), BM_SETCHECK, (hvar) ? BST_CHECKED : BST_UNCHECKED, 0)
#define ENABLE_CONTROL(idc, value) EnableWindow(GetDlgItem(hWnd, idc), value)
#define INIT_SLIDER(idc, minrange, maxrange, tickfreq, pagesize, linesize) \
@ -44,7 +51,8 @@ extern HINSTANCE hInstance;
SendMessage(GetDlgItem(hWnd, idc), TBM_SETLINESIZE, 0, linesize)
#define HANDLE_SCROLL_MESSAGE(idc, idcDisplay) \
if((HWND)lParam == GetDlgItem(hWnd,idc)) return DoHandleScrollMessage( GetDlgItem(hWnd,idcDisplay), wParam, lParam )
if ((HWND)lParam == GetDlgItem(hWnd, idc)) \
return DoHandleScrollMessage(GetDlgItem(hWnd, idcDisplay), wParam, lParam)
// *** BEGIN DRIVER-SPECIFIC CONFIGURATION ***
@ -55,9 +63,9 @@ struct CONFIG_XAUDIO2
wxString Device;
s8 NumBuffers;
CONFIG_XAUDIO2() :
Device(),
NumBuffers( 2 )
CONFIG_XAUDIO2()
: Device()
, NumBuffers(2)
{
}
};
@ -67,9 +75,9 @@ struct CONFIG_WAVEOUT
wxString Device;
s8 NumBuffers;
CONFIG_WAVEOUT() :
Device(),
NumBuffers( 4 )
CONFIG_WAVEOUT()
: Device()
, NumBuffers(4)
{
}
};

View File

@ -50,7 +50,8 @@ DWORD WINAPI DspUpdateThread(PVOID param);
s32 DspLoadLibrary(wchar_t *fileName, int modNum)
#ifdef USE_A_THREAD
{
if(!dspPluginEnabled) return -1;
if (!dspPluginEnabled)
return -1;
running = true;
hUpdateThread = CreateThread(NULL, 0, DspUpdateThread, NULL, 0, &UpdateThreadId);
@ -60,18 +61,17 @@ s32 DspLoadLibrary(wchar_t *fileName, int modNum)
s32 DspLoadLibrary2(wchar_t *fileName, int modNum)
#endif
{
if( !dspPluginEnabled ) return -1;
if (!dspPluginEnabled)
return -1;
hLib = LoadLibraryW(fileName);
if(!hLib)
{
if (!hLib) {
return 1;
}
pGetHeader = (pWinampDSPGetHeader2)GetProcAddress(hLib, "winampDSPGetHeader2");
if(!pGetHeader)
{
if (!pGetHeader) {
FreeLibrary(hLib);
hLib = NULL;
return 1;
@ -81,8 +81,7 @@ s32 DspLoadLibrary2( wchar_t *fileName, int modNum )
pModule = pHeader->getModule(modNum);
if(!pModule)
{
if (!pModule) {
pGetHeader = NULL;
pHeader = NULL;
FreeLibrary(hLib);
@ -100,12 +99,12 @@ s32 DspLoadLibrary2( wchar_t *fileName, int modNum )
void DspCloseLibrary()
#ifdef USE_A_THREAD
{
if(!dspPluginEnabled) return ;
if (!dspPluginEnabled)
return;
PostThreadMessage(UpdateThreadId, WM_QUIT, 0, 0);
running = false;
if(WaitForSingleObject(hUpdateThread,1000)==WAIT_TIMEOUT)
{
if (WaitForSingleObject(hUpdateThread, 1000) == WAIT_TIMEOUT) {
ConLog("SPU2-X: WARNING: DSP Thread did not close itself in time. Assuming hung. Terminating.\n");
TerminateThread(hUpdateThread, 1);
}
@ -114,10 +113,10 @@ void DspCloseLibrary()
void DspCloseLibrary2()
#endif
{
if(!dspPluginEnabled) return ;
if (!dspPluginEnabled)
return;
if(hLib)
{
if (hLib) {
pModule->Quit(pModule);
FreeLibrary(hLib);
}
@ -129,10 +128,10 @@ void DspCloseLibrary2()
int DspProcess(s16 *buffer, int samples)
{
if(!dspPluginEnabled) return samples;
if (!dspPluginEnabled)
return samples;
if(hLib)
{
if (hLib) {
return pModule->ModifySamples(pModule, buffer, samples, 16, 2, SampleRate);
}
return samples;
@ -145,17 +144,16 @@ void DspUpdate()
DWORD WINAPI DspUpdateThread(PVOID param)
{
if( !dspPluginEnabled ) return -1;
if (!dspPluginEnabled)
return -1;
if (DspLoadLibrary2(dspPlugin, dspPluginModule))
return -1;
MSG msg;
while(running)
{
while (running) {
GetMessage(&msg, 0, 0, 0);
if((msg.hwnd==NULL)&&(msg.message==WM_QUIT))
{
if ((msg.hwnd == NULL) && (msg.message == WM_QUIT)) {
break;
}
TranslateMessage(&msg);
@ -168,11 +166,11 @@ DWORD WINAPI DspUpdateThread(PVOID param)
#else
{
if(!dspPluginEnabled) return;
if (!dspPluginEnabled)
return;
MSG msg;
while(PeekMessage(&msg,0,0,0,PM_REMOVE))
{
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

View File

@ -27,7 +27,8 @@
#pragma once
typedef struct winampDSPModule {
typedef struct winampDSPModule
{
char *description; // description
HWND hwndParent; // parent window (filled in by calling app)
HINSTANCE hDllInstance; // instance handle to this DLL (filled in by calling app)
@ -45,7 +46,8 @@ typedef struct winampDSPModule {
void *userData; // user data, optional
} winampDSPModule;
typedef struct {
typedef struct
{
int version; // DSP_HDRVER
char *description; // description of library
winampDSPModule *(*getModule)(int); // module retrieval function

View File

@ -40,9 +40,9 @@ struct V_VolumeLR
s32 Right;
V_VolumeLR() {}
V_VolumeLR( s32 both ) :
Left( both ),
Right( both )
V_VolumeLR(s32 both)
: Left(both)
, Right(both)
{
}
@ -61,11 +61,11 @@ struct V_VolumeSlide
public:
V_VolumeSlide() {}
V_VolumeSlide( s16 regval, s32 fullvol ) :
Reg_VOL( regval ),
Value( fullvol ),
Increment( 0 ),
Mode( 0 )
V_VolumeSlide(s16 regval, s32 fullvol)
: Reg_VOL(regval)
, Value(fullvol)
, Increment(0)
, Mode(0)
{
}
@ -84,9 +84,9 @@ struct V_VolumeSlideLR
public:
V_VolumeSlideLR() {}
V_VolumeSlideLR( s16 regval, s32 bothval ) :
Left( regval, bothval ),
Right( regval, bothval )
V_VolumeSlideLR(s16 regval, s32 bothval)
: Left(regval, bothval)
, Right(regval, bothval)
{
}
@ -351,7 +351,6 @@ struct V_CoreGates
s16 ExtR; // External Input to Direct Output (Right)
};
};
};
struct VoiceMixSet
@ -360,9 +359,9 @@ struct VoiceMixSet
StereoOut32 Dry, Wet;
VoiceMixSet() {}
VoiceMixSet( const StereoOut32& dry, const StereoOut32& wet ) :
Dry( dry ),
Wet( wet )
VoiceMixSet(const StereoOut32 &dry, const StereoOut32 &wet)
: Dry(dry)
, Wet(wet)
{
}
};
@ -459,7 +458,11 @@ struct V_Core
// ----------------------------------------------------------------------------------
// uninitialized constructor
V_Core() : Index( -1 ), DMAPtr( NULL ) {}
V_Core()
: Index(-1)
, DMAPtr(NULL)
{
}
V_Core(int idx); // our badass constructor
~V_Core() throw();
@ -505,14 +508,16 @@ struct V_Core
__forceinline u16 DmaRead()
{
const u16 ret = (u16)spu2M_Read(TSA);
++TSA; TSA &= 0xfffff;
++TSA;
TSA &= 0xfffff;
return ret;
}
__forceinline void DmaWrite(u16 value)
{
spu2M_Write(TSA, value);
++TSA; TSA &= 0xfffff;
++TSA;
TSA &= 0xfffff;
}
void LogAutoDMA(FILE *fp);

View File

@ -193,4 +193,3 @@ Core attributes (SD_C)
extern u16 *regtable[0x401];
extern u16 const *const regtable_original[0x401];

View File

@ -108,4 +108,3 @@ typedef struct _chstatus
u8 category;
u8 reservd2[22];
} chstatus:

View File

@ -56,8 +56,10 @@ s32 __fastcall Savestate::FreezeIt( DataBlock& spud )
pxAssertMsg(spu2regs && _spu2mem, "Looks like PCSX2 is trying to savestate while pluigns are shut down. That's a no-no! It shouldn't crash, but the savestate will probably be corrupted.");
if( spu2regs != NULL ) memcpy(spud.unkregs, spu2regs, sizeof(spud.unkregs));
if( _spu2mem != NULL ) memcpy(spud.mem, _spu2mem, sizeof(spud.mem));
if (spu2regs != NULL)
memcpy(spud.unkregs, spu2regs, sizeof(spud.unkregs));
if (_spu2mem != NULL)
memcpy(spud.mem, _spu2mem, sizeof(spud.mem));
memcpy(spud.Cores, Cores, sizeof(Cores));
memcpy(&spud.Spdif, &Spdif, sizeof(Spdif));
@ -78,8 +80,7 @@ s32 __fastcall Savestate::FreezeIt( DataBlock& spud )
s32 __fastcall Savestate::ThawIt(DataBlock &spud)
{
if( spud.spu2id != SAVE_ID || spud.version < SAVE_VERSION )
{
if (spud.spu2id != SAVE_ID || spud.version < SAVE_VERSION) {
fprintf(stderr, "\n*** SPU2-X Warning:\n");
if (spud.spu2id == SAVE_ID)
fprintf(stderr, "\tSavestate version is from an older version of this plugin.\n");
@ -88,8 +89,7 @@ s32 __fastcall Savestate::ThawIt( DataBlock& spud )
fprintf(stderr,
"\tAudio may not recover correctly. Save your game to memorycard, reset,\n\n"
"\tand then continue from there.\n\n"
);
"\tand then continue from there.\n\n");
// Do *not* reset the cores.
// We'll need some "hints" as to how the cores should be initialized, and the
@ -99,16 +99,16 @@ s32 __fastcall Savestate::ThawIt( DataBlock& spud )
// adpcm cache : Clear all the cache flags and buffers.
wipe_the_cache();
}
else
{
} else {
SndBuffer::ClearContents();
pxAssertMsg(spu2regs && _spu2mem, "Looks like PCSX2 is trying to loadstate while pluigns are shut down. That's a no-no! It shouldn't crash, but the savestate will probably be corrupted.");
// base stuff
if( spu2regs ) memcpy(spu2regs, spud.unkregs, sizeof(spud.unkregs));
if( _spu2mem ) memcpy(_spu2mem, spud.mem, sizeof(spud.mem));
if (spu2regs)
memcpy(spu2regs, spud.unkregs, sizeof(spud.unkregs));
if (_spu2mem)
memcpy(_spu2mem, spud.mem, sizeof(spud.mem));
memcpy(Cores, spud.Cores, sizeof(Cores));
memcpy(&Spdif, &spud.Spdif, sizeof(Spdif));
@ -124,10 +124,8 @@ s32 __fastcall Savestate::ThawIt( DataBlock& spud )
// Go through the V_Voice structs and recalculate SBuffer pointer from
// the NextA setting.
for( int c=0; c<2; c++ )
{
for( int v=0; v<24; v++ )
{
for (int c = 0; c < 2; c++) {
for (int v = 0; v < 24; v++) {
const int cacheIdx = Cores[c].Voices[v].NextA / pcm_WordsPerBlock;
Cores[c].Voices[v].SBuffer = pcm_cache_data[cacheIdx].Sampledata;
}

View File

@ -77,12 +77,12 @@ __forceinline void spu2M_Write( u32 addr, s16 value )
// (note to self : addr address WORDs, not bytes)
addr &= 0xfffff;
if( addr >= SPU2_DYN_MEMLINE )
{
if (addr >= SPU2_DYN_MEMLINE) {
const int cacheIdx = addr / pcm_WordsPerBlock;
pcm_cache_data[cacheIdx].Validated = false;
if(MsgToConsole() && MsgCache()) ConLog( "* SPU2-X: PcmCache Block Clear at 0x%x (cacheIdx=0x%x)\n", addr, cacheIdx);
if (MsgToConsole() && MsgCache())
ConLog("* SPU2-X: PcmCache Block Clear at 0x%x (cacheIdx=0x%x)\n", addr, cacheIdx);
}
*GetMemPtr(addr) = value;
}
@ -96,7 +96,8 @@ __forceinline void spu2M_Write( u32 addr, u16 value )
V_VolumeLR V_VolumeLR::Max(0x7FFFFFFF);
V_VolumeSlideLR V_VolumeSlideLR::Max(0x3FFF, 0x7FFFFFFF);
V_Core::V_Core( int coreidx ) : Index( coreidx )
V_Core::V_Core(int coreidx)
: Index(coreidx)
//LogFile_AutoDMA( NULL )
{
/*char fname[128];
@ -134,8 +135,7 @@ void V_Core::Init( int index )
memset(&WetGate, -1, sizeof(WetGate));
DryGate.ExtL = 0;
DryGate.ExtR = 0;
if (!c)
{
if (!c) {
WetGate.ExtL = 0;
WetGate.ExtR = 0;
}
@ -162,8 +162,7 @@ void V_Core::Init( int index )
IRQA = 0x800;
IRQEnable = 0; // PS2 confirmed
for( uint v=0; v<NumVoices; ++v )
{
for (uint v = 0; v < NumVoices; ++v) {
VoiceGates[v].DryL = -1;
VoiceGates[v].DryR = -1;
VoiceGates[v].WetL = -1;
@ -235,12 +234,9 @@ s32 V_Core::EffectsBufferIndexer( s32 offset ) const
// Need to use modulus here, because games can and will drop the buffer size
// without notice, and it leads to offsets several times past the end of the buffer.
if( pos > EffectsEndA )
{
if (pos > EffectsEndA) {
pos = EffectsStartA + (offset % EffectsBufferSize);
}
else if( pos < EffectsStartA )
{
} else if (pos < EffectsStartA) {
pos = EffectsEndA + 1 - (offset % EffectsBufferSize);
}
return pos;
@ -277,10 +273,12 @@ void V_Core::UpdateEffectsBufferSize()
EffectsBufferSize = newbufsize;
EffectsBufferStart = EffectsStartA;
if( EffectsBufferSize <= 0 ) return;
if (EffectsBufferSize <= 0)
return;
// debug: shows reverb parameters in console
if(MsgToConsole()) AnalyzeReverbPreset();
if (MsgToConsole())
AnalyzeReverbPreset();
// Rebuild buffer indexers.
RevBuffers.ACC_SRC_A0 = EffectsBufferIndexer(Revb.ACC_SRC_A0);
@ -313,8 +311,7 @@ void V_Core::UpdateEffectsBufferSize()
void V_Voice::QueueStart()
{
if (Cycles - PlayCycle < delayCycles)
{
if (Cycles - PlayCycle < delayCycles) {
// Required by The Legend of Spyro: The Eternal Night (probably the other two legend games too)
ConLog(" *** KeyOn after less than %d T disregarded.\n", delayCycles);
return;
@ -324,10 +321,8 @@ void V_Voice::QueueStart()
bool V_Voice::Start()
{
if((Cycles-PlayCycle)>= delayCycles)
{
if(StartA&7)
{
if ((Cycles - PlayCycle) >= delayCycles) {
if (StartA & 7) {
fprintf(stderr, " *** Misaligned StartA %05x!\n", StartA);
StartA = (StartA + 0xFFFF8) + 0x8;
}
@ -346,8 +341,7 @@ bool V_Voice::Start()
PV3 = PV4 = 0;
NextCrest = -0x8000;
return true;
}
else
} else
return false;
}
@ -369,15 +363,16 @@ __forceinline void TimeUpdate(u32 cClocks)
// It's not totally uncommon for the IOP's clock to jump backwards a cycle or two, and in
// such cases we just want to ignore the TimeUpdate call.
if( dClocks > (u32)-15 ) return;
if (dClocks > (u32)-15)
return;
// But if for some reason our clock value seems way off base (typically due to bad dma
// timings from PCSX2), just mix out a little bit, skip the rest, and hope the ship
// "rights" itself later on.
if( dClocks > (u32)(TickInterval*SanityInterval) )
{
if(MsgToConsole()) ConLog( " * SPU2 > TimeUpdate Sanity Check (Tick Delta: %d) (PS2 Ticks: %d)\n", dClocks/TickInterval, cClocks/TickInterval );
if (dClocks > (u32)(TickInterval * SanityInterval)) {
if (MsgToConsole())
ConLog(" * SPU2 > TimeUpdate Sanity Check (Tick Delta: %d) (PS2 Ticks: %d)\n", dClocks / TickInterval, cClocks / TickInterval);
dClocks = TickInterval * SanityInterval;
lClocks = cClocks - dClocks;
}
@ -389,47 +384,43 @@ __forceinline void TimeUpdate(u32 cClocks)
if (SynchMode == 1) // AsyncMix on
SndBuffer::UpdateTempoChangeAsyncMixing();
else TickInterval = 768; // Reset to default, in case the user hotswitched from async to something else.
else
TickInterval = 768; // Reset to default, in case the user hotswitched from async to something else.
//Update Mixing Progress
while(dClocks>=TickInterval)
{
if(has_to_call_irq)
{
while (dClocks >= TickInterval) {
if (has_to_call_irq) {
//ConLog("* SPU2-X: Irq Called (%04x) at cycle %d.\n", Spdif.Info, Cycles);
has_to_call_irq = false;
if(_irqcallback) _irqcallback();
if (_irqcallback)
_irqcallback();
}
#ifndef ENABLE_NEW_IOPDMA_SPU2
//Update DMA4 interrupt delay counter
if(Cores[0].DMAICounter>0)
{
if (Cores[0].DMAICounter > 0) {
Cores[0].DMAICounter -= TickInterval;
if(Cores[0].DMAICounter<=0)
{
if (Cores[0].DMAICounter <= 0) {
//ConLog("counter set and callback!\n");
Cores[0].MADR = Cores[0].TADR;
Cores[0].DMAICounter = 0;
if(dma4callback) dma4callback();
}
else {
if (dma4callback)
dma4callback();
} else {
Cores[0].MADR += TickInterval << 1;
}
}
//Update DMA7 interrupt delay counter
if(Cores[1].DMAICounter>0)
{
if (Cores[1].DMAICounter > 0) {
Cores[1].DMAICounter -= TickInterval;
if(Cores[1].DMAICounter<=0)
{
if (Cores[1].DMAICounter <= 0) {
Cores[1].MADR = Cores[1].TADR;
Cores[1].DMAICounter = 0;
//ConLog( "* SPU2 > DMA 7 Callback! %d\n", Cycles );
if(dma7callback) dma7callback();
}
else {
if (dma7callback)
dma7callback();
} else {
Cores[1].MADR += TickInterval << 1;
}
}
@ -464,22 +455,17 @@ __forceinline void UpdateSpdifMode()
return;
}
if(Spdif.Out&SPDIF_OUT_BYPASS)
{
if (Spdif.Out & SPDIF_OUT_BYPASS) {
PlayMode = 2;
if (!(Spdif.Mode & SPDIF_MODE_BYPASS_BITSTREAM))
PlayMode = 4; //bitstream bypass
}
else
{
} else {
PlayMode = 0; //normal processing
if(Spdif.Out&SPDIF_OUT_PCM)
{
if (Spdif.Out & SPDIF_OUT_PCM) {
PlayMode = 1;
}
}
if(OPM!=PlayMode)
{
if (OPM != PlayMode) {
ConLog("* SPU2-X: Play Mode Set to %s (%d).\n",
(PlayMode == 0) ? "Normal" : ((PlayMode == 1) ? "PCM Clone" : ((PlayMode == 2) ? "PCM Bypass" : "BitStream Bypass")), PlayMode);
}
@ -515,13 +501,11 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
bool show = true;
u32 reg = mem & 0xffff;
if((reg>=0x1c00)&&(reg<0x1d80))
{
if ((reg >= 0x1c00) && (reg < 0x1d80)) {
//voice values
u8 voice = ((reg - 0x1c00) >> 4);
u8 vval = reg & 0xf;
switch(vval)
{
switch (vval) {
case 0x0: //VOLL (Volume L)
case 0x2: //VOLR (Volume R)
{
@ -533,10 +517,9 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
thisvol.Mode = (value & 0xF000) >> 12;
thisvol.Increment = (value & 0x7F);
// We're not sure slides work 100%
if (IsDevBuild) ConLog("* SPU2: Voice uses Slides in Mode = %x, Increment = %x\n", thisvol.Mode, thisvol.Increment);
}
else
{
if (IsDevBuild)
ConLog("* SPU2: Voice uses Slides in Mode = %x, Increment = %x\n", thisvol.Mode, thisvol.Increment);
} else {
// Constant Volume mode (no slides or envelopes)
// Volumes range from 0x3fff to 0x7fff, with 0x4000 serving as
// the "sign" bit, so a simple bitwise extension will do the trick:
@ -549,7 +532,8 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
break;
}
case 0x4:
if (value > 0x3fff) ConLog("* SPU2: Pitch setting too big: 0x%x\n", value);
if (value > 0x3fff)
ConLog("* SPU2: Pitch setting too big: 0x%x\n", value);
Voices[voice].Pitch = value & 0x3fff;
//ConLog("voice %x Pitch write: %x\n", voice, Voices[voice].Pitch);
break;
@ -581,8 +565,8 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
}
}
else switch(reg)
{
else
switch (reg) {
case 0x1d80: // Mainvolume left
MasterVol.Left.Mode = 0;
MasterVol.Left.RegSet(value);
@ -617,23 +601,27 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
case 0x1d90: // Channel FM (pitch lfo) mode (0-15)
SPU2_FastWrite(REG_S_PMON, value);
if (value!=0)ConLog("spu2x warning: wants to set Pitch Modulation reg1 to %x \n", value);
if (value != 0)
ConLog("spu2x warning: wants to set Pitch Modulation reg1 to %x \n", value);
break;
case 0x1d92: // Channel FM (pitch lfo) mode (16-23)
SPU2_FastWrite(REG_S_PMON + 2, value);
if (value != 0)ConLog("spu2x warning: wants to set Pitch Modulation reg2 to %x \n", value);
if (value != 0)
ConLog("spu2x warning: wants to set Pitch Modulation reg2 to %x \n", value);
break;
case 0x1d94: // Channel Noise mode (0-15)
SPU2_FastWrite(REG_S_NON, value);
if (value != 0) ConLog("spu2x warning: wants to set Channel Noise mode reg1 to %x\n", value);
if (value != 0)
ConLog("spu2x warning: wants to set Channel Noise mode reg1 to %x\n", value);
break;
case 0x1d96: // Channel Noise mode (16-23)
SPU2_FastWrite(REG_S_NON + 2, value);
if (value != 0) ConLog("spu2x warning: wants to set Channel Noise mode reg2 to %x\n", value);
if (value != 0)
ConLog("spu2x warning: wants to set Channel Noise mode reg2 to %x\n", value);
break;
case 0x1d98: // 1F801D98h - Voice 0..23 Reverb mode aka Echo On (EON) (R/W)
@ -676,8 +664,7 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
//EffectsEndA = 0xFFFFF; // fixed EndA in psx mode
Cores[0].RevBuffers.NeedsUpdated = true;
ReverbX = 0;
}
break;
} break;
case 0x1da4:
IRQA = map_spu1to2(value);
@ -691,8 +678,7 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
case 0x1da8: // Spu Write to Memory
//ConLog("SPU direct DMA Write. Current TSA = %x\n", TSA);
if (Cores[0].IRQEnable && (Cores[0].IRQA <= Cores[0].TSA))
{
if (Cores[0].IRQEnable && (Cores[0].IRQA <= Cores[0].TSA)) {
SetIrqCall(0);
_irqcallback();
}
@ -732,42 +718,106 @@ void V_Core::WriteRegPS1( u32 mem, u16 value )
case 0x1DBE:
break;
case 0x1DC0: Revb.FB_SRC_A = value * 4; break;
case 0x1DC2: Revb.FB_SRC_B = value * 4; break;
case 0x1DC4: Revb.IIR_ALPHA = value; break;
case 0x1DC6: Revb.ACC_COEF_A = value; break;
case 0x1DC8: Revb.ACC_COEF_B = value; break;
case 0x1DCA: Revb.ACC_COEF_C = value; break;
case 0x1DCC: Revb.ACC_COEF_D = value; break;
case 0x1DCE: Revb.IIR_COEF = value; break;
case 0x1DD0: Revb.FB_ALPHA = value; break;
case 0x1DD2: Revb.FB_X = value; break;
case 0x1DD4: Revb.IIR_DEST_A0 = value * 4; break;
case 0x1DD6: Revb.IIR_DEST_A1 = value * 4; break;
case 0x1DD8: Revb.ACC_SRC_A0 = value * 4; break;
case 0x1DDA: Revb.ACC_SRC_A1 = value * 4; break;
case 0x1DDC: Revb.ACC_SRC_B0 = value * 4; break;
case 0x1DDE: Revb.ACC_SRC_B1 = value * 4; break;
case 0x1DE0: Revb.IIR_SRC_A0 = value * 4; break;
case 0x1DE2: Revb.IIR_SRC_A1 = value * 4; break;
case 0x1DE4: Revb.IIR_DEST_B0 = value * 4; break;
case 0x1DE6: Revb.IIR_DEST_B1 = value * 4; break;
case 0x1DE8: Revb.ACC_SRC_C0 = value * 4; break;
case 0x1DEA: Revb.ACC_SRC_C1 = value * 4; break;
case 0x1DEC: Revb.ACC_SRC_D0 = value * 4; break;
case 0x1DEE: Revb.ACC_SRC_D1 = value * 4; break;
case 0x1DF0: Revb.IIR_SRC_B0 = value * 4; break; // IIR_SRC_B0 and IIR_SRC_B1 supposedly swapped on SPU2
case 0x1DF2: Revb.IIR_SRC_B1 = value * 4; break; // but I don't believe it! (games in psxmode sound better unswapped)
case 0x1DF4: Revb.MIX_DEST_A0 = value * 4; break;
case 0x1DF6: Revb.MIX_DEST_A1 = value * 4; break;
case 0x1DF8: Revb.MIX_DEST_B0 = value * 4; break;
case 0x1DFA: Revb.MIX_DEST_B1 = value * 4; break;
case 0x1DFC: Revb.IN_COEF_L = value; break;
case 0x1DFE: Revb.IN_COEF_R = value; break;
case 0x1DC0:
Revb.FB_SRC_A = value * 4;
break;
case 0x1DC2:
Revb.FB_SRC_B = value * 4;
break;
case 0x1DC4:
Revb.IIR_ALPHA = value;
break;
case 0x1DC6:
Revb.ACC_COEF_A = value;
break;
case 0x1DC8:
Revb.ACC_COEF_B = value;
break;
case 0x1DCA:
Revb.ACC_COEF_C = value;
break;
case 0x1DCC:
Revb.ACC_COEF_D = value;
break;
case 0x1DCE:
Revb.IIR_COEF = value;
break;
case 0x1DD0:
Revb.FB_ALPHA = value;
break;
case 0x1DD2:
Revb.FB_X = value;
break;
case 0x1DD4:
Revb.IIR_DEST_A0 = value * 4;
break;
case 0x1DD6:
Revb.IIR_DEST_A1 = value * 4;
break;
case 0x1DD8:
Revb.ACC_SRC_A0 = value * 4;
break;
case 0x1DDA:
Revb.ACC_SRC_A1 = value * 4;
break;
case 0x1DDC:
Revb.ACC_SRC_B0 = value * 4;
break;
case 0x1DDE:
Revb.ACC_SRC_B1 = value * 4;
break;
case 0x1DE0:
Revb.IIR_SRC_A0 = value * 4;
break;
case 0x1DE2:
Revb.IIR_SRC_A1 = value * 4;
break;
case 0x1DE4:
Revb.IIR_DEST_B0 = value * 4;
break;
case 0x1DE6:
Revb.IIR_DEST_B1 = value * 4;
break;
case 0x1DE8:
Revb.ACC_SRC_C0 = value * 4;
break;
case 0x1DEA:
Revb.ACC_SRC_C1 = value * 4;
break;
case 0x1DEC:
Revb.ACC_SRC_D0 = value * 4;
break;
case 0x1DEE:
Revb.ACC_SRC_D1 = value * 4;
break;
case 0x1DF0:
Revb.IIR_SRC_B0 = value * 4;
break; // IIR_SRC_B0 and IIR_SRC_B1 supposedly swapped on SPU2
case 0x1DF2:
Revb.IIR_SRC_B1 = value * 4;
break; // but I don't believe it! (games in psxmode sound better unswapped)
case 0x1DF4:
Revb.MIX_DEST_A0 = value * 4;
break;
case 0x1DF6:
Revb.MIX_DEST_A1 = value * 4;
break;
case 0x1DF8:
Revb.MIX_DEST_B0 = value * 4;
break;
case 0x1DFA:
Revb.MIX_DEST_B1 = value * 4;
break;
case 0x1DFC:
Revb.IN_COEF_L = value;
break;
case 0x1DFE:
Revb.IN_COEF_R = value;
break;
}
if(show) FileLog("[%10d] (!) SPU write mem %08x value %04x\n",Cycles,mem,value);
if (show)
FileLog("[%10d] (!) SPU write mem %08x value %04x\n", Cycles, mem, value);
spu2Ru16(mem) = value;
}
@ -781,13 +831,11 @@ u16 V_Core::ReadRegPS1(u32 mem)
u32 reg = mem & 0xffff;
if((reg>=0x1c00)&&(reg<0x1d80))
{
if ((reg >= 0x1c00) && (reg < 0x1d80)) {
//voice values
u8 voice = ((reg - 0x1c00) >> 4);
u8 vval = reg & 0xf;
switch(vval)
{
switch (vval) {
case 0x0: //VOLL (Volume L)
//value=Voices[voice].VolumeL.Mode;
//value=Voices[voice].VolumeL.Value;
@ -825,31 +873,61 @@ u16 V_Core::ReadRegPS1(u32 mem)
jNO_DEFAULT;
}
}
else switch(reg)
{
case 0x1d80: value = MasterVol.Left.Value >> 16; break;
case 0x1d82: value = MasterVol.Right.Value >> 16; break;
case 0x1d84: value = FxVol.Left >> 16; break;
case 0x1d86: value = FxVol.Right >> 16; break;
} else
switch (reg) {
case 0x1d80:
value = MasterVol.Left.Value >> 16;
break;
case 0x1d82:
value = MasterVol.Right.Value >> 16;
break;
case 0x1d84:
value = FxVol.Left >> 16;
break;
case 0x1d86:
value = FxVol.Right >> 16;
break;
case 0x1d88: value = 0; break; // Voice 0..23 Key ON(Start Attack / Decay / Sustain) (W)
case 0x1d8a: value = 0; break;
case 0x1d8c: value = 0; break; // Voice 0..23 Key OFF (Start Release) (W)
case 0x1d8e: value = 0; break;
case 0x1d88:
value = 0;
break; // Voice 0..23 Key ON(Start Attack / Decay / Sustain) (W)
case 0x1d8a:
value = 0;
break;
case 0x1d8c:
value = 0;
break; // Voice 0..23 Key OFF (Start Release) (W)
case 0x1d8e:
value = 0;
break;
case 0x1d90: value = Regs.PMON&0xFFFF; break; // Voice 0..23 Channel FM(pitch lfo) mode(R / W)
case 0x1d92: value = Regs.PMON>>16; break;
case 0x1d90:
value = Regs.PMON & 0xFFFF;
break; // Voice 0..23 Channel FM(pitch lfo) mode(R / W)
case 0x1d92:
value = Regs.PMON >> 16;
break;
case 0x1d94: value = Regs.NON&0xFFFF; break; // Voice 0..23 Channel Noise mode (R/W)
case 0x1d96: value = Regs.NON>>16; break;
case 0x1d94:
value = Regs.NON & 0xFFFF;
break; // Voice 0..23 Channel Noise mode (R/W)
case 0x1d96:
value = Regs.NON >> 16;
break;
case 0x1d98: value = Regs.VMIXEL&0xFFFF; break; // Voice 0..23 Channel Reverb mode (R/W)
case 0x1d9a: value = Regs.VMIXEL>>16; break;
case 0x1d98:
value = Regs.VMIXEL & 0xFFFF;
break; // Voice 0..23 Channel Reverb mode (R/W)
case 0x1d9a:
value = Regs.VMIXEL >> 16;
break;
/*case 0x1d9c: value = Regs.VMIXL&0xFFFF; break;*/ // this is wrong?
/*case 0x1d9e: value = Regs.VMIXL >> 16; break;*/
case 0x1d9c: value = Regs.ENDX & 0xFFFF; break;// Voice 0..23 Channel ON / OFF(status) (R) (ENDX)
case 0x1d9e: value = Regs.ENDX >> 16;
case 0x1d9c:
value = Regs.ENDX & 0xFFFF;
break; // Voice 0..23 Channel ON / OFF(status) (R) (ENDX)
case 0x1d9e:
value = Regs.ENDX >> 16;
case 0x1da2:
value = map_spu2to1(EffectsStartA);
@ -879,7 +957,8 @@ u16 V_Core::ReadRegPS1(u32 mem)
break;
}
if(show) FileLog("[%10d] (!) SPU read mem %08x value %04x\n",Cycles,mem,value);
if (show)
FileLog("[%10d] (!) SPU read mem %08x value %04x\n", Cycles, mem, value);
return value;
}
@ -912,8 +991,7 @@ static void __fastcall RegWrite_VoiceParams( u16 value )
V_Voice &thisvoice = Cores[core].Voices[voice];
switch (param)
{
switch (param) {
case 0: //VOLL (Volume L)
case 1: //VOLR (Volume R)
{
@ -925,10 +1003,9 @@ static void __fastcall RegWrite_VoiceParams( u16 value )
thisvol.Mode = (value & 0xF000) >> 12;
thisvol.Increment = (value & 0x7F);
// We're not sure slides work 100%
if( IsDevBuild ) ConLog("* SPU2: Voice uses Slides in Mode = %x, Increment = %x\n",thisvol.Mode,thisvol.Increment);
}
else
{
if (IsDevBuild)
ConLog("* SPU2: Voice uses Slides in Mode = %x, Increment = %x\n", thisvol.Mode, thisvol.Increment);
} else {
// Constant Volume mode (no slides or envelopes)
// Volumes range from 0x3fff to 0x7fff, with 0x4000 serving as
// the "sign" bit, so a simple bitwise extension will do the trick:
@ -937,11 +1014,11 @@ static void __fastcall RegWrite_VoiceParams( u16 value )
thisvol.Mode = 0;
thisvol.Increment = 0;
}
}
break;
} break;
case 2:
if (value > 0x3fff) ConLog( "* SPU2: Pitch setting too big: 0x%x\n", value);
if (value > 0x3fff)
ConLog("* SPU2: Pitch setting too big: 0x%x\n", value);
thisvoice.Pitch = value & 0x3fff;
break;
@ -960,8 +1037,12 @@ static void __fastcall RegWrite_VoiceParams( u16 value )
ConLog("* SPU2: Mysterious ADSR Volume Set to 0x%x\n", value);
break;
case 6: thisvoice.Volume.Left.RegSet( value ); break;
case 7: thisvoice.Volume.Right.RegSet( value ); break;
case 6:
thisvoice.Volume.Left.RegSet(value);
break;
case 7:
thisvoice.Volume.Right.RegSet(value);
break;
jNO_DEFAULT;
}
@ -975,8 +1056,7 @@ static void __fastcall RegWrite_VoiceAddr( u16 value )
V_Voice &thisvoice = Cores[core].Voices[voice];
switch (address)
{
switch (address) {
case 0: // SSA (Waveform Start Addr) (hiword, 4 bits only)
thisvoice.StartA = ((value & 0x0F) << 16) | (thisvoice.StartA & 0xFFF8);
if (IsDevBuild)
@ -1023,8 +1103,7 @@ static void __fastcall RegWrite_Core( u16 value )
const int core = CoreIdx;
V_Core &thiscore = Cores[core];
switch(omem)
{
switch (omem) {
case REG__1AC:
// ----------------------------------------------------------------------------
// 0x1ac / 0x5ac : direct-write to DMA address : special register (undocumented)
@ -1038,18 +1117,15 @@ static void __fastcall RegWrite_Core( u16 value )
// Performance Note: The PS2 Bios uses this extensively right before booting games,
// causing massive slowdown if we don't shortcut it here.
for( int i=0; i<2; i++ )
{
if(Cores[i].IRQEnable && (Cores[i].IRQA == thiscore.TSA))
{
for (int i = 0; i < 2; i++) {
if (Cores[i].IRQEnable && (Cores[i].IRQA == thiscore.TSA)) {
SetIrqCall(i);
}
}
thiscore.DmaWrite(value);
break;
case REG_C_ATTR:
{
case REG_C_ATTR: {
bool irqe = thiscore.IRQEnable;
int bit0 = thiscore.AttrBit0;
bool fxenable = thiscore.FxEnable;
@ -1069,33 +1145,28 @@ static void __fastcall RegWrite_Core( u16 value )
thiscore.Regs.STATX = 0;
thiscore.Regs.ATTR = value & 0x7fff;
if (fxenable && !thiscore.FxEnable
&& (thiscore.EffectsStartA != thiscore.ExtEffectsStartA
|| thiscore.EffectsEndA != thiscore.ExtEffectsEndA))
{
if (fxenable && !thiscore.FxEnable && (thiscore.EffectsStartA != thiscore.ExtEffectsStartA || thiscore.EffectsEndA != thiscore.ExtEffectsEndA)) {
thiscore.EffectsStartA = thiscore.ExtEffectsStartA;
thiscore.EffectsEndA = thiscore.ExtEffectsEndA;
thiscore.ReverbX = 0;
thiscore.RevBuffers.NeedsUpdated = true;
}
if(oldDmaMode != thiscore.DmaMode)
{
if (oldDmaMode != thiscore.DmaMode) {
// FIXME... maybe: if this mode was cleared in the middle of a DMA, should we interrupt it?
thiscore.Regs.STATX &= ~0x400; // ready to transfer
}
if(value&0x000E)
{
if(MsgToConsole()) ConLog("* SPU2-X: Core %d ATTR unknown bits SET! value=%04x\n",core,value);
if (value & 0x000E) {
if (MsgToConsole())
ConLog("* SPU2-X: Core %d ATTR unknown bits SET! value=%04x\n", core, value);
}
if(thiscore.AttrBit0!=bit0)
{
if(MsgToConsole()) ConLog("* SPU2-X: ATTR bit 0 set to %d\n",thiscore.AttrBit0);
if (thiscore.AttrBit0 != bit0) {
if (MsgToConsole())
ConLog("* SPU2-X: ATTR bit 0 set to %d\n", thiscore.AttrBit0);
}
if(thiscore.IRQEnable!=irqe)
{
if (thiscore.IRQEnable != irqe) {
//ConLog("* SPU2-X: Core%d IRQ %s at cycle %d. Current IRQA = %x Current EffectA = %x\n",
// core, ((thiscore.IRQEnable==0)?"disabled":"enabled"), Cycles, thiscore.IRQA, thiscore.EffectsStartA);
@ -1103,8 +1174,7 @@ static void __fastcall RegWrite_Core( u16 value )
Spdif.Info &= ~(4 << thiscore.Index);
}
}
break;
} break;
case REG_S_PMON:
for (int vc = 1; vc < 16; ++vc)
@ -1139,7 +1209,8 @@ static void __fastcall RegWrite_Core( u16 value )
SetHiWord(thiscore.Regs.reg_out, value); \
else \
SetLoWord(thiscore.Regs.reg_out, value); \
if( result == thiscore.Regs.reg_out ) break; \
if (result == thiscore.Regs.reg_out) \
break; \
\
const uint start_bit = (hiword) ? 16 : 0; \
const uint end_bit = (hiword) ? 24 : 16; \
@ -1179,8 +1250,7 @@ static void __fastcall RegWrite_Core( u16 value )
vx_SetSomeBits(VMIXER, WetR, true);
break;
case REG_P_MMIX:
{
case REG_P_MMIX: {
// Each MMIX gate is assigned either 0 or 0xffffffff depending on the status
// of the MMIX bits. I use -1 below as a shorthand for 0xffffffff. :)
@ -1198,8 +1268,7 @@ static void __fastcall RegWrite_Core( u16 value )
thiscore.DryGate.SndR = (vx & 0x400) ? -1 : 0;
thiscore.DryGate.SndL = (vx & 0x800) ? -1 : 0;
thiscore.Regs.MMIX = value;
}
break;
} break;
case (REG_S_KON + 2):
StartVoices(core, ((u32)value) << 16);
@ -1243,8 +1312,7 @@ static void __fastcall RegWrite_Core( u16 value )
//
case REG_A_ESA:
SetHiWord(thiscore.ExtEffectsStartA, value);
if (!thiscore.FxEnable)
{
if (!thiscore.FxEnable) {
thiscore.EffectsStartA = thiscore.ExtEffectsStartA;
thiscore.ReverbX = 0;
thiscore.RevBuffers.NeedsUpdated = true;
@ -1253,8 +1321,7 @@ static void __fastcall RegWrite_Core( u16 value )
case (REG_A_ESA + 2):
SetLoWord(thiscore.ExtEffectsStartA, value);
if (!thiscore.FxEnable)
{
if (!thiscore.FxEnable) {
thiscore.EffectsStartA = thiscore.ExtEffectsStartA;
thiscore.ReverbX = 0;
thiscore.RevBuffers.NeedsUpdated = true;
@ -1263,8 +1330,7 @@ static void __fastcall RegWrite_Core( u16 value )
case REG_A_EEA:
thiscore.ExtEffectsEndA = ((u32)value << 16) | 0xFFFF;
if (!thiscore.FxEnable)
{
if (!thiscore.FxEnable) {
thiscore.EffectsEndA = thiscore.ExtEffectsEndA;
thiscore.ReverbX = 0;
thiscore.RevBuffers.NeedsUpdated = true;
@ -1272,9 +1338,11 @@ static void __fastcall RegWrite_Core( u16 value )
break;
case REG_S_ADMAS:
if ( MsgToConsole() ) ConLog("* SPU2-X: Core %d AutoDMAControl set to %d (at cycle %d)\n",core,value, Cycles);
if (MsgToConsole())
ConLog("* SPU2-X: Core %d AutoDMAControl set to %d (at cycle %d)\n", core, value, Cycles);
if (psxmode) ConLog("* SPU2-X: Writing to REG_S_ADMAS while in PSX mode! value: %x",value);
if (psxmode)
ConLog("* SPU2-X: Writing to REG_S_ADMAS while in PSX mode! value: %x", value);
// hack for ps1driver which writes -1 (and never turns the adma off after psxlogo).
// adma isn't available in psx mode either
if (value == 32767) {
@ -1289,8 +1357,7 @@ static void __fastcall RegWrite_Core( u16 value )
Cores[1].RevBuffers.NeedsUpdated = true;
Cores[0].ReverbX = 0;
Cores[0].RevBuffers.NeedsUpdated = true;
for (uint v = 0; v < 24; ++v)
{
for (uint v = 0; v < 24; ++v) {
Cores[1].Voices[v].Volume = V_VolumeSlideLR(0, 0); // V_VolumeSlideLR::Max;
Cores[1].Voices[v].SCurrent = 28;
@ -1306,18 +1373,15 @@ static void __fastcall RegWrite_Core( u16 value )
}
thiscore.AutoDMACtrl = value;
if(value==0)
{
if (value == 0) {
thiscore.AdmaInProgress = 0;
}
break;
default:
{
default: {
const int addr = omem | ((core == 1) ? 0x400 : 0);
*(regtable[addr >> 1]) = value;
}
break;
} break;
}
}
@ -1327,13 +1391,11 @@ static void __fastcall RegWrite_CoreExt( u16 value )
V_Core &thiscore = Cores[CoreIdx];
const int core = CoreIdx;
switch(addr)
{
switch (addr) {
// Master Volume Address Write!
case REG_P_MVOLL:
case REG_P_MVOLR:
{
case REG_P_MVOLR: {
V_VolumeSlide &thisvol = (addr == REG_P_MVOLL) ? thiscore.MasterVol.Left : thiscore.MasterVol.Right;
if (value & 0x8000) // +Lin/-Lin/+Exp/-Exp
@ -1341,9 +1403,7 @@ static void __fastcall RegWrite_CoreExt( u16 value )
thisvol.Mode = (value & 0xF000) >> 12;
thisvol.Increment = (value & 0x7F);
//printf("slides Mode = %x, Increment = %x\n",thisvol.Mode,thisvol.Increment);
}
else
{
} else {
// Constant Volume mode (no slides or envelopes)
// Volumes range from 0x3fff to 0x7fff, with 0x4000 serving as
// the "sign" bit, so a simple bitwise extension will do the trick:
@ -1353,8 +1413,7 @@ static void __fastcall RegWrite_CoreExt( u16 value )
thisvol.Increment = 0;
}
thisvol.Reg_VOL = value;
}
break;
} break;
case REG_P_EVOLL:
thiscore.FxVol.Left = GetVol32(value);
@ -1380,12 +1439,10 @@ static void __fastcall RegWrite_CoreExt( u16 value )
thiscore.InpVol.Right = GetVol32(value);
break;
default:
{
default: {
const int raddr = addr + ((core == 1) ? 0x28 : 0);
*(regtable[raddr >> 1]) = value;
}
break;
} break;
}
}
@ -1700,23 +1757,24 @@ void StartVoices(int core, u32 value)
// Optimization: Games like to write zero to the KeyOn reg a lot, so shortcut
// this loop if value is zero.
if( value == 0 ) return;
if (value == 0)
return;
Cores[core].Regs.ENDX &= ~value;
Cores[core].KeyOn |= value;
for( u8 vc=0; vc<V_Core::NumVoices; vc++ )
{
if( !((value>>vc) & 1) ) continue;
for (u8 vc = 0; vc < V_Core::NumVoices; vc++) {
if (!((value >> vc) & 1))
continue;
Cores[core].Voices[vc].QueueStart();
if( IsDevBuild )
{
if (IsDevBuild) {
V_Voice &thisvc(Cores[core].Voices[vc]);
if(MsgKeyOnOff()) ConLog("* SPU2-X: KeyOn: C%dV%02d: SSA: %8x; M: %s%s%s%s; H: %04x; P: %04x V: %04x/%04x; ADSR: %04x%04x\n",
if (MsgKeyOnOff())
ConLog("* SPU2-X: KeyOn: C%dV%02d: SSA: %8x; M: %s%s%s%s; H: %04x; P: %04x V: %04x/%04x; ADSR: %04x%04x\n",
core, vc, thisvc.StartA,
(Cores[core].VoiceGates[vc].DryL) ? "+" : "-", (Cores[core].VoiceGates[vc].DryR) ? "+" : "-",
(Cores[core].VoiceGates[vc].WetL) ? "+" : "-", (Cores[core].VoiceGates[vc].WetR) ? "+" : "-",
@ -1730,13 +1788,14 @@ void StartVoices(int core, u32 value)
void StopVoices(int core, u32 value)
{
if( value == 0 ) return;
for( u8 vc=0; vc<V_Core::NumVoices; vc++ )
{
if( !((value>>vc) & 1) ) continue;
if (value == 0)
return;
for (u8 vc = 0; vc < V_Core::NumVoices; vc++) {
if (!((value >> vc) & 1))
continue;
Cores[core].Voices[vc].ADSR.Releasing = true;
if(MsgKeyOnOff()) ConLog("* SPU2-X: KeyOff: Core %d; Voice %d.\n",core,vc);
if (MsgKeyOnOff())
ConLog("* SPU2-X: KeyOff: Core %d; Voice %d.\n", core, vc);
}
}