SPU2: clang-format

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-09-25 14:42:06 +02:00 committed by refractionpcsx2
parent b0b4adea75
commit 6dc3966be9
57 changed files with 9163 additions and 8630 deletions

View File

@ -23,7 +23,8 @@ 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)
@ -42,9 +43,11 @@ 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;
@ -58,7 +61,8 @@ 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;
@ -74,12 +78,14 @@ 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
{
@ -93,26 +99,32 @@ 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;
@ -125,13 +137,16 @@ 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++;
}
@ -170,20 +185,26 @@ void V_VolumeSlide::Update()
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

@ -92,7 +92,7 @@ extern bool dspPluginEnabled;
namespace SoundtouchCfg
{
extern void ApplySettings(soundtouch::SoundTouch &sndtouch);
extern void ApplySettings(soundtouch::SoundTouch& sndtouch);
}
//////

View File

@ -19,9 +19,9 @@ int crazy_debug = 0;
char s[4096];
FILE *spu2Log = NULL;
FILE* spu2Log = NULL;
void FileLog(const char *fmt, ...)
void FileLog(const char* fmt, ...)
{
#ifdef SPU2_LOG
va_list list;
@ -52,7 +52,7 @@ 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, ...)
void ConLog(const char* fmt, ...)
{
if (!MsgToConsole())
return;
@ -65,13 +65,14 @@ void ConLog(const char *fmt, ...)
fputs(s, stderr);
fflush(stderr);
if (spu2Log) {
if (spu2Log)
{
fputs(s, spu2Log);
fflush(spu2Log);
}
}
void V_VolumeSlide::DebugDump(FILE *dump, const char *title, const char *nameLR)
void V_VolumeSlide::DebugDump(FILE* dump, const char* title, const char* nameLR)
{
fprintf(dump, "%s Volume for %s Channel:\t%x\n"
" - Value: %x\n"
@ -80,13 +81,13 @@ void V_VolumeSlide::DebugDump(FILE *dump, const char *title, const char *nameLR)
title, nameLR, Reg_VOL, Value, Mode, Increment);
}
void V_VolumeSlideLR::DebugDump(FILE *dump, const char *title)
void V_VolumeSlideLR::DebugDump(FILE* dump, const char* title)
{
Left.DebugDump(dump, title, "Left");
Right.DebugDump(dump, title, "Right");
}
void V_VolumeLR::DebugDump(FILE *dump, const char *title)
void V_VolumeLR::DebugDump(FILE* dump, const char* title)
{
fprintf(dump, "Volume for %s (%s Channel):\t%x\n", title, "Left", Left);
fprintf(dump, "Volume for %s (%s Channel):\t%x\n", title, "Right", Right);
@ -96,19 +97,23 @@ void DoFullDump()
{
#ifdef _MSC_VER
#ifdef SPU2_LOG
FILE *dump;
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);
}
@ -117,8 +122,10 @@ void DoFullDump()
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");
@ -159,7 +166,8 @@ 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, "");
@ -207,8 +215,10 @@ 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

@ -16,20 +16,21 @@
#ifndef DEBUG_H_INCLUDED
#define DEBUG_H_INCLUDED
extern FILE *spu2Log;
extern FILE* spu2Log;
extern void FileLog(const char *fmt, ...);
extern void ConLog(const char *fmt, ...);
extern void FileLog(const char* fmt, ...);
extern void ConLog(const char* fmt, ...);
extern void DoFullDump();
extern FILE *OpenBinaryLog(const wxString &logfile);
extern FILE *OpenLog(const wxString &logfile);
extern FILE *OpenDump(const wxString &logfile);
extern FILE* OpenBinaryLog(const wxString& logfile);
extern FILE* OpenLog(const wxString& logfile);
extern FILE* OpenDump(const wxString& logfile);
namespace WaveDump
{
enum CoreSourceType {
enum CoreSourceType
{
// Core's input stream, usually pulled from ADMA streams.
CoreSrc_Input = 0,
@ -50,19 +51,19 @@ enum CoreSourceType {
CoreSrc_External,
CoreSrc_Count
};
};
extern void Open();
extern void Close();
extern void WriteCore(uint coreidx, CoreSourceType src, s16 left, s16 right);
extern void WriteCore(uint coreidx, CoreSourceType src, const StereoOut16 &sample);
}
extern void Open();
extern void Close();
extern void WriteCore(uint coreidx, CoreSourceType src, s16 left, s16 right);
extern void WriteCore(uint coreidx, CoreSourceType src, const StereoOut16& sample);
} // namespace WaveDump
using WaveDump::CoreSrc_Input;
using WaveDump::CoreSrc_DryVoiceMix;
using WaveDump::CoreSrc_WetVoiceMix;
using WaveDump::CoreSrc_PreReverb;
using WaveDump::CoreSrc_PostReverb;
using WaveDump::CoreSrc_External;
using WaveDump::CoreSrc_Input;
using WaveDump::CoreSrc_PostReverb;
using WaveDump::CoreSrc_PreReverb;
using WaveDump::CoreSrc_WetVoiceMix;
#endif // DEBUG_H_INCLUDED //

View File

@ -20,13 +20,13 @@
extern u8 callirq;
static FILE *DMA4LogFile = NULL;
static FILE *DMA7LogFile = NULL;
static FILE *ADMA4LogFile = NULL;
static FILE *ADMA7LogFile = NULL;
static FILE *ADMAOutLogFile = NULL;
static FILE* DMA4LogFile = NULL;
static FILE* DMA7LogFile = NULL;
static FILE* ADMA4LogFile = NULL;
static FILE* ADMA7LogFile = NULL;
static FILE* ADMAOutLogFile = NULL;
static FILE *REGWRTLogFile[2] = {0, 0};
static FILE* REGWRTLogFile[2] = {0, 0};
void DMALogOpen()
{
@ -39,7 +39,7 @@ void DMALogOpen()
ADMAOutLogFile = OpenBinaryLog(L"admaOut.raw");
}
void DMA4LogWrite(void *lpData, u32 ulSize)
void DMA4LogWrite(void* lpData, u32 ulSize)
{
if (!DMALog())
return;
@ -48,7 +48,7 @@ void DMA4LogWrite(void *lpData, u32 ulSize)
fwrite(lpData, ulSize, 1, DMA4LogFile);
}
void DMA7LogWrite(void *lpData, u32 ulSize)
void DMA7LogWrite(void* lpData, u32 ulSize)
{
if (!DMALog())
return;
@ -57,7 +57,7 @@ void DMA7LogWrite(void *lpData, u32 ulSize)
fwrite(lpData, ulSize, 1, DMA7LogFile);
}
void ADMAOutLogWrite(void *lpData, u32 ulSize)
void ADMAOutLogWrite(void* lpData, u32 ulSize)
{
if (!DMALog())
return;
@ -86,7 +86,7 @@ void DMALogClose()
safe_fclose(ADMAOutLogFile);
}
void V_Core::LogAutoDMA(FILE *fp)
void V_Core::LogAutoDMA(FILE* fp)
{
if (!DMALog() || !fp || !DMAPtr)
return;
@ -103,14 +103,17 @@ 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);
@ -125,11 +128,11 @@ void V_Core::AutoDMAReadBuffer(int mode) //mode: 0= split stereo; 1 = do not spl
InputDataLeft -= 0x100;
InputDataProgress += 0x100;
}
// See ReadInput at mixer.cpp for explanation on the commented out lines
//
// See ReadInput at mixer.cpp for explanation on the commented out lines
//
}
void V_Core::StartADMAWrite(u16 *pMem, u32 sz)
void V_Core::StartADMAWrite(u16* pMem, u32 sz)
{
int size = (sz) & (~511);
@ -138,16 +141,23 @@ void V_Core::StartADMAWrite(u16 *pMem, u32 sz)
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
@ -162,7 +172,9 @@ void V_Core::StartADMAWrite(u16 *pMem, u32 sz)
}
AdmaInProgress = 1;
} else {
}
else
{
InputDataLeft = 0;
DMAICounter = 1;
}
@ -186,21 +198,23 @@ void V_Core::StartADMAWrite(u16 *pMem, u32 sz)
// Update: This hack is no longer needed when we don't do a core reset. Guess the null pc was in spu2 memory?
#define NO_BIOS_HACKFIX 1 // set to 1 to disable the hackfix
void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
void V_Core::PlainDMAWrite(u16* pMem, u32 size)
{
// Perform an alignment check.
// Not really important. Everything should work regardless,
// but it could be indicative of an emulation foopah elsewhere.
if (MsgToConsole()) {
if (MsgToConsole())
{
// Don't need this anymore. Target may still be good to know though.
/*if((uptr)pMem & 15)
{
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) {
ConLog("* SPU2 DMA Write > Misaligned target. Core: %d IOP: %p TSA: 0x%x Size: 0x%x\n", Index, (void *)pMem, TSA, size);
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);
}
}
@ -213,17 +227,19 @@ 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;
}
const int cacheIdxStart = TSA / pcm_WordsPerBlock;
const int cacheIdxEnd = (buff1end + pcm_WordsPerBlock - 1) / pcm_WordsPerBlock;
PcmCacheEntry *cacheLine = &pcm_cache_data[cacheIdxStart];
PcmCacheEntry &cacheEnd = pcm_cache_data[cacheIdxEnd];
PcmCacheEntry* cacheLine = &pcm_cache_data[cacheIdxStart];
PcmCacheEntry& cacheEnd = pcm_cache_data[cacheIdxEnd];
do {
do
{
cacheLine->Validated = false;
cacheLine++;
} while (cacheLine != &cacheEnd);
@ -240,7 +256,8 @@ 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
@ -255,12 +272,13 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
memcpy(GetMemPtr(0), &pMem[buff1size], buff2end * 2);
TDA = (buff2end + 1) & 0xfffff;
// Flag interrupt? If IRQA occurs between start and dest, flag it.
// Important: Test both core IRQ settings for either DMA!
// Note: Because this buffer wraps, we use || instead of &&
// Flag interrupt? If IRQA occurs between start and dest, flag it.
// Important: Test both core IRQ settings for either DMA!
// 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?)
@ -270,7 +288,8 @@ 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);
}
@ -281,24 +300,29 @@ 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...
TDA = (buff1end + 1) & 0xfffff;
// Flag interrupt? If IRQA occurs between start and dest, flag it.
// Important: Test both core IRQ settings for either DMA!
// Flag interrupt? If IRQA occurs between start and dest, flag it.
// 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
@ -309,13 +333,14 @@ void V_Core::PlainDMAWrite(u16 *pMem, u32 size)
TADR = MADR + (size << 1);
}
void V_Core::DoDMAread(u16 *pMem, u32 size)
void V_Core::DoDMAread(u16* pMem, u32 size)
{
TSA &= 0xfffff;
u32 buff1end = TSA + size;
u32 buff2end = 0;
if (buff1end > 0x100000) {
if (buff1end > 0x100000)
{
buff2end = buff1end - 0x100000;
buff1end = 0x100000;
}
@ -329,7 +354,8 @@ 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
@ -341,12 +367,16 @@ 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...
@ -355,8 +385,10 @@ 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);
}
}
@ -370,11 +402,12 @@ void V_Core::DoDMAread(u16 *pMem, u32 size)
TADR = MADR + (size << 1);
}
void V_Core::DoDMAwrite(u16 *pMem, u32 size)
void V_Core::DoDMAwrite(u16* pMem, u32 size)
{
DMAPtr = pMem;
if (size < 2) {
if (size < 2)
{
Regs.STATX &= ~0x80;
//Regs.ATTR |= 0x30;
DMAICounter = 1;
@ -382,13 +415,16 @@ void V_Core::DoDMAwrite(u16 *pMem, u32 size)
return;
}
if (IsDevBuild) {
if (IsDevBuild)
{
DebugCores[Index].lastsize = size;
DebugCores[Index].dmaFlag = 2;
}
if (MsgToConsole()) {
if (TSA > 0xfffff) {
if (MsgToConsole())
{
if (TSA > 0xfffff)
{
ConLog("* SPU2-X: Transfer Start Address out of bounds. TSA is %x\n", TSA);
}
}
@ -397,10 +433,13 @@ 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 {
}
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,
@ -409,5 +448,5 @@ void V_Core::DoDMAwrite(u16 *pMem, u32 size)
PlainDMAWrite(pMem, size);
}
Regs.STATX &= ~0x80;
//Regs.ATTR |= 0x30;
//Regs.ATTR |= 0x30;
}

View File

@ -16,6 +16,6 @@
#pragma once
extern void DMALogOpen();
extern void DMA4LogWrite(void *lpData, u32 ulSize);
extern void DMA7LogWrite(void *lpData, u32 ulSize);
extern void DMA4LogWrite(void* lpData, u32 ulSize);
extern void DMA7LogWrite(void* lpData, u32 ulSize);
extern void DMALogClose();

View File

@ -65,7 +65,7 @@ extern void ResetDplIIDecoder()
AccR = 0;
}
void ProcessDplIISample32(const StereoOut32 &src, Stereo51Out32DplII *s)
void ProcessDplIISample32(const StereoOut32& src, Stereo51Out32DplII* s)
{
float IL = src.Left / (float)(1 << (SndOutVolumeShift + 16));
float IR = src.Right / (float)(1 << (SndOutVolumeShift + 16));
@ -120,7 +120,7 @@ void ProcessDplIISample32(const StereoOut32 &src, Stereo51Out32DplII *s)
s->RightBack = (s32)(SR * GainSR);
}
void ProcessDplIISample16(const StereoOut32 &src, Stereo51Out16DplII *s)
void ProcessDplIISample16(const StereoOut32& src, Stereo51Out16DplII* s)
{
Stereo51Out32DplII ss;
ProcessDplIISample32(src, &ss);
@ -133,7 +133,7 @@ void ProcessDplIISample16(const StereoOut32 &src, Stereo51Out16DplII *s)
s->RightBack = ss.RightBack >> 16;
}
void ProcessDplSample32(const StereoOut32 &src, Stereo51Out32Dpl *s)
void ProcessDplSample32(const StereoOut32& src, Stereo51Out32Dpl* s)
{
float ValL = src.Left / (float)(1 << (SndOutVolumeShift + 16));
float ValR = src.Right / (float)(1 << (SndOutVolumeShift + 16));
@ -156,7 +156,7 @@ void ProcessDplSample32(const StereoOut32 &src, Stereo51Out32Dpl *s)
s->RightBack = (s32)(S * GainSR);
}
void ProcessDplSample16(const StereoOut32 &src, Stereo51Out16Dpl *s)
void ProcessDplSample16(const StereoOut32& src, Stereo51Out16Dpl* s)
{
Stereo51Out32Dpl ss;
ProcessDplSample32(src, &ss);

View File

@ -27,7 +27,7 @@ struct V_Core;
namespace soundtouch
{
class SoundTouch;
class SoundTouch;
}
#include <assert.h>
@ -44,9 +44,9 @@ class SoundTouch;
namespace VersionInfo
{
static const u8 Release = 2;
static const u8 Revision = 0; // increase that with each version
}
static const u8 Release = 2;
static const u8 Revision = 0; // increase that with each version
} // namespace VersionInfo
//////////////////////////////////////////////////////////////////////////
// Override Win32 min/max macros with the STL's type safe and macro
@ -56,7 +56,7 @@ static const u8 Revision = 0; // increase that with each version
#undef max
template <typename T>
static __forceinline void Clampify(T &src, T min, T max)
static __forceinline void Clampify(T& src, T min, T max)
{
src = std::min(std::max(src, min), max);
}
@ -69,9 +69,9 @@ static __forceinline T GetClamped(T src, T min, T max)
#ifdef __WXMAC__
#else
extern void SysMessage(const char *fmt, ...);
extern void SysMessage(const char* fmt, ...);
#endif
extern void SysMessage(const wchar_t *fmt, ...);
extern void SysMessage(const wchar_t* fmt, ...);
//////////////////////////////////////////////////////////////
// Dev / Debug conditionals --
@ -100,4 +100,3 @@ extern void SysMessage(const wchar_t *fmt, ...);
#include "Config.h"
#include "Debug.h"
#include "SndOut.h"

View File

@ -32,9 +32,9 @@ protected:
static const int NumBuffers = 4; // TODO: this should be configurable someday -- lower values reduce latency.
unsigned int pspeed;
snd_pcm_t *handle;
snd_pcm_t* handle;
snd_pcm_uframes_t buffer_size;
snd_async_handler_t *pcm_callback;
snd_async_handler_t* pcm_callback;
uint period_time;
uint buffer_time;
@ -47,9 +47,10 @@ 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;
StereoOut16* p1 = buff;
for (int p = 0; p < PacketsPerBuffer; p++, p1 += SndOutPacketSize)
SndBuffer::ReadSamples(p1);
@ -61,16 +62,17 @@ protected:
// Preps and invokes the _InternalCallback above. This provides a cdecl-compliant
// entry point for our C++ified object state. :)
static void ExternalCallback(snd_async_handler_t *pcm_call)
static void ExternalCallback(snd_async_handler_t* pcm_call)
{
fprintf(stderr, "* SPU2-X:Iz in your external callback.\n");
AlsaMod *data = (AlsaMod *)snd_async_handler_get_callback_private(pcm_call);
AlsaMod* data = (AlsaMod*)snd_async_handler_get_callback_private(pcm_call);
pxAssume(data != NULL);
//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;
}
@ -82,9 +84,9 @@ public:
s32 Init()
{
//fprintf(stderr,"* SPU2-X: Initing Alsa\n");
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
snd_pcm_status_t *status;
snd_pcm_hw_params_t* hwparams;
snd_pcm_sw_params_t* swparams;
snd_pcm_status_t* status;
int pchannels = 2;
snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE;
@ -100,13 +102,15 @@ 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;
}
@ -115,55 +119,64 @@ 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;
}
err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0);
if (err < 0) {
if (err < 0)
{
fprintf(stderr, "Buffer time error: %s\n", snd_strerror(err));
return -1;
}
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;
}
@ -177,7 +190,8 @@ public:
// 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;
}
@ -212,7 +226,8 @@ public:
int GetEmptySampleCount()
{
if (handle == NULL) {
if (handle == NULL)
{
fprintf(stderr, "Handle is NULL!\n");
return 0;
}
@ -224,12 +239,12 @@ public:
return (l / 1000) * (SampleRate / 1000);
}
const wchar_t *GetIdent() const
const wchar_t* GetIdent() const
{
return L"Alsa";
}
const wchar_t *GetLongName() const
const wchar_t* GetLongName() const
{
return L"Alsa";
}
@ -247,6 +262,6 @@ public:
}
} static Alsa;
SndOutModule *AlsaOut = &Alsa;
SndOutModule* AlsaOut = &Alsa;
#endif

View File

@ -30,11 +30,11 @@
extern int AlsaSetupSound();
extern void AlsaRemoveSound();
extern int AlsaSoundGetBytesBuffered();
extern void AlsaSoundFeedVoiceData(unsigned char *pSound, long lBytes);
extern void AlsaSoundFeedVoiceData(unsigned char* pSound, long lBytes);
extern int SetupSound();
extern void RemoveSound();
extern int SoundGetBytesBuffered();
extern void SoundFeedVoiceData(unsigned char *pSound, long lBytes);
extern void SoundFeedVoiceData(unsigned char* pSound, long lBytes);
#endif // __LINUX_H__

View File

@ -16,7 +16,7 @@
#include "Dialogs.h"
#include <wx/fileconf.h>
wxFileConfig *spuConfig = nullptr;
wxFileConfig* spuConfig = nullptr;
wxString path(L"~/.config/PCSX2/inis/SPU2.ini");
bool pathSet = false;
@ -26,44 +26,44 @@ void initIni()
spuConfig = new wxFileConfig(L"", L"", path, L"", wxCONFIG_USE_LOCAL_FILE);
}
void setIni(const wchar_t *Section)
void setIni(const wchar_t* Section)
{
initIni();
spuConfig->SetPath(wxsFormat(L"/%s", Section));
}
void CfgSetSettingsDir(const char *dir)
void CfgSetSettingsDir(const char* dir)
{
FileLog("CfgSetSettingsDir(%s)\n", dir);
path = wxString::FromUTF8(dir) + L"/SPU2.ini";
pathSet = true;
}
void CfgWriteBool(const wchar_t *Section, const wchar_t *Name, bool Value)
void CfgWriteBool(const wchar_t* Section, const wchar_t* Name, bool Value)
{
setIni(Section);
spuConfig->Write(Name, Value);
}
void CfgWriteInt(const wchar_t *Section, const wchar_t *Name, int Value)
void CfgWriteInt(const wchar_t* Section, const wchar_t* Name, int Value)
{
setIni(Section);
spuConfig->Write(Name, Value);
}
void CfgWriteFloat(const wchar_t *Section, const wchar_t *Name, float Value)
void CfgWriteFloat(const wchar_t* Section, const wchar_t* Name, float Value)
{
setIni(Section);
spuConfig->Write(Name, (double)Value);
}
void CfgWriteStr(const wchar_t *Section, const wchar_t *Name, const wxString &Data)
void CfgWriteStr(const wchar_t* Section, const wchar_t* Name, const wxString& Data)
{
setIni(Section);
spuConfig->Write(Name, Data);
}
bool CfgReadBool(const wchar_t *Section, const wchar_t *Name, bool Default)
bool CfgReadBool(const wchar_t* Section, const wchar_t* Name, bool Default)
{
bool ret;
@ -73,7 +73,7 @@ bool CfgReadBool(const wchar_t *Section, const wchar_t *Name, bool Default)
return ret;
}
int CfgReadInt(const wchar_t *Section, const wchar_t *Name, int Default)
int CfgReadInt(const wchar_t* Section, const wchar_t* Name, int Default)
{
int ret;
@ -83,7 +83,7 @@ int CfgReadInt(const wchar_t *Section, const wchar_t *Name, int Default)
return ret;
}
float CfgReadFloat(const wchar_t *Section, const wchar_t *Name, float Default)
float CfgReadFloat(const wchar_t* Section, const wchar_t* Name, float Default)
{
double ret;
@ -93,13 +93,13 @@ float CfgReadFloat(const wchar_t *Section, const wchar_t *Name, float Default)
return (float)ret;
}
void CfgReadStr(const wchar_t *Section, const wchar_t *Name, wchar_t *Data, int DataSize, const wchar_t *Default)
void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wchar_t* Data, int DataSize, const wchar_t* Default)
{
setIni(Section);
wcscpy(Data, spuConfig->Read(Name, Default).wc_str());
}
void CfgReadStr(const wchar_t *Section, const wchar_t *Name, wxString &Data, const wchar_t *Default)
void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wxString& Data, const wchar_t* Default)
{
setIni(Section);
Data = spuConfig->Read(Name, Default);

View File

@ -81,7 +81,8 @@ 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;
}
@ -142,7 +143,8 @@ void ReadSettings()
SdlOutputAPI = 0;
#if SDL_MAJOR_VERSION >= 2
// YES It sucks ...
for (int i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
for (int i = 0; i < SDL_GetNumAudioDrivers(); ++i)
{
if (!temp.Cmp(wxString(SDL_GetAudioDriver(i), wxConvUTF8)))
SdlOutputAPI = i;
}
@ -167,7 +169,8 @@ void ReadSettings()
Clampify(SndOutLatencyMS, LATENCY_MIN, LATENCY_MAX);
if (mods[OutputModule] == nullptr) {
if (mods[OutputModule] == nullptr)
{
fwprintf(stderr, L"* SPU2-X: Unknown output module '%s' specified in configuration file.\n", temp.wc_str());
fprintf(stderr, "* SPU2-X: Defaulting to SDL (%S).\n", SDLOut->GetIdent());
OutputModule = FindOutputModuleById(SDLOut->GetIdent());
@ -181,7 +184,8 @@ void ReadSettings()
void WriteSettings()
{
if (!pathSet) {
if (!pathSet)
{
FileLog("Write called without the path set.\n");
return;
}
@ -219,7 +223,7 @@ void WriteSettings()
void configure()
{
auto *dialog = new Dialog;
auto* dialog = new Dialog;
initIni();
ReadSettings();

View File

@ -97,21 +97,21 @@ const int LATENCY_MIN_TIMESTRETCH = 15;
namespace SoundtouchCfg
{
extern const int SequenceLen_Min;
extern const int SequenceLen_Max;
extern const int SequenceLen_Min;
extern const int SequenceLen_Max;
extern const int SeekWindow_Min;
extern const int SeekWindow_Max;
extern const int SeekWindow_Min;
extern const int SeekWindow_Max;
extern const int Overlap_Min;
extern const int Overlap_Max;
extern const int Overlap_Min;
extern const int Overlap_Max;
extern int SequenceLenMS;
extern int SeekWindowMS;
extern int OverlapMS;
extern int SequenceLenMS;
extern int SeekWindowMS;
extern int OverlapMS;
void ReadSettings();
void WriteSettings();
void ReadSettings();
void WriteSettings();
}; // namespace SoundtouchCfg
void ReadSettings();
@ -119,7 +119,7 @@ void WriteSettings();
void DisplayDialog();
void configure();
extern wxFileConfig *spuConfig;
extern wxFileConfig* spuConfig;
extern bool pathSet;
extern void initIni();
#endif // CONFIG_H_INCLUDED

View File

@ -51,34 +51,34 @@ wxString CoresDumpFileName;
wxString MemDumpFileName;
wxString RegDumpFileName;
void CfgSetLogDir(const char *dir)
void CfgSetLogDir(const char* dir)
{
LogsFolder = (dir == NULL) ? wxString(L"logs") : fromUTF8(dir);
DumpsFolder = (dir == NULL) ? wxString(L"logs") : fromUTF8(dir);
LogLocationSetByPcsx2 = (dir != NULL);
}
FILE *OpenBinaryLog(const wxString &logfile)
FILE* OpenBinaryLog(const wxString& logfile)
{
return wxFopen(Path::Combine(LogsFolder, logfile), L"wb");
}
FILE *OpenLog(const wxString &logfile)
FILE* OpenLog(const wxString& logfile)
{
return wxFopen(Path::Combine(LogsFolder, logfile), L"w");
}
FILE *OpenDump(const wxString &logfile)
FILE* OpenDump(const wxString& logfile)
{
return wxFopen(Path::Combine(DumpsFolder, logfile), L"w");
}
namespace DebugConfig
{
static const wchar_t *Section = L"DEBUG";
static const wchar_t* Section = L"DEBUG";
static void set_default_filenames()
{
static void set_default_filenames()
{
AccessLogFileName = L"SPU2Log.txt";
WaveLogFileName = L"SPU2log.wav";
DMA4LogFileName = L"SPU2dma4.dat";
@ -87,10 +87,10 @@ static void set_default_filenames()
CoresDumpFileName = L"SPU2Cores.txt";
MemDumpFileName = L"SPU2mem.dat";
RegDumpFileName = L"SPU2regs.dat";
}
}
void ReadSettings()
{
void ReadSettings()
{
DebugEnabled = CfgReadBool(Section, L"Global_Enable", 0);
_MsgToConsole = CfgReadBool(Section, L"Show_Messages", 0);
_MsgKeyOnOff = CfgReadBool(Section, L"Show_Messages_Key_On_Off", 0);
@ -118,11 +118,11 @@ void ReadSettings()
CfgReadStr(Section, L"Info_Dump_Filename", CoresDumpFileName, L"logs/SPU2Cores.txt");
CfgReadStr(Section, L"Mem_Dump_Filename", MemDumpFileName, L"logs/SPU2mem.dat");
CfgReadStr(Section, L"Reg_Dump_Filename", RegDumpFileName, L"logs/SPU2regs.dat");
}
}
void WriteSettings()
{
void WriteSettings()
{
CfgWriteBool(Section, L"Global_Enable", DebugEnabled);
CfgWriteBool(Section, L"Show_Messages", _MsgToConsole);
@ -150,6 +150,6 @@ void WriteSettings()
CfgWriteStr(Section, L"Info_Dump_Filename", CoresDumpFileName);
CfgWriteStr(Section, L"Mem_Dump_Filename", MemDumpFileName);
CfgWriteStr(Section, L"Reg_Dump_Filename", RegDumpFileName);
}
}
} // namespace DebugConfig

View File

@ -20,49 +20,49 @@
namespace SoundtouchCfg
{
// Timestretch Slider Bounds, Min/Max
const int SequenceLen_Min = 20;
const int SequenceLen_Max = 100;
// Timestretch Slider Bounds, Min/Max
const int SequenceLen_Min = 20;
const int SequenceLen_Max = 100;
const int SeekWindow_Min = 10;
const int SeekWindow_Max = 30;
const int SeekWindow_Min = 10;
const int SeekWindow_Max = 30;
const int Overlap_Min = 5;
const int Overlap_Max = 15;
const int Overlap_Min = 5;
const int Overlap_Max = 15;
int SequenceLenMS = 30;
int SeekWindowMS = 20;
int OverlapMS = 10;
int SequenceLenMS = 30;
int SeekWindowMS = 20;
int OverlapMS = 10;
static void ClampValues()
{
static void ClampValues()
{
Clampify(SequenceLenMS, SequenceLen_Min, SequenceLen_Max);
Clampify(SeekWindowMS, SeekWindow_Min, SeekWindow_Max);
Clampify(OverlapMS, Overlap_Min, Overlap_Max);
}
}
void ApplySettings(soundtouch::SoundTouch &sndtouch)
{
void ApplySettings(soundtouch::SoundTouch& sndtouch)
{
sndtouch.setSetting(SETTING_SEQUENCE_MS, SequenceLenMS);
sndtouch.setSetting(SETTING_SEEKWINDOW_MS, SeekWindowMS);
sndtouch.setSetting(SETTING_OVERLAP_MS, OverlapMS);
}
}
void ReadSettings()
{
void ReadSettings()
{
SequenceLenMS = CfgReadInt(L"SOUNDTOUCH", L"SequenceLengthMS", 30);
SeekWindowMS = CfgReadInt(L"SOUNDTOUCH", L"SeekWindowMS", 20);
OverlapMS = CfgReadInt(L"SOUNDTOUCH", L"OverlapMS", 10);
ClampValues();
WriteSettings();
}
}
void WriteSettings()
{
void WriteSettings()
{
CfgWriteInt(L"SOUNDTOUCH", L"SequenceLengthMS", SequenceLenMS);
CfgWriteInt(L"SOUNDTOUCH", L"SeekWindowMS", SeekWindowMS);
CfgWriteInt(L"SOUNDTOUCH", L"OverlapMS", OverlapMS);
}
}
} // namespace SoundtouchCfg

View File

@ -21,7 +21,7 @@
#if defined(__unix__)
#include <wx/wx.h>
void SysMessage(const char *fmt, ...)
void SysMessage(const char* fmt, ...)
{
va_list list;
char msg[512];
@ -37,7 +37,7 @@ void SysMessage(const char *fmt, ...)
dialog.ShowModal();
}
void SysMessage(const wchar_t *fmt, ...)
void SysMessage(const wchar_t* fmt, ...)
{
va_list list;
va_start(list, fmt);
@ -54,7 +54,7 @@ void DspUpdate()
{
}
s32 DspLoadLibrary(wchar_t *fileName, int modnum)
s32 DspLoadLibrary(wchar_t* fileName, int modnum)
{
return 0;
}

View File

@ -21,22 +21,22 @@
namespace DebugConfig
{
extern void ReadSettings();
extern void WriteSettings();
extern void ReadSettings();
extern void WriteSettings();
} // namespace DebugConfig
extern void CfgSetSettingsDir(const char *dir);
extern void CfgSetLogDir(const char *dir);
extern void CfgSetSettingsDir(const char* dir);
extern void CfgSetLogDir(const char* dir);
extern void CfgWriteBool(const wchar_t *Section, const wchar_t *Name, bool Value);
extern void CfgWriteInt(const wchar_t *Section, const wchar_t *Name, int Value);
extern void CfgWriteFloat(const wchar_t *Section, const wchar_t *Name, float Value);
extern void CfgWriteStr(const wchar_t *Section, const wchar_t *Name, const wxString &Data);
extern void CfgWriteBool(const wchar_t* Section, const wchar_t* Name, bool Value);
extern void CfgWriteInt(const wchar_t* Section, const wchar_t* Name, int Value);
extern void CfgWriteFloat(const wchar_t* Section, const wchar_t* Name, float Value);
extern void CfgWriteStr(const wchar_t* Section, const wchar_t* Name, const wxString& Data);
extern bool CfgReadBool(const wchar_t *Section, const wchar_t *Name, bool Default);
extern void CfgReadStr(const wchar_t *Section, const wchar_t *Name, wxString &Data, const wchar_t *Default);
extern bool CfgReadBool(const wchar_t* Section, const wchar_t* Name, bool Default);
extern void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wxString& Data, const wchar_t* Default);
//extern void CfgReadStr(const wchar_t* Section, const wchar_t* Name, wchar_t* Data, int DataSize, const wchar_t* Default);
extern int CfgReadInt(const wchar_t *Section, const wchar_t *Name, int Default);
extern float CfgReadFloat(const wchar_t *Section, const wchar_t *Name, float Default);
extern int CfgReadInt(const wchar_t* Section, const wchar_t* Name, int Default);
extern float CfgReadFloat(const wchar_t* Section, const wchar_t* Name, float Default);
#endif

View File

@ -20,7 +20,7 @@
// disable the optimisation until we can tie it to the game database.
#define NEVER_SKIP_VOICES 1
void ADMAOutLogWrite(void *lpData, u32 ulSize);
void ADMAOutLogWrite(void* lpData, u32 ulSize);
static const s32 tbl_XA_Factor[16][2] =
{
@ -65,7 +65,7 @@ __forceinline
// do it but it still experimental...
#endif
StereoOut32
clamp_mix(const StereoOut32 &sample, u8 bitshift)
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.
@ -75,7 +75,7 @@ __forceinline
GetClamped(sample.Right, -(0x7f00 << bitshift), 0x7f00 << bitshift));
}
static void __forceinline XA_decode_block(s16 *buffer, const s16 *block, s32 &prev1, s32 &prev2)
static void __forceinline XA_decode_block(s16* buffer, const s16* block, s32& prev1, s32& prev2)
{
const s32 header = *block;
const s32 shift = (header & 0xF) + 16;
@ -85,10 +85,11 @@ static void __forceinline XA_decode_block(s16 *buffer, const s16 *block, s32 &pr
const s32 pred1 = tbl_XA_Factor[id][0];
const s32 pred2 = tbl_XA_Factor[id][1];
const s8 *blockbytes = (s8 *)&block[1];
const s8 *blockend = &blockbytes[13];
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);
@ -106,15 +107,17 @@ static void __forceinline XA_decode_block(s16 *buffer, const s16 *block, s32 &pr
}
}
static void __forceinline IncrementNextA(V_Core &thiscore, uint voiceidx)
static void __forceinline IncrementNextA(V_Core& thiscore, uint voiceidx)
{
V_Voice &vc(thiscore.Voices[voiceidx]);
V_Voice& vc(thiscore.Voices[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);
@ -129,7 +132,7 @@ static void __forceinline IncrementNextA(V_Core &thiscore, uint voiceidx)
// decoded pcm data, used to cache the decoded data so that it needn't be decoded
// multiple times. Cache chunks are decoded when the mixer requests the blocks, and
// invalided when DMA transfers and memory writes are performed.
PcmCacheEntry *pcm_cache_data = NULL;
PcmCacheEntry* pcm_cache_data = NULL;
int g_counter_cache_hits = 0;
int g_counter_cache_misses = 0;
@ -144,32 +147,38 @@ int g_counter_cache_ignores = 0;
#define XAFLAG_LOOP (1ul << 1)
#define XAFLAG_LOOP_START (1ul << 2)
static __forceinline s32 GetNextDataBuffered(V_Core &thiscore, uint voiceidx)
static __forceinline s32 GetNextDataBuffered(V_Core& thiscore, uint voiceidx)
{
V_Voice &vc(thiscore.Voices[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 (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:
@ -178,17 +187,18 @@ static __forceinline s32 GetNextDataBuffered(V_Core &thiscore, uint voiceidx)
if (Cores[i].IRQEnable && Cores[i].IRQA == (vc.NextA & 0xFFFF8))
SetIrqCall(i);
s16 *memptr = GetMemPtr(vc.NextA & 0xFFFF8);
s16* memptr = GetMemPtr(vc.NextA & 0xFFFF8);
vc.LoopFlags = *memptr >> 8; // grab loop flags from the upper byte.
if ((vc.LoopFlags & XAFLAG_LOOP_START) && !vc.LoopMode)
vc.LoopStartA = vc.NextA & 0xFFFF8;
const int cacheIdx = vc.NextA / pcm_WordsPerBlock;
PcmCacheEntry &cacheLine = pcm_cache_data[cacheIdx];
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:
@ -199,12 +209,15 @@ 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
@ -218,22 +231,25 @@ static __forceinline s32 GetNextDataBuffered(V_Core &thiscore, uint voiceidx)
return vc.SBuffer[vc.SCurrent++];
}
static __forceinline void GetNextDataDummy(V_Core &thiscore, uint voiceidx)
static __forceinline void GetNextDataDummy(V_Core& thiscore, uint voiceidx)
{
V_Voice &vc(thiscore.Voices[voiceidx]);
V_Voice& vc(thiscore.Voices[voiceidx]);
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;
} 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);
@ -275,14 +291,14 @@ static __forceinline s32 ApplyVolume(s32 data, s32 volume)
return MulShr32(data << 1, volume);
}
static __forceinline StereoOut32 ApplyVolume(const StereoOut32 &data, const V_VolumeLR &volume)
static __forceinline StereoOut32 ApplyVolume(const StereoOut32& data, const V_VolumeLR& volume)
{
return StereoOut32(
ApplyVolume(data.Left, volume.Left),
ApplyVolume(data.Right, volume.Right));
}
static __forceinline StereoOut32 ApplyVolume(const StereoOut32 &data, const V_VolumeSlideLR &volume)
static __forceinline StereoOut32 ApplyVolume(const StereoOut32& data, const V_VolumeSlideLR& volume)
{
return StereoOut32(
ApplyVolume(data.Left, volume.Left.Value),
@ -291,7 +307,7 @@ static __forceinline StereoOut32 ApplyVolume(const StereoOut32 &data, const V_Vo
static void __forceinline UpdatePitch(uint coreidx, uint voiceidx)
{
V_Voice &vc(Cores[coreidx].Voices[voiceidx]);
V_Voice& vc(Cores[coreidx].Voices[voiceidx]);
s32 pitch;
// [Air] : re-ordered comparisons: Modulated is much more likely to be zero than voice,
@ -307,17 +323,20 @@ static void __forceinline UpdatePitch(uint coreidx, uint voiceidx)
}
static __forceinline void CalculateADSR(V_Core &thiscore, uint voiceidx)
static __forceinline void CalculateADSR(V_Core& thiscore, uint voiceidx)
{
V_Voice &vc(thiscore.Voices[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 (!vc.ADSR.Calculate())
{
if (IsDevBuild)
{
if (MsgVoiceOff())
ConLog("* SPU2-X: Voice Off by ADSR: %d \n", voiceidx);
}
@ -337,7 +356,7 @@ __forceinline static s32 HermiteInterpolate(
s32 y2, // 16.0
s32 y3, // 16.0
s32 mu // 0.12
)
)
{
s32 m00 = ((y1 - y0) * i_tension) >> 16; // 16.0
s32 m01 = ((y2 - y1) * i_tension) >> 16; // 16.0
@ -360,7 +379,7 @@ __forceinline static s32 CatmullRomInterpolate(
s32 y2, // 16.0
s32 y3, // 16.0
s32 mu // 0.12
)
)
{
//q(t) = 0.5 *( (2 * P1) +
// (-P0 + P2) * t +
@ -385,7 +404,7 @@ __forceinline static s32 CubicInterpolate(
s32 y2, // 16.0
s32 y3, // 16.0
s32 mu // 0.12
)
)
{
const s32 a0 = y3 - y2 - y0 + y1;
const s32 a1 = y0 - y1 - a0;
@ -402,12 +421,14 @@ __forceinline static s32 CubicInterpolate(
// Uses standard template-style optimization techniques to statically generate five different
// versions of this function (one for each type of interpolation).
template <int InterpType>
static __forceinline s32 GetVoiceValues(V_Core &thiscore, uint voiceidx)
static __forceinline s32 GetVoiceValues(V_Core& thiscore, uint voiceidx)
{
V_Voice &vc(thiscore.Voices[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;
}
@ -418,7 +439,8 @@ static __forceinline s32 GetVoiceValues(V_Core &thiscore, uint voiceidx)
const s32 mu = vc.SP + 4096;
switch (InterpType) {
switch (InterpType)
{
case 0:
return vc.PV1 << 1;
case 1:
@ -440,7 +462,7 @@ static __forceinline s32 GetVoiceValues(V_Core &thiscore, uint voiceidx)
// Noise values need to be mixed without going through interpolation, since it
// can wreak havoc on the noise (causing muffling or popping). Not that this noise
// generator is accurate in its own right.. but eh, ah well :)
static __forceinline s32 GetNoiseValues(V_Core &thiscore, uint voiceidx)
static __forceinline s32 GetNoiseValues(V_Core& thiscore, uint voiceidx)
{
// V_Voice &vc(thiscore.Voices[voiceidx]);
@ -469,8 +491,10 @@ 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);
}
@ -485,8 +509,8 @@ static __forceinline void spu2M_WriteFast(u32 addr, s16 value)
static __forceinline StereoOut32 MixVoice(uint coreidx, uint voiceidx)
{
V_Core &thiscore(Cores[coreidx]);
V_Voice &vc(thiscore.Voices[voiceidx]);
V_Core& thiscore(Cores[coreidx]);
V_Voice& vc(thiscore.Voices[voiceidx]);
// If this assertion fails, it mans SCurrent is being corrupted somewhere, or is not initialized
// properly. Invalid values in SCurrent will cause errant IRQs and corrupted audio.
@ -502,18 +526,21 @@ 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) {
switch (Interpolation)
{
case 0:
Value = GetVoiceValues<0>(thiscore, voiceidx);
break;
@ -546,11 +573,13 @@ 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;
}
@ -565,7 +594,9 @@ static __forceinline StereoOut32 MixVoice(uint coreidx, uint voiceidx)
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
|| (Cores[0].IRQEnable && (Cores[0].IRQA & ~7) == vc.LoopStartA) // or should be interrupting regularly
@ -589,11 +620,12 @@ static __forceinline StereoOut32 MixVoice(uint coreidx, uint voiceidx)
const VoiceMixSet VoiceMixSet::Empty((StereoOut32()), (StereoOut32())); // Don't use SteroOut32::Empty because C++ doesn't make any dep/order checks on global initializers.
static __forceinline void MixCoreVoices(VoiceMixSet &dest, const uint coreidx)
static __forceinline void MixCoreVoices(VoiceMixSet& dest, const uint coreidx)
{
V_Core &thiscore(Cores[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.
@ -605,7 +637,7 @@ static __forceinline void MixCoreVoices(VoiceMixSet &dest, const uint coreidx)
}
}
StereoOut32 V_Core::Mix(const VoiceMixSet &inVoices, const StereoOut32 &Input, const StereoOut32 &Ext)
StereoOut32 V_Core::Mix(const VoiceMixSet& inVoices, const StereoOut32& Input, const StereoOut32& Ext)
{
MasterVol.Update();
@ -695,7 +727,7 @@ StereoOut32 V_Core::Mix(const VoiceMixSet &inVoices, const StereoOut32 &Input, c
// Taken from http://nenolod.net/projects/upse/
#define OVERALL_SCALE (0.87f)
StereoOut32 Apply_Frequency_Response_Filter(StereoOut32 &SoundStream)
StereoOut32 Apply_Frequency_Response_Filter(StereoOut32& SoundStream)
{
static FrequencyResponseFilter FRF = FrequencyResponseFilter();
@ -748,7 +780,7 @@ StereoOut32 Apply_Frequency_Response_Filter(StereoOut32 &SoundStream)
return SoundStream;
}
StereoOut32 Apply_Dealias_Filter(StereoOut32 &SoundStream)
StereoOut32 Apply_Dealias_Filter(StereoOut32& SoundStream)
{
static StereoOut32 Old = StereoOut32::Empty;
@ -804,7 +836,8 @@ __forceinline
if ((PlayMode & 4) || (Cores[0].Mute != 0))
Ext = StereoOut32::Empty;
else {
else
{
Ext = clamp_mix(ApplyVolume(Ext, Cores[0].MasterVol));
}
@ -817,13 +850,16 @@ __forceinline
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);
@ -831,7 +867,8 @@ __forceinline
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);
}
@ -860,9 +897,11 @@ __forceinline
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",

View File

@ -38,26 +38,26 @@ struct StereoOut32
{
}
StereoOut32(const StereoOut16 &src);
explicit StereoOut32(const StereoOutFloat &src);
StereoOut32(const StereoOut16& src);
explicit StereoOut32(const StereoOutFloat& src);
StereoOut16 DownSample() const;
StereoOut32 operator*(const int &factor) const
StereoOut32 operator*(const int& factor) const
{
return StereoOut32(
Left * factor,
Right * factor);
}
StereoOut32 &operator*=(const int &factor)
StereoOut32& operator*=(const int& factor)
{
Left *= factor;
Right *= factor;
return *this;
}
StereoOut32 operator+(const StereoOut32 &right) const
StereoOut32 operator+(const StereoOut32& right) const
{
return StereoOut32(
Left + right.Left,
@ -69,13 +69,13 @@ struct StereoOut32
return StereoOut32(Left / src, Right / src);
}
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
this->Left = src.Left << 2;
this->Right = src.Right << 2;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -129,4 +129,4 @@ struct FrequencyResponseFilter
extern void Mix();
extern s32 clamp_mix(s32 x, u8 bitshift = 0);
extern StereoOut32 clamp_mix(const StereoOut32 &sample, u8 bitshift = 0);
extern StereoOut32 clamp_mix(const StereoOut32& sample, u8 bitshift = 0);

View File

@ -47,10 +47,11 @@ StereoOut32 V_Core::ReadInput_HiFi()
//#endif
StereoOut32 retval(
(s32 &)(*GetMemPtr(0x2000 + (Index << 10) + InputPosRead)),
(s32 &)(*GetMemPtr(0x2200 + (Index << 10) + InputPosRead)));
(s32&)(*GetMemPtr(0x2000 + (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
@ -64,9 +65,11 @@ 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))
{
AdmaInProgress = 0;
if (InputDataLeft >= 0x200) {
if (InputDataLeft >= 0x200)
{
#ifdef PCM24_S1_INTERLEAVE
AutoDMAReadBuffer(1);
#else
@ -76,11 +79,14 @@ 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 (IsDevBuild)
{
if (InputDataLeft > 0)
{
if (MsgAutoDMA())
ConLog("WARNING: adma buffer didn't finish with a whole block!!\n");
}
@ -88,13 +94,16 @@ StereoOut32 V_Core::ReadInput_HiFi()
InputDataLeft = 0;
// Hack, kinda. We call the interrupt early here, since PCSX2 doesn't like them delayed.
//DMAICounter = 1;
if (Index == 0) {
if(!SPU2_dummy_callback)
if (Index == 0)
{
if (!SPU2_dummy_callback)
spu2DMA4Irq();
else
SPU2interruptDMA4();
} else {
if(!SPU2_dummy_callback)
}
else
{
if (!SPU2_dummy_callback)
spu2DMA7Irq();
else
SPU2interruptDMA7();
@ -110,7 +119,8 @@ 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);
@ -131,9 +141,11 @@ StereoOut32 V_Core::ReadInput()
InputPosRead++;
if (AutoDMACtrl & (Index + 1) && (InputPosRead == 0x100 || InputPosRead == 0x200)) {
if (AutoDMACtrl & (Index + 1) && (InputPosRead == 0x100 || InputPosRead == 0x200))
{
AdmaInProgress = 0;
if (InputDataLeft >= 0x200) {
if (InputDataLeft >= 0x200)
{
//u8 k=InputDataLeft>=InputDataProgress;
AutoDMAReadBuffer(0);
@ -141,12 +153,15 @@ 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 (InputDataLeft > 0)
{
if (MsgAutoDMA())
ConLog("WARNING: adma buffer didn't finish with a whole block!!\n");
}
@ -155,13 +170,16 @@ StereoOut32 V_Core::ReadInput()
InputDataLeft = 0;
// Hack, kinda. We call the interrupt early here, since PCSX2 doesn't like them delayed.
//DMAICounter = 1;
if (Index == 0) {
if(!SPU2_dummy_callback)
if (Index == 0)
{
if (!SPU2_dummy_callback)
spu2DMA4Irq();
else
SPU2interruptDMA4();
} else {
if(!SPU2_dummy_callback)
}
else
{
if (!SPU2_dummy_callback)
spu2DMA7Irq();
else
SPU2interruptDMA7();

View File

@ -15,10 +15,10 @@
#include "Global.h"
const char *ParamNames[8] = {"VOLL", "VOLR", "PITCH", "ADSR1", "ADSR2", "ENVX", "VOLXL", "VOLXR"};
const char *AddressNames[6] = {"SSAH", "SSAL", "LSAH", "LSAL", "NAXH", "NAXL"};
const char* ParamNames[8] = {"VOLL", "VOLR", "PITCH", "ADSR1", "ADSR2", "ENVX", "VOLXL", "VOLXR"};
const char* AddressNames[6] = {"SSAH", "SSAL", "LSAH", "LSAL", "NAXH", "NAXL"};
__forceinline void _RegLog_(const char *action, int level, const char *RName, u32 mem, u32 core, u16 value)
__forceinline void _RegLog_(const char* action, int level, const char* RName, u32 mem, u32 core, u16 value)
{
if (level > 1)
FileLog("[%10d] SPU2 %s mem %08x (core %d, register %s) value %04x\n",
@ -27,7 +27,7 @@ __forceinline void _RegLog_(const char *action, int level, const char *RName, u3
#define RegLog(lev, rname, mem, core, val) _RegLog_(action, lev, rname, mem, core, val)
void SPU2writeLog(const char *action, u32 rmem, u16 value)
void SPU2writeLog(const char* action, u32 rmem, u16 value)
{
if (!IsDevBuild)
return;
@ -35,7 +35,8 @@ void SPU2writeLog(const char *action, u32 rmem, u16 value)
//u32 vx=0, vc=0;
u32 core = 0, omem, mem;
omem = mem = rmem & 0x7FF; //FFFF;
if (mem & 0x400) {
if (mem & 0x400)
{
omem ^= 0x400;
core = 1;
}
@ -47,7 +48,8 @@ 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;
@ -55,14 +57,18 @@ 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)) {
}
else if ((mem >= 0x0760) && (mem < 0x07b0))
{
omem = mem;
core = 0;
if (mem >= 0x0788) {
if (mem >= 0x0788)
{
omem -= 0x28;
core = 1;
}
switch (omem) {
switch (omem)
{
case REG_P_EVOLL:
RegLog(2, "EVOLL", rmem, core, value);
break;
@ -70,12 +76,14 @@ void SPU2writeLog(const char *action, u32 rmem, u16 value)
RegLog(2, "EVOLR", rmem, core, value);
break;
case REG_P_AVOLL:
if (core) {
if (core)
{
RegLog(2, "AVOLL", rmem, core, value);
}
break;
case REG_P_AVOLR:
if (core) {
if (core)
{
RegLog(2, "AVOLR", rmem, core, value);
}
break;
@ -122,8 +130,11 @@ void SPU2writeLog(const char *action, u32 rmem, u16 value)
RegLog(2, "IN_COEF_R", rmem, core, value);
break;
}
} else if ((mem >= 0x07C0) && (mem < 0x07CE)) {
switch (mem) {
}
else if ((mem >= 0x07C0) && (mem < 0x07CE))
{
switch (mem)
{
case SPDIF_OUT:
RegLog(2, "SPDIF_OUT", rmem, -1, value);
break;
@ -157,8 +168,11 @@ void SPU2writeLog(const char *action, u32 rmem, u16 value)
break;
}
UpdateSpdifMode();
} else {
switch (omem) {
}
else
{
switch (omem)
{
case REG_C_ATTR:
RegLog(4, "ATTR", rmem, core, value);
break;

View File

@ -41,15 +41,15 @@
PVCP(c, v, NextA)
#define PRAW(a) \
((u16 *)NULL)
((u16*)NULL)
#define PREVB_REG(c, n) \
PCORE(c, Revb.n) + 1, \
PCORE(c, Revb.n)
u16 *regtable[0x401];
u16* regtable[0x401];
u16 const *const regtable_original[0x401] =
u16 const* const regtable_original[0x401] =
{
// Voice Params: 8 params, 24 voices = 0x180 bytes
PVC(0, 0), PVC(0, 1), PVC(0, 2), PVC(0, 3), PVC(0, 4), PVC(0, 5),

View File

@ -22,7 +22,8 @@ __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;
}
@ -36,7 +37,8 @@ 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;
@ -45,9 +47,10 @@ void V_Core::Reverb_AdvanceBuffer()
/////////////////////////////////////////////////////////////////////////////////////////
StereoOut32 V_Core::DoReverb(const StereoOut32 &Input)
StereoOut32 V_Core::DoReverb(const StereoOut32& Input)
{
if (EffectsBufferSize <= 0) {
if (EffectsBufferSize <= 0)
{
return StereoOut32::Empty;
}
@ -82,8 +85,10 @@ 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 == same_src) || (Cores[i].IRQA == diff_src) ||
(Cores[i].IRQA == same_dst) || (Cores[i].IRQA == diff_dst) ||
(Cores[i].IRQA == same_prv) || (Cores[i].IRQA == diff_prv) ||
@ -92,7 +97,8 @@ StereoOut32 V_Core::DoReverb(const StereoOut32 &Input)
(Cores[i].IRQA == comb3_src) || (Cores[i].IRQA == comb4_src) ||
(Cores[i].IRQA == apf1_dst) || (Cores[i].IRQA == apf1_src) ||
(Cores[i].IRQA == apf2_dst) || (Cores[i].IRQA == apf2_src)) {
(Cores[i].IRQA == apf2_dst) || (Cores[i].IRQA == apf2_src))
{
//printf("Core %d IRQ Called (Reverb). IRQA = %x\n",i,addr);
SetIrqCall(i);
}
@ -118,7 +124,8 @@ StereoOut32 V_Core::DoReverb(const StereoOut32 &Input)
out = _spu2mem[apf2_src] + MUL(Revb.APF2_VOL, apf2);
// According to no$psx the effects always run but don't always write back, see check in V_Core::Mix
if (FxEnable) {
if (FxEnable)
{
_spu2mem[same_dst] = clamp_mix(same);
_spu2mem[diff_dst] = clamp_mix(diff);
_spu2mem[apf1_dst] = clamp_mix(apf1);

View File

@ -18,13 +18,13 @@
StereoOut32 StereoOut32::Empty(0, 0);
StereoOut32::StereoOut32(const StereoOut16 &src)
StereoOut32::StereoOut32(const StereoOut16& src)
: Left(src.Left)
, Right(src.Right)
{
}
StereoOut32::StereoOut32(const StereoOutFloat &src)
StereoOut32::StereoOut32(const StereoOutFloat& src)
: Left((s32)(src.Left * 2147483647.0f))
, Right((s32)(src.Right * 2147483647.0f))
{
@ -54,12 +54,12 @@ public:
void Configure(uptr parent) {}
int GetEmptySampleCount() { return 0; }
const wchar_t *GetIdent() const
const wchar_t* GetIdent() const
{
return L"nullout";
}
const wchar_t *GetLongName() const
const wchar_t* GetLongName() const
{
return L"No Sound (Emulate SPU2 only)";
}
@ -78,7 +78,7 @@ public:
} NullOut;
SndOutModule *mods[] =
SndOutModule* mods[] =
{
&NullOut,
#ifdef _MSC_VER
@ -96,10 +96,11 @@ SndOutModule *mods[] =
NULL // signals the end of our list
};
int FindOutputModuleById(const wchar_t *omodid)
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;
@ -107,14 +108,14 @@ int FindOutputModuleById(const wchar_t *omodid)
return modcnt;
}
StereoOut32 *SndBuffer::m_buffer;
StereoOut32* SndBuffer::m_buffer;
s32 SndBuffer::m_size;
__aligned(4) volatile s32 SndBuffer::m_rpos;
__aligned(4) volatile s32 SndBuffer::m_wpos;
bool SndBuffer::m_underrun_freeze;
StereoOut32 *SndBuffer::sndTempBuffer = NULL;
StereoOut16 *SndBuffer::sndTempBuffer16 = NULL;
StereoOut32* SndBuffer::sndTempBuffer = NULL;
StereoOut16* SndBuffer::sndTempBuffer16 = NULL;
int SndBuffer::sndTempProgress = 0;
int GetAlignedBufferSize(int comp)
@ -124,18 +125,20 @@ int GetAlignedBufferSize(int comp)
// Returns TRUE if there is data to be output, or false if no data
// is available to be copied.
bool SndBuffer::CheckUnderrunStatus(int &nSamples, int &quietSampleCount)
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;
}
@ -144,7 +147,9 @@ 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;
@ -172,7 +177,7 @@ int SndBuffer::_GetApproximateDataInBuffer()
return (m_wpos + m_size - m_rpos) % m_size;
}
void SndBuffer::_WriteSamples_Internal(StereoOut32 *bData, int nSamples)
void SndBuffer::_WriteSamples_Internal(StereoOut32* bData, int nSamples)
{
// WARNING: This assumes the write will NOT wrap around,
// and also assumes there's enough free space in the buffer.
@ -186,7 +191,7 @@ void SndBuffer::_DropSamples_Internal(int nSamples)
m_rpos = (m_rpos + nSamples) % m_size;
}
void SndBuffer::_ReadSamples_Internal(StereoOut32 *bData, int nSamples)
void SndBuffer::_ReadSamples_Internal(StereoOut32* bData, int nSamples)
{
// WARNING: This assumes the read will NOT wrap around,
// and also assumes there's enough data in the buffer.
@ -194,30 +199,36 @@ void SndBuffer::_ReadSamples_Internal(StereoOut32 *bData, int nSamples)
_DropSamples_Internal(nSamples);
}
void SndBuffer::_WriteSamples_Safe(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);
}
}
void SndBuffer::_ReadSamples_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);
}
}
@ -227,7 +238,7 @@ void SndBuffer::_ReadSamples_Safe(StereoOut32 *bData, int nSamples)
// 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)
void SndBuffer::ReadSamples(T* bData)
{
int nSamples = SndOutPacketSize;
@ -245,7 +256,8 @@ 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.
@ -254,7 +266,8 @@ 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]);
@ -263,7 +276,9 @@ 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]);
@ -283,28 +298,28 @@ void SndBuffer::ReadSamples(T *bData)
std::fill_n(bData, quietSamples, T{});
}
template void SndBuffer::ReadSamples(StereoOut16 *);
template void SndBuffer::ReadSamples(StereoOut32 *);
template void SndBuffer::ReadSamples(StereoOut16*);
template void SndBuffer::ReadSamples(StereoOut32*);
//template void SndBuffer::ReadSamples(StereoOutFloat*);
template void SndBuffer::ReadSamples(Stereo21Out16 *);
template void SndBuffer::ReadSamples(Stereo40Out16 *);
template void SndBuffer::ReadSamples(Stereo41Out16 *);
template void SndBuffer::ReadSamples(Stereo51Out16 *);
template void SndBuffer::ReadSamples(Stereo51Out16Dpl *);
template void SndBuffer::ReadSamples(Stereo51Out16DplII *);
template void SndBuffer::ReadSamples(Stereo71Out16 *);
template void SndBuffer::ReadSamples(Stereo21Out16*);
template void SndBuffer::ReadSamples(Stereo40Out16*);
template void SndBuffer::ReadSamples(Stereo41Out16*);
template void SndBuffer::ReadSamples(Stereo51Out16*);
template void SndBuffer::ReadSamples(Stereo51Out16Dpl*);
template void SndBuffer::ReadSamples(Stereo51Out16DplII*);
template void SndBuffer::ReadSamples(Stereo71Out16*);
template void SndBuffer::ReadSamples(Stereo20Out32 *);
template void SndBuffer::ReadSamples(Stereo21Out32 *);
template void SndBuffer::ReadSamples(Stereo40Out32 *);
template void SndBuffer::ReadSamples(Stereo41Out32 *);
template void SndBuffer::ReadSamples(Stereo51Out32 *);
template void SndBuffer::ReadSamples(Stereo51Out32Dpl *);
template void SndBuffer::ReadSamples(Stereo51Out32DplII *);
template void SndBuffer::ReadSamples(Stereo71Out32 *);
template void SndBuffer::ReadSamples(Stereo20Out32*);
template void SndBuffer::ReadSamples(Stereo21Out32*);
template void SndBuffer::ReadSamples(Stereo40Out32*);
template void SndBuffer::ReadSamples(Stereo41Out32*);
template void SndBuffer::ReadSamples(Stereo51Out32*);
template void SndBuffer::ReadSamples(Stereo51Out32Dpl*);
template void SndBuffer::ReadSamples(Stereo51Out32DplII*);
template void SndBuffer::ReadSamples(Stereo71Out32*);
void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
void SndBuffer::_WriteSamples(StereoOut32* bData, int nSamples)
{
m_predictData = 0;
@ -320,7 +335,8 @@ 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!
@ -358,7 +374,8 @@ void SndBuffer::_WriteSamples(StereoOut32 *bData, int nSamples)
void SndBuffer::Init()
{
if (mods[OutputModule] == NULL) {
if (mods[OutputModule] == NULL)
{
_InitFail();
return;
}
@ -370,7 +387,8 @@ void SndBuffer::Init()
m_rpos = 0;
m_wpos = 0;
try {
try
{
const float latencyMS = SndOutLatencyMS * 16;
m_size = GetAlignedBufferSize((int)(latencyMS * SampleRate / 1000.0f));
printf("%d SampleRate: \n", SampleRate);
@ -379,7 +397,9 @@ 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.");
@ -418,7 +438,7 @@ void SndBuffer::ClearContents()
SndBuffer::ssFreeze = 256; //Delays sound output for about 1 second.
}
void SndBuffer::Write(const StereoOut32 &Sample)
void SndBuffer::Write(const StereoOut32& Sample)
{
// Log final output to wavefile.
WaveDump::WriteCore(1, CoreSrc_External, Sample.DownSample());
@ -437,25 +457,30 @@ void SndBuffer::Write(const StereoOut32 &Sample)
sndTempProgress = 0;
//Don't play anything directly after loading a savestate, avoids static killing your speakers.
if (ssFreeze > 0) {
if (ssFreeze > 0)
{
ssFreeze--;
// Play silence
std::fill_n(sndTempBuffer, SndOutPacketSize, StereoOut32{});
}
#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) {
for (int i = 0; i < SndOutPacketSize; ++i, ++ei)
{
sndTempBuffer16[ei] = sndTempBuffer[i].DownSample();
}
m_dsp_progress += DspProcess((s16 *)sndTempBuffer16 + m_dsp_progress, SndOutPacketSize);
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) {
while (m_dsp_progress >= SndOutPacketSize)
{
for (int i = 0; i < SndOutPacketSize; ++i, ++ei)
{
sndTempBuffer[i] = sndTempBuffer16[ei].UpSample();
}
@ -468,13 +493,15 @@ 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);
}
}
#endif
else {
else
{
if (SynchMode == 0) // TimeStrech on
timeStretchWrite();
else

View File

@ -32,7 +32,7 @@ static const int SndOutVolumeShift32 = 16 - SndOutVolumeShift; // shift up, not
// is too problematic. :)
extern int SampleRate;
extern int FindOutputModuleById(const wchar_t *omodid);
extern int FindOutputModuleById(const wchar_t* omodid);
// Implemented in Config.cpp
extern float VolumeAdjustFL;
@ -52,10 +52,10 @@ struct Stereo51Out16Dpl; // similar to DplII but without rear balancing
struct Stereo51Out32Dpl;
extern void ResetDplIIDecoder();
extern void ProcessDplIISample16(const StereoOut32 &src, Stereo51Out16DplII *s);
extern void ProcessDplIISample32(const StereoOut32 &src, Stereo51Out32DplII *s);
extern void ProcessDplSample16(const StereoOut32 &src, Stereo51Out16Dpl *s);
extern void ProcessDplSample32(const StereoOut32 &src, Stereo51Out32Dpl *s);
extern void ProcessDplIISample16(const StereoOut32& src, Stereo51Out16DplII* s);
extern void ProcessDplIISample32(const StereoOut32& src, Stereo51Out32DplII* s);
extern void ProcessDplSample16(const StereoOut32& src, Stereo51Out16Dpl* s);
extern void ProcessDplSample32(const StereoOut32& src, Stereo51Out32Dpl* s);
struct StereoOut16
{
@ -68,7 +68,7 @@ struct StereoOut16
{
}
StereoOut16(const StereoOut32 &src)
StereoOut16(const StereoOut32& src)
: Left((s16)src.Left)
, Right((s16)src.Right)
{
@ -82,13 +82,13 @@ struct StereoOut16
StereoOut32 UpSample() const;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
// Use StereoOut32's built in conversion
*this = src.DownSample();
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -108,7 +108,7 @@ struct StereoOutFloat
{
}
explicit StereoOutFloat(const StereoOut32 &src)
explicit StereoOutFloat(const StereoOut32& src)
: Left(src.Left / 2147483647.0f)
, Right(src.Right / 2147483647.0f)
{
@ -133,14 +133,14 @@ struct Stereo21Out16
s16 Right;
s16 LFE;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left >> SndOutVolumeShift;
Right = src.Right >> SndOutVolumeShift;
LFE = (src.Left + src.Right) >> (SndOutVolumeShift + 1);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -157,7 +157,7 @@ struct Stereo40Out16
s16 LeftBack;
s16 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left >> SndOutVolumeShift;
Right = src.Right >> SndOutVolumeShift;
@ -165,7 +165,7 @@ struct Stereo40Out16
RightBack = src.Right >> SndOutVolumeShift;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -183,7 +183,7 @@ struct Stereo40Out32
s32 LeftBack;
s32 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left << SndOutVolumeShift32;
Right = src.Right << SndOutVolumeShift32;
@ -191,7 +191,7 @@ struct Stereo40Out32
RightBack = src.Right << SndOutVolumeShift32;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -210,7 +210,7 @@ struct Stereo41Out16
s16 LeftBack;
s16 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left >> SndOutVolumeShift;
Right = src.Right >> SndOutVolumeShift;
@ -219,7 +219,7 @@ struct Stereo41Out16
RightBack = src.Right >> SndOutVolumeShift;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -245,7 +245,7 @@ struct Stereo51Out16
// systems do to their own low pass / crossover. Manual lowpass is wasted effort
// and can't match solid state results anyway.
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left >> SndOutVolumeShift;
Right = src.Right >> SndOutVolumeShift;
@ -255,7 +255,7 @@ struct Stereo51Out16
RightBack = src.Right >> SndOutVolumeShift;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -277,12 +277,12 @@ struct Stereo51Out16DplII
s16 LeftBack;
s16 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
ProcessDplIISample16(src, this);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -304,12 +304,12 @@ struct Stereo51Out32DplII
s32 LeftBack;
s32 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
ProcessDplIISample32(src, this);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -331,12 +331,12 @@ struct Stereo51Out16Dpl
s16 LeftBack;
s16 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
ProcessDplSample16(src, this);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -358,12 +358,12 @@ struct Stereo51Out32Dpl
s32 LeftBack;
s32 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
ProcessDplSample32(src, this);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -387,7 +387,7 @@ struct Stereo71Out16
s16 LeftSide;
s16 RightSide;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left >> SndOutVolumeShift;
Right = src.Right >> SndOutVolumeShift;
@ -400,7 +400,7 @@ struct Stereo71Out16
RightSide = src.Right >> (SndOutVolumeShift + 1);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -426,7 +426,7 @@ struct Stereo71Out32
s32 LeftSide;
s32 RightSide;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left << SndOutVolumeShift32;
Right = src.Right << SndOutVolumeShift32;
@ -439,7 +439,7 @@ struct Stereo71Out32
RightSide = src.Right << (SndOutVolumeShift32 - 1);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -459,13 +459,13 @@ struct Stereo20Out32
s32 Left;
s32 Right;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left << SndOutVolumeShift32;
Right = src.Right << SndOutVolumeShift32;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -480,14 +480,14 @@ struct Stereo21Out32
s32 Right;
s32 LFE;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left << SndOutVolumeShift32;
Right = src.Right << SndOutVolumeShift32;
LFE = (src.Left + src.Right) << (SndOutVolumeShift32 - 1);
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -505,7 +505,7 @@ struct Stereo41Out32
s32 LeftBack;
s32 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left << SndOutVolumeShift32;
Right = src.Right << SndOutVolumeShift32;
@ -515,7 +515,7 @@ struct Stereo41Out32
RightBack = src.Right << SndOutVolumeShift32;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -536,7 +536,7 @@ struct Stereo51Out32
s32 LeftBack;
s32 RightBack;
void ResampleFrom(const StereoOut32 &src)
void ResampleFrom(const StereoOut32& src)
{
Left = src.Left << SndOutVolumeShift32;
Right = src.Right << SndOutVolumeShift32;
@ -546,7 +546,7 @@ struct Stereo51Out32
RightBack = src.Right << SndOutVolumeShift32;
}
void AdjustFrom(const StereoOut32 &src)
void AdjustFrom(const StereoOut32& src)
{
ResampleFrom(src);
@ -567,8 +567,8 @@ private:
static s32 m_predictData;
static float lastPct;
static StereoOut32 *sndTempBuffer;
static StereoOut16 *sndTempBuffer16;
static StereoOut32* sndTempBuffer;
static StereoOut16* sndTempBuffer16;
static int sndTempProgress;
static int m_dsp_progress;
@ -576,7 +576,7 @@ private:
static int m_timestretch_progress;
static int m_timestretch_writepos;
static StereoOut32 *m_buffer;
static StereoOut32* m_buffer;
static s32 m_size;
static __aligned(4) volatile s32 m_rpos;
@ -588,7 +588,7 @@ private:
static int ssFreeze;
static void _InitFail();
static bool CheckUnderrunStatus(int &nSamples, int &quietSampleCount);
static bool CheckUnderrunStatus(int& nSamples, int& quietSampleCount);
static void soundtouchInit();
static void soundtouchClearContents();
@ -602,14 +602,14 @@ private:
static void UpdateTempoChangeSoundTouch();
static void UpdateTempoChangeSoundTouch2();
static void _WriteSamples(StereoOut32 *bData, int nSamples);
static void _WriteSamples(StereoOut32* bData, int nSamples);
static void _WriteSamples_Safe(StereoOut32 *bData, int nSamples);
static void _ReadSamples_Safe(StereoOut32 *bData, int nSamples);
static void _WriteSamples_Safe(StereoOut32* bData, int nSamples);
static void _ReadSamples_Safe(StereoOut32* bData, int nSamples);
static void _WriteSamples_Internal(StereoOut32 *bData, int nSamples);
static void _WriteSamples_Internal(StereoOut32* bData, int nSamples);
static void _DropSamples_Internal(int nSamples);
static void _ReadSamples_Internal(StereoOut32 *bData, int nSamples);
static void _ReadSamples_Internal(StereoOut32* bData, int nSamples);
static int _GetApproximateDataInBuffer();
@ -617,7 +617,7 @@ public:
static void UpdateTempoChangeAsyncMixing();
static void Init();
static void Cleanup();
static void Write(const StereoOut32 &Sample);
static void Write(const StereoOut32& Sample);
static s32 Test();
static void ClearContents();
@ -626,7 +626,7 @@ public:
// 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>
static void ReadSamples(T *bData);
static void ReadSamples(T* bData);
};
class SndOutModule
@ -637,11 +637,11 @@ public:
// Returns a unique identification string for this driver.
// (usually just matches the driver's cpp filename)
virtual const wchar_t *GetIdent() const = 0;
virtual const wchar_t* GetIdent() const = 0;
// Returns the long name / description for this driver.
// (for use in configuration screen)
virtual const wchar_t *GetLongName() const = 0;
virtual const wchar_t* GetLongName() const = 0;
virtual s32 Init() = 0;
virtual void Close() = 0;
@ -666,19 +666,19 @@ public:
#ifdef _MSC_VER
//internal
extern SndOutModule *WaveOut;
extern SndOutModule *DSoundOut;
extern SndOutModule *XAudio2Out;
extern SndOutModule* WaveOut;
extern SndOutModule* DSoundOut;
extern SndOutModule* XAudio2Out;
#endif
#if defined(_WIN32) || defined(SPU2X_PORTAUDIO)
extern SndOutModule *PortaudioOut;
extern SndOutModule* PortaudioOut;
#endif
extern SndOutModule *const SDLOut;
extern SndOutModule* const SDLOut;
#ifdef __linux__
extern SndOutModule *AlsaOut;
extern SndOutModule* AlsaOut;
#endif
extern SndOutModule *mods[];
extern SndOutModule* mods[];
// =====================================================================================================
@ -686,9 +686,9 @@ extern bool WavRecordEnabled;
extern void RecordStart(std::wstring* filename);
extern void RecordStop();
extern void RecordWrite(const StereoOut16 &sample);
extern void RecordWrite(const StereoOut16& sample);
extern s32 DspLoadLibrary(wchar_t *fileName, int modNum);
extern s32 DspLoadLibrary(wchar_t* fileName, int modNum);
extern void DspCloseLibrary();
extern int DspProcess(s16 *buffer, int samples);
extern int DspProcess(s16* buffer, int samples);
extern void DspUpdate(); // to let the Dsp process window messages

View File

@ -28,11 +28,11 @@
#include "pa_win_wasapi.h"
#endif
int PaCallback(const void *inputBuffer, void *outputBuffer,
int PaCallback(const void* inputBuffer, void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData);
void* userData);
class Portaudio : public SndOutModule
{
@ -60,38 +60,38 @@ private:
int actualUsedChannels;
bool started;
PaStream *stream;
PaStream* stream;
//////////////////////////////////////////////////////////////////////////////////////////
// Stuff necessary for speaker expansion
class SampleReader
{
public:
virtual int ReadSamples(const void *inputBuffer, void *outputBuffer,
virtual int ReadSamples(const void* inputBuffer, void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData) = 0;
void* userData) = 0;
};
template <class T>
class ConvertedSampleReader : public SampleReader
{
int *written;
int* written;
public:
ConvertedSampleReader(int *pWritten)
ConvertedSampleReader(int* pWritten)
{
written = pWritten;
}
virtual int ReadSamples(const void *inputBuffer, void *outputBuffer,
virtual int ReadSamples(const void* inputBuffer, void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData)
void* userData)
{
T *p1 = (T *)outputBuffer;
T* p1 = (T*)outputBuffer;
int packets = framesPerBuffer / SndOutPacketSize;
@ -105,7 +105,7 @@ private:
};
public:
SampleReader *ActualPaCallback;
SampleReader* ActualPaCallback;
Portaudio()
{
@ -131,7 +131,8 @@ 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;
}
@ -140,16 +141,20 @@ public:
int deviceIndex = -1;
fprintf(stderr, "* SPU2-X: Enumerating PortAudio devices:\n");
for (int i = 0, j = 0; i < Pa_GetDeviceCount(); i++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
for (int i = 0, j = 0; i < Pa_GetDeviceCount(); i++)
{
const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
if (info->maxOutputChannels > 0) {
const PaHostApiInfo *apiinfo = Pa_GetHostApiInfo(info->hostApi);
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)");
}
@ -161,19 +166,23 @@ public:
}
fflush(stderr);
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 (deviceIndex < 0 && m_ApiId >= 0)
{
for (int i = 0; i < Pa_GetHostApiCount(); i++)
{
const PaHostApiInfo* apiinfo = Pa_GetHostApiInfo(i);
if (apiinfo->type == m_ApiId)
{
deviceIndex = apiinfo->defaultOutputDevice;
}
}
}
if (deviceIndex >= 0) {
void *infoPtr = NULL;
if (deviceIndex >= 0)
{
void* infoPtr = NULL;
const PaDeviceInfo *devinfo = Pa_GetDeviceInfo(deviceIndex);
const PaDeviceInfo* devinfo = Pa_GetDeviceInfo(deviceIndex);
int speakers;
switch (numSpeakers) // speakers = (numSpeakers + 1) *2; ?
@ -195,7 +204,8 @@ public:
}
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);
@ -218,7 +228,8 @@ 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
@ -249,7 +260,8 @@ public:
1,
paWinWasapiExclusive};
if ((m_ApiId == paWASAPI) && m_WasapiExclusiveMode) {
if ((m_ApiId == paWASAPI) && m_WasapiExclusiveMode)
{
// Pass it the Exclusive mode enable flag
infoPtr = &info;
}
@ -275,21 +287,25 @@ 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;
@ -303,9 +319,12 @@ 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));
@ -337,8 +356,10 @@ private:
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);
@ -348,31 +369,38 @@ 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++) {
const PaHostApiInfo *apiinfo = Pa_GetHostApiInfo(i);
if (apiinfo->deviceCount > 0) {
for (int i = 0; i < Pa_GetHostApiCount(); i++)
{
const PaHostApiInfo* apiinfo = Pa_GetHostApiInfo(i);
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++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
if (info->hostApi == api_idx && info->maxOutputChannels > 0) {
for (int j = 0; j < Pa_GetDeviceCount(); j++)
{
const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
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++;
@ -392,21 +420,25 @@ 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);
idx = (int)SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_GETCURSEL, 0, 0);
const PaDeviceInfo *info = (const PaDeviceInfo *)SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_GETITEMDATA, idx, 0);
const PaDeviceInfo* info = (const PaDeviceInfo*)SendMessage(GetDlgItem(hWnd, IDC_PA_DEVICE), CB_GETITEMDATA, idx, 0);
if (info)
m_Device = wxString::FromUTF8(info->name);
else
@ -424,14 +456,17 @@ private:
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);
@ -439,9 +474,11 @@ 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++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
if (info->hostApi == api_idx && info->maxOutputChannels > 0) {
for (int j = 0; j < Pa_GetDeviceCount(); j++)
{
const PaDeviceInfo* info = Pa_GetDeviceInfo(j);
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++;
@ -449,17 +486,21 @@ 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_LINEUP:
case TB_LINEDOWN:
case TB_PAGEUP:
@ -468,7 +509,8 @@ private:
case TB_BOTTOM:
wmEvent = (int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0);
case TB_THUMBPOSITION:
case TB_THUMBTRACK: {
case TB_THUMBTRACK:
{
wchar_t temp[128];
if (wmEvent < 10)
wmEvent = 10;
@ -482,7 +524,8 @@ private:
default:
return FALSE;
}
} break;
}
break;
default:
return FALSE;
@ -497,7 +540,8 @@ 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;
}
@ -505,7 +549,8 @@ 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;
}
@ -535,12 +580,12 @@ public:
return playedSinceLastTime;
}
const wchar_t *GetIdent() const
const wchar_t* GetIdent() const
{
return L"portaudio";
}
const wchar_t *GetLongName() const
const wchar_t* GetLongName() const
{
return L"PortAudio (Cross-platform)";
}
@ -608,7 +653,8 @@ public:
void WriteSettings() const
{
wxString api;
switch (m_ApiId) {
switch (m_ApiId)
{
case paInDevelopment:
api = L"InDevelopment";
break; /* use while developing support for a new host API */
@ -665,11 +711,11 @@ public:
} static PA;
int PaCallback(const void *inputBuffer, void *outputBuffer,
int PaCallback(const void* inputBuffer, void* outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData)
void* userData)
{
return PA.ActualPaCallback->ReadSamples(inputBuffer, outputBuffer, framesPerBuffer, timeInfo, statusFlags, userData);
}
@ -681,4 +727,4 @@ BOOL CALLBACK Portaudio::ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
}
#endif
SndOutModule *PortaudioOut = &PA;
SndOutModule* PortaudioOut = &PA;

View File

@ -35,22 +35,22 @@ typedef StereoOut16 StereoOut_SDL;
namespace
{
/* Since spu2 only ever outputs stereo, we don't worry about emitting surround sound
/* Since spu2 only ever outputs stereo, we don't worry about emitting surround sound
* even though SDL2 supports it */
const Uint8 channels = 2;
/* SDL2 supports s32 audio */
/* Samples should vary from [512,8192] according to SDL spec. Take note this is the desired
const Uint8 channels = 2;
/* SDL2 supports s32 audio */
/* Samples should vary from [512,8192] according to SDL spec. Take note this is the desired
* sample count and SDL may provide otherwise. Pulseaudio will cut this value in half if
* PA_STREAM_ADJUST_LATENCY is set in the backened, for example. */
const Uint16 desiredSamples = 2048;
const Uint16 format = AUDIO_S16SYS;
const Uint16 desiredSamples = 2048;
const Uint16 format = AUDIO_S16SYS;
Uint16 samples = desiredSamples;
Uint16 samples = desiredSamples;
std::unique_ptr<StereoOut_SDL[]> buffer;
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
@ -65,9 +65,9 @@ void callback_fillBuffer(void *userdata, Uint8 *stream, int len)
for (Uint16 i = 0; i < sdl_samples; i += SndOutPacketSize)
SndBuffer::ReadSamples(&buffer[i]);
SDL_MixAudio(stream, (Uint8 *)buffer.get(), len, SDL_MIX_MAXVOLUME);
}
}
SDL_MixAudio(stream, (Uint8*)buffer.get(), len, SDL_MIX_MAXVOLUME);
}
} // namespace
struct SDLAudioMod : public SndOutModule
{
@ -87,24 +87,28 @@ struct SDLAudioMod : public SndOutModule
spec.samples = desiredSamples;
// Mandatory otherwise, init will be redone in SDL_OpenAudio
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
std::cerr << "SPU2-X: SDL INIT audio error: " << SDL_GetError() << std::endl;
return -1;
}
#if SDL_MAJOR_VERSION >= 2
if (m_api.compare("pulseaudio")) {
if (m_api.compare("pulseaudio"))
{
// Close the audio, but keep the subsystem open
SDL_AudioQuit();
// Reopen the audio
if (SDL_AudioInit(m_api.c_str()) < 0) {
if (SDL_AudioInit(m_api.c_str()) < 0)
{
std::cerr << "SPU2-X: SDL audio init error: " << SDL_GetError() << std::endl;
return -1;
}
}
#endif
if (SDL_OpenAudio(&spec, NULL) < 0) {
if (SDL_OpenAudio(&spec, NULL) < 0)
{
std::cerr << "SPU2-X: SDL audio error: " << SDL_GetError() << std::endl;
return -1;
}
@ -116,7 +120,8 @@ struct SDLAudioMod : public SndOutModule
/* This is so ugly. It is hilariously ugly. I didn't use a vector to save reallocs. */
if (samples != spec.samples || buffer == NULL)
buffer = std::unique_ptr<StereoOut_SDL[]>(new StereoOut_SDL[spec.samples]);
if (samples != spec.samples) {
if (samples != spec.samples)
{
fprintf(stderr, "SPU2-X: SDL failed to get desired samples (%d) got %d samples instead\n", samples, spec.samples);
// Samples must always be a multiple of packet size.
@ -127,8 +132,8 @@ struct SDLAudioMod : public SndOutModule
return 0;
}
const wchar_t *GetIdent() const { return L"SDLAudio"; }
const wchar_t *GetLongName() const { return L"SDL Audio"; }
const wchar_t* GetIdent() const { return L"SDLAudio"; }
const wchar_t* GetLongName() const { return L"SDL Audio"; }
void Close()
{
@ -161,12 +166,16 @@ struct SDLAudioMod : public SndOutModule
// Validate the api name
bool valid = false;
std::string api_name = std::string(api.utf8_str());
for (int i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
for (int i = 0; i < SDL_GetNumAudioDrivers(); ++i)
{
valid |= (api_name.compare(SDL_GetAudioDriver(i)) == 0);
}
if (valid) {
if (valid)
{
m_api = api.utf8_str();
} else {
}
else
{
std::cerr << "SDL audio driver configuration is invalid!" << std::endl
<< "It will be replaced by pulseaudio!" << std::endl;
m_api = "pulseaudio";
@ -190,4 +199,4 @@ private:
SDLAudioMod SDLAudioMod::mod;
SndOutModule *const SDLOut = &SDLAudioMod::mod;
SndOutModule* const SDLOut = &SDLAudioMod::mod;

View File

@ -21,7 +21,7 @@
//Uncomment the next line to use the old time stretcher
//#define SPU2X_USE_OLD_STRETCHER
static soundtouch::SoundTouch *pSoundTouch = NULL;
static soundtouch::SoundTouch* pSoundTouch = NULL;
// data prediction amount, used to "commit" data that hasn't
// finished timestretch processing.
@ -130,7 +130,8 @@ float addToAvg(float val)
// Few gotchas: val overwrites first-1, handling actualWindow changes, etc.
// However, this isn't hot code, so unless proven otherwise, we can live with unoptimized code.
float sum = 0;
for (unsigned int i = first; i < first + actualWindow; i++) {
for (unsigned int i = first; i < first + actualWindow; i++)
{
sum += avg_fullness[i % AVERAGING_BUFFER_SIZE];
}
sum = sum / actualWindow;
@ -139,7 +140,7 @@ float addToAvg(float val)
}
template <class T>
bool IsInRange(const T &val, const T &min, const T &max)
bool IsInRange(const T& val, const T& min, const T& max)
{
return (min <= val && val <= max);
}
@ -156,7 +157,8 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
static bool inside_hysteresis; //=false;
static int hys_ok_count; //=0;
static float dynamicTargetFullness; //=baseTargetFullness;
if (gRequestStretcherReset >= STRETCHER_RESET_THRESHOLD) {
if (gRequestStretcherReset >= STRETCHER_RESET_THRESHOLD)
{
ConLog("______> stretch: Reset.\n");
inside_hysteresis = false;
hys_ok_count = 0;
@ -172,9 +174,11 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
static wxDateTime last = wxDateTime::UNow();
wxDateTime unow = wxDateTime::UNow();
wxTimeSpan delta = unow.Subtract(last);
if (delta.GetMilliseconds() > 500) {
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 (!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);
targetIPS = pot_targetIPS;
@ -212,19 +216,22 @@ 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
hys_ok_count = 0;
if (hys_ok_count >= hys_min_ok_count) {
if (hys_ok_count >= hys_min_ok_count)
{
inside_hysteresis = true;
if (MsgOverruns())
ConLog("======> stretch: None (1:1)\n");
}
} else if (!IsInRange(tempoAdjust, 1.0f / hys_bad_factor, hys_bad_factor)) {
}
else if (!IsInRange(tempoAdjust, 1.0f / hys_bad_factor, hys_bad_factor))
{
if (MsgOverruns())
ConLog("~~~~~~> stretch: Dynamic\n");
inside_hysteresis = false;
@ -234,13 +241,15 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
if (inside_hysteresis)
tempoAdjust = 1.0;
if (MsgOverruns()) {
if (MsgOverruns())
{
static int iters = 0;
static wxDateTime last = wxDateTime::UNow();
wxDateTime unow = wxDateTime::UNow();
wxTimeSpan delta = unow.Subtract(last);
if (delta.GetMilliseconds() > 1000) { //report buffers state and tempo adjust every second
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);
last = unow;
@ -281,7 +290,8 @@ 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.
@ -319,7 +329,8 @@ 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);
}
@ -352,7 +363,8 @@ 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)
@ -375,15 +387,20 @@ 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);
}
@ -396,19 +413,23 @@ 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;
//printf("-- %d, %f\n",TickInterval,statusPct);
} else if (statusPct > 0.2f) {
}
else if (statusPct > 0.2f)
{
TickInterval += 1;
if (TickInterval >= 7000)
TickInterval = 7000;
//printf("++ %d, %f\n",TickInterval,statusPct);
} else
}
else
TickInterval = 768;
}
@ -442,21 +463,21 @@ s32 SndBuffer::timeStretchOverrun()
return SndOutPacketSize * 2;
}
static void CvtPacketToFloat(StereoOut32 *srcdest)
static void CvtPacketToFloat(StereoOut32* srcdest)
{
StereoOutFloat *dest = (StereoOutFloat *)srcdest;
const StereoOut32 *src = (StereoOut32 *)srcdest;
StereoOutFloat* dest = (StereoOutFloat*)srcdest;
const StereoOut32* src = (StereoOut32*)srcdest;
for (uint i = 0; i < SndOutPacketSize; ++i, ++dest, ++src)
*dest = (StereoOutFloat)*src;
}
// Parameter note: Size should always be a multiple of 128, thanks!
static void CvtPacketToInt(StereoOut32 *srcdest, uint size)
static void CvtPacketToInt(StereoOut32* srcdest, uint size)
{
//pxAssume( (size & 127) == 0 );
const StereoOutFloat *src = (StereoOutFloat *)srcdest;
StereoOut32 *dest = srcdest;
const StereoOutFloat* src = (StereoOutFloat*)srcdest;
StereoOut32* dest = srcdest;
for (uint i = 0; i < size; ++i, ++dest, ++src)
*dest = (StereoOut32)*src;
@ -473,11 +494,12 @@ void SndBuffer::timeStretchWrite()
PredictDataWrite((int)(SndOutPacketSize / eTempo));
CvtPacketToFloat(sndTempBuffer);
pSoundTouch->putSamples((float *)sndTempBuffer, SndOutPacketSize);
pSoundTouch->putSamples((float*)sndTempBuffer, SndOutPacketSize);
int tempProgress;
while (tempProgress = pSoundTouch->receiveSamples((float *)sndTempBuffer, SndOutPacketSize),
tempProgress != 0) {
while (tempProgress = pSoundTouch->receiveSamples((float*)sndTempBuffer, SndOutPacketSize),
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.

View File

@ -37,11 +37,12 @@ static const char dataStr[] = "data";
// Class WavOutFile
//
WavOutFile::WavOutFile(const char *fileName, int sampleRate, int bits, int channels)
WavOutFile::WavOutFile(const char* fileName, int sampleRate, int bits, int channels)
{
bytesWritten = 0;
fptr = fopen(fileName, "wb");
if (fptr == NULL) {
if (fptr == NULL)
{
string msg = "Error : Unable to open file \"";
msg += fileName;
msg += "\" for writing.";
@ -56,7 +57,8 @@ WavOutFile::WavOutFile(const char *fileName, int sampleRate, int bits, int chann
WavOutFile::~WavOutFile()
{
if (fptr) {
if (fptr)
{
finishHeader();
fclose(fptr);
}
@ -117,7 +119,8 @@ 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.");
}
@ -126,7 +129,7 @@ void WavOutFile::writeHeader()
}
void WavOutFile::write(const short *buffer, int numElems)
void WavOutFile::write(const short* buffer, int numElems)
{
int res;
@ -138,7 +141,8 @@ void WavOutFile::write(const short *buffer, int numElems)
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

@ -69,7 +69,7 @@ class WavOutFile
{
private:
/// Pointer to the WAV file
FILE *fptr;
FILE* fptr;
/// WAV file header data.
WavHeader header;
@ -90,7 +90,7 @@ private:
public:
/// Constructor: Creates a new WAV file. Throws a 'runtime_error' exception
/// if file creation fails.
WavOutFile(const char *fileName, ///< Filename
WavOutFile(const char* fileName, ///< Filename
int sampleRate, ///< Sample rate (e.g. 44100 etc)
int bits, ///< Bits per sample (8 or 16 bits)
int channels ///< Number of channels (1=mono, 2=stereo)
@ -101,7 +101,7 @@ public:
/// Write data to WAV file. Throws a 'runtime_error' exception if writing to
/// file fails.
void write(const short *buffer, ///< Pointer to sample data buffer.
void write(const short* buffer, ///< Pointer to sample data buffer.
int numElems ///< How many array items are to be written to file.
);
};

View File

@ -20,16 +20,16 @@
#include "soundtouch/source/SoundStretch/WavFile.h"
#endif
static WavOutFile *_new_WavOutFile(const char *destfile)
static WavOutFile* _new_WavOutFile(const char* destfile)
{
return new WavOutFile(destfile, 48000, 16, 2);
}
namespace WaveDump
{
static WavOutFile *m_CoreWav[2][CoreSrc_Count];
static WavOutFile* m_CoreWav[2][CoreSrc_Count];
static const char *m_tbl_CoreOutputTypeNames[CoreSrc_Count] =
static const char* m_tbl_CoreOutputTypeNames[CoreSrc_Count] =
{
"Input",
"DryVoiceMix",
@ -38,8 +38,8 @@ static const char *m_tbl_CoreOutputTypeNames[CoreSrc_Count] =
"PostReverb",
"External"};
void Open()
{
void Open()
{
if (!IsDevBuild)
return;
if (!WaveLog())
@ -47,8 +47,10 @@ void Open()
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%ud-%s.wav",
@ -58,40 +60,45 @@ void Open()
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;
}
}
}
}
}
void Close()
{
void Close()
{
if (!IsDevBuild)
return;
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]);
}
}
}
}
void WriteCore(uint coreidx, CoreSourceType src, const StereoOut16 &sample)
{
void WriteCore(uint coreidx, CoreSourceType src, const StereoOut16& sample)
{
if (!IsDevBuild)
return;
if (m_CoreWav[coreidx][src] != NULL)
m_CoreWav[coreidx][src]->write((s16 *)&sample, 2);
}
m_CoreWav[coreidx][src]->write((s16*)&sample, 2);
}
void WriteCore(uint coreidx, CoreSourceType src, s16 left, s16 right)
{
void WriteCore(uint coreidx, CoreSourceType src, s16 left, s16 right)
{
WriteCore(coreidx, src, StereoOut16(left, right));
}
}
}
} // namespace WaveDump
#include "Utilities/Threading.h"
@ -99,14 +106,15 @@ using namespace Threading;
bool WavRecordEnabled = false;
static WavOutFile *m_wavrecord = NULL;
static WavOutFile* m_wavrecord = NULL;
static Mutex WavRecordMutex;
void RecordStart(std::wstring* filename)
{
WavRecordEnabled = false;
try {
try
{
ScopedLock lock(WavRecordMutex);
safe_delete(m_wavrecord);
#ifdef _WIN32
@ -118,7 +126,9 @@ void RecordStart(std::wstring* filename)
m_wavrecord = new WavOutFile("audio_recording.wav", 48000, 16, 2);
#endif
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.", "audio_recording.wav");
}
@ -131,10 +141,10 @@ void RecordStop()
safe_delete(m_wavrecord);
}
void RecordWrite(const StereoOut16 &sample)
void RecordWrite(const StereoOut16& sample)
{
ScopedLock lock(WavRecordMutex);
if (m_wavrecord == NULL)
return;
m_wavrecord->write((s16 *)&sample, 2);
m_wavrecord->write((s16*)&sample, 2);
}

View File

@ -20,7 +20,7 @@
extern uptr gsWindowHandle;
void SysMessage(const char *fmt, ...)
void SysMessage(const char* fmt, ...)
{
va_list list;
char tmp[512];
@ -34,7 +34,7 @@ void SysMessage(const char *fmt, ...)
L"SPU2-X System Message", MB_OK | MB_SETFOREGROUND);
}
void SysMessage(const wchar_t *fmt, ...)
void SysMessage(const wchar_t* fmt, ...)
{
va_list list;
va_start(list, fmt);
@ -51,7 +51,7 @@ void SysMessage(const wchar_t *fmt, ...)
static wxString CfgFile(L"inis/SPU2.ini");
void CfgSetSettingsDir(const char *dir)
void CfgSetSettingsDir(const char* dir)
{
CfgFile = Path::Combine((dir == NULL) ? wxString(L"inis") : wxString::FromUTF8(dir), L"SPU2.ini");
}
@ -72,20 +72,20 @@ void CfgSetSettingsDir(const char *dir)
\*_____________________________________________*/
void CfgWriteBool(const TCHAR *Section, const TCHAR *Name, bool Value)
void CfgWriteBool(const TCHAR* Section, const TCHAR* Name, bool Value)
{
const TCHAR *Data = Value ? L"TRUE" : L"FALSE";
const TCHAR* Data = Value ? L"TRUE" : L"FALSE";
WritePrivateProfileString(Section, Name, Data, CfgFile);
}
void CfgWriteInt(const TCHAR *Section, const TCHAR *Name, int Value)
void CfgWriteInt(const TCHAR* Section, const TCHAR* Name, int Value)
{
TCHAR Data[32];
_itow(Value, Data, 10);
WritePrivateProfileString(Section, Name, Data, CfgFile);
}
void CfgWriteFloat(const TCHAR *Section, const TCHAR *Name, float Value)
void CfgWriteFloat(const TCHAR* Section, const TCHAR* Name, float Value)
{
TCHAR Data[32];
_swprintf(Data, L"%f", Value);
@ -97,20 +97,21 @@ void CfgWriteFloat(const TCHAR *Section, const TCHAR *Name, float Value)
WritePrivateProfileString( Section, Name, Data, CfgFile );
}*/
void CfgWriteStr(const TCHAR *Section, const TCHAR *Name, const wxString &Data)
void CfgWriteStr(const TCHAR* Section, const TCHAR* Name, const wxString& Data)
{
WritePrivateProfileString(Section, Name, Data, CfgFile);
}
/*****************************************************************************/
bool CfgReadBool(const TCHAR *Section, const TCHAR *Name, bool Default)
bool CfgReadBool(const TCHAR* Section, const TCHAR* Name, bool Default)
{
TCHAR Data[255] = {0};
GetPrivateProfileString(Section, Name, L"", Data, 255, CfgFile);
Data[254] = 0;
if (wcslen(Data) == 0) {
if (wcslen(Data) == 0)
{
CfgWriteBool(Section, Name, Default);
return Default;
}
@ -129,13 +130,14 @@ bool CfgReadBool(const TCHAR *Section, const TCHAR *Name, bool Default)
}
int CfgReadInt(const TCHAR *Section, const TCHAR *Name, int Default)
int CfgReadInt(const TCHAR* Section, const TCHAR* Name, int Default)
{
TCHAR Data[255] = {0};
GetPrivateProfileString(Section, Name, L"", Data, 255, CfgFile);
Data[254] = 0;
if (wcslen(Data) == 0) {
if (wcslen(Data) == 0)
{
CfgWriteInt(Section, Name, Default);
return Default;
}
@ -143,13 +145,14 @@ int CfgReadInt(const TCHAR *Section, const TCHAR *Name, int Default)
return _wtoi(Data);
}
float CfgReadFloat(const TCHAR *Section, const TCHAR *Name, float Default)
float CfgReadFloat(const TCHAR* Section, const TCHAR* Name, float Default)
{
TCHAR Data[255] = {0};
GetPrivateProfileString(Section, Name, L"", Data, 255, CfgFile);
Data[254] = 0;
if (wcslen(Data) == 0) {
if (wcslen(Data) == 0)
{
CfgWriteFloat(Section, Name, Default);
return Default;
}
@ -157,24 +160,26 @@ float CfgReadFloat(const TCHAR *Section, const TCHAR *Name, float Default)
return (float)_wtof(Data);
}
void CfgReadStr(const TCHAR *Section, const TCHAR *Name, TCHAR *Data, int DataSize, const TCHAR *Default)
void CfgReadStr(const TCHAR* Section, const TCHAR* Name, TCHAR* Data, int DataSize, const TCHAR* Default)
{
GetPrivateProfileString(Section, Name, L"", Data, DataSize, CfgFile);
if (wcslen(Data) == 0) {
if (wcslen(Data) == 0)
{
swprintf_s(Data, DataSize, L"%s", Default);
CfgWriteStr(Section, Name, Data);
}
}
void CfgReadStr(const TCHAR *Section, const TCHAR *Name, wxString &Data, const TCHAR *Default)
void CfgReadStr(const TCHAR* Section, const TCHAR* Name, wxString& Data, const TCHAR* Default)
{
wchar_t workspace[512];
GetPrivateProfileString(Section, Name, L"", workspace, ArraySize(workspace), CfgFile);
Data = workspace;
if (Data.empty()) {
if (Data.empty())
{
Data = Default;
CfgWriteStr(Section, Name, Default);
}
@ -182,7 +187,7 @@ void CfgReadStr(const TCHAR *Section, const TCHAR *Name, wxString &Data, const T
// Tries to read the requested value.
// Returns FALSE if the value isn't found.
bool CfgFindName(const TCHAR *Section, const TCHAR *Name)
bool CfgFindName(const TCHAR* Section, const TCHAR* Name)
{
// Only load 24 characters. No need to load more.
TCHAR Data[24] = {0};

View File

@ -150,7 +150,8 @@ 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());
@ -222,11 +223,13 @@ 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)");
@ -251,7 +254,8 @@ 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;
@ -283,14 +287,17 @@ 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);
@ -302,36 +309,44 @@ 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_OUTPUT:
if (wmEvent == CBN_SELCHANGE) {
if (wmEvent == CBN_SELCHANGE)
{
CheckOutputModule(hWnd);
}
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);
} break;
}
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);
@ -346,7 +361,8 @@ 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:
@ -366,13 +382,15 @@ 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;
int curpos = HIWORD(wParam);
switch (wmEvent) {
switch (wmEvent)
{
case TB_LINEUP:
case TB_LINEDOWN:
case TB_PAGEUP:
@ -389,14 +407,16 @@ BOOL CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
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,7 +425,8 @@ BOOL CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
default:
return FALSE;
}
} break;
}
break;
default:
return FALSE;
@ -418,7 +439,8 @@ 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

@ -55,24 +55,24 @@ wxString CoresDumpFileName;
wxString MemDumpFileName;
wxString RegDumpFileName;
void CfgSetLogDir(const char *dir)
void CfgSetLogDir(const char* dir)
{
LogsFolder = (dir == NULL) ? wxString(L"logs") : wxString(dir, wxConvFile);
DumpsFolder = (dir == NULL) ? wxString(L"logs") : wxString(dir, wxConvFile);
LogLocationSetByPcsx2 = (dir != NULL);
}
FILE *OpenBinaryLog(const wxString &logfile)
FILE* OpenBinaryLog(const wxString& logfile)
{
return wxFopen(Path::Combine(LogsFolder, logfile), L"wb");
}
FILE *OpenLog(const wxString &logfile)
FILE* OpenLog(const wxString& logfile)
{
return wxFopen(Path::Combine(LogsFolder, logfile), L"w");
}
FILE *OpenDump(const wxString &logfile)
FILE* OpenDump(const wxString& logfile)
{
return wxFopen(Path::Combine(DumpsFolder, logfile), L"w");
}
@ -80,10 +80,10 @@ FILE *OpenDump(const wxString &logfile)
namespace DebugConfig
{
static const wxChar *Section = L"DEBUG";
static const wxChar* Section = L"DEBUG";
void ReadSettings()
{
void ReadSettings()
{
DebugEnabled = CfgReadBool(Section, L"Global_Enable", 0);
_MsgToConsole = CfgReadBool(Section, L"Show_Messages", 0);
_MsgKeyOnOff = CfgReadBool(Section, L"Show_Messages_Key_On_Off", 0);
@ -114,15 +114,16 @@ 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;
}
}
}
void WriteSettings()
{
void WriteSettings()
{
CfgWriteBool(Section, L"Global_Enable", DebugEnabled);
CfgWriteBool(Section, L"Show_Messages", _MsgToConsole);
@ -155,10 +156,10 @@ void WriteSettings()
CfgWriteStr(Section, L"Info_Dump_Filename", CoresDumpFileName);
CfgWriteStr(Section, L"Mem_Dump_Filename", MemDumpFileName);
CfgWriteStr(Section, L"Reg_Dump_Filename", RegDumpFileName);
}
}
static void EnableMessages(HWND hWnd)
{
static void EnableMessages(HWND hWnd)
{
ENABLE_CONTROL(IDC_MSGSHOW, DebugEnabled);
ENABLE_CONTROL(IDC_MSGKEY, MsgToConsole());
ENABLE_CONTROL(IDC_MSGVOICE, MsgToConsole());
@ -166,10 +167,10 @@ static void EnableMessages(HWND hWnd)
ENABLE_CONTROL(IDC_MSGADMA, MsgToConsole());
ENABLE_CONTROL(IDC_DBG_OVERRUNS, MsgToConsole());
ENABLE_CONTROL(IDC_DBG_CACHE, MsgToConsole());
}
}
void EnableControls(HWND hWnd)
{
void EnableControls(HWND hWnd)
{
EnableMessages(hWnd);
ENABLE_CONTROL(IDC_LOGDMA, DebugEnabled);
ENABLE_CONTROL(IDC_LOGREGS, IsDevBuild ? DebugEnabled : false);
@ -178,18 +179,20 @@ void EnableControls(HWND hWnd)
ENABLE_CONTROL(IDC_DUMPMEM, DebugEnabled);
ENABLE_CONTROL(IDC_DUMPREGS, DebugEnabled);
ENABLE_CONTROL(IDC_DEBUG_VISUAL, IsDevBuild ? DebugEnabled : false);
}
}
static BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
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:
@ -210,12 +213,14 @@ static BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
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);
@ -253,15 +258,16 @@ static BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
return FALSE;
}
return TRUE;
}
}
void OpenDialog()
{
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();
}
}
}
} // namespace DebugConfig

View File

@ -32,7 +32,7 @@ static const int SeekWindow_Max = 30;
static const int Overlap_Min = 5;
static const int Overlap_Max = 15;
void SoundtouchCfg::ApplySettings(soundtouch::SoundTouch &sndtouch)
void SoundtouchCfg::ApplySettings(soundtouch::SoundTouch& sndtouch)
{
sndtouch.setSetting(SETTING_SEQUENCE_MS, SequenceLenMS);
sndtouch.setSetting(SETTING_SEEKWINDOW_MS, SeekWindowMS);
@ -67,11 +67,13 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
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);
@ -84,7 +86,8 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
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);
@ -92,7 +95,9 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
ClampValues();
WriteSettings();
EndDialog(hWnd, 0);
} else if (wmId == IDC_RESET_DEFAULTS) {
}
else if (wmId == IDC_RESET_DEFAULTS)
{
SequenceLenMS = 30;
SeekWindowMS = 20;
OverlapMS = 10;
@ -102,7 +107,9 @@ BOOL CALLBACK SoundtouchCfg::DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
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;
@ -121,7 +128,8 @@ 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

@ -23,19 +23,19 @@
namespace DebugConfig
{
extern void ReadSettings();
extern void WriteSettings();
extern void OpenDialog();
extern void EnableControls(HWND hWnd);
}
extern void ReadSettings();
extern void WriteSettings();
extern void OpenDialog();
extern void EnableControls(HWND hWnd);
} // namespace DebugConfig
namespace SoundtouchCfg
{
extern void ReadSettings();
extern void WriteSettings();
extern void OpenDialog(HWND hWnd);
extern BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
}
extern void ReadSettings();
extern void WriteSettings();
extern void OpenDialog(HWND hWnd);
extern BOOL CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
} // namespace SoundtouchCfg
extern int SendDialogMsg(HWND hwnd, int dlgId, UINT code, WPARAM wParam, LPARAM lParam);
@ -44,27 +44,27 @@ extern void AssignSliderValue(HWND hWnd, int idc, int editbox, int value);
extern int GetSliderValue(HWND hWnd, int idc);
extern BOOL DoHandleScrollMessage(HWND hwndDisplay, WPARAM wParam, LPARAM lParam);
extern void CfgSetSettingsDir(const char *dir);
extern void CfgSetLogDir(const char *dir);
extern void CfgSetSettingsDir(const char* dir);
extern void CfgSetLogDir(const char* dir);
extern bool CfgFindName(const TCHAR *Section, const TCHAR *Name);
extern bool CfgFindName(const TCHAR* Section, const TCHAR* Name);
extern void CfgWriteBool(const TCHAR *Section, const TCHAR *Name, bool Value);
extern void CfgWriteInt(const TCHAR *Section, const TCHAR *Name, int Value);
extern void CfgWriteFloat(const TCHAR *Section, const TCHAR *Name, float Value);
extern void CfgWriteStr(const TCHAR *Section, const TCHAR *Name, const wxString &Data);
extern void CfgWriteBool(const TCHAR* Section, const TCHAR* Name, bool Value);
extern void CfgWriteInt(const TCHAR* Section, const TCHAR* Name, int Value);
extern void CfgWriteFloat(const TCHAR* Section, const TCHAR* Name, float Value);
extern void CfgWriteStr(const TCHAR* Section, const TCHAR* Name, const wxString& Data);
extern bool CfgReadBool(const TCHAR *Section, const TCHAR *Name, bool Default);
extern void CfgReadStr(const TCHAR *Section, const TCHAR *Name, wxString &Data, const TCHAR *Default);
extern void CfgReadStr(const TCHAR *Section, const TCHAR *Name, TCHAR *Data, int DataSize, const TCHAR *Default);
extern int CfgReadInt(const TCHAR *Section, const TCHAR *Name, int Default);
extern float CfgReadFloat(const TCHAR *Section, const TCHAR *Name, float Default);
extern bool CfgReadBool(const TCHAR* Section, const TCHAR* Name, bool Default);
extern void CfgReadStr(const TCHAR* Section, const TCHAR* Name, wxString& Data, const TCHAR* Default);
extern void CfgReadStr(const TCHAR* Section, const TCHAR* Name, TCHAR* Data, int DataSize, const TCHAR* Default);
extern int CfgReadInt(const TCHAR* Section, const TCHAR* Name, int Default);
extern float CfgReadFloat(const TCHAR* Section, const TCHAR* Name, float Default);
// Items Specific to DirectSound
#define STRFY(x) #x
#define verifyc(x) Verifyc(x, STRFY(x))
extern void Verifyc(HRESULT hr, const char *fn);
extern void Verifyc(HRESULT hr, const char* fn);
struct ds_device_data
{

View File

@ -56,7 +56,8 @@ void UpdateDebugDialog()
{
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");
}
@ -65,25 +66,30 @@ void UpdateDebugDialog()
SelectObject(hdc, GetStockObject(DC_BRUSH));
SelectObject(hdc, GetStockObject(DC_PEN));
for (int c = 0; c < 2; c++) {
V_Core &cx(Cores[c]);
V_CoreDebug &cd(DebugCores[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;
int IY = 8 + 48 * vv;
V_Voice &vc(cx.Voices[v]);
V_VoiceDebug &vcd(cd.Voices[v]);
V_Voice& vc(cx.Voices[v]);
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)); // light blue for playing voice
if (vc.Modulated) {
if (vc.Modulated)
{
SetDCBrushColor(hdc, RGB(0, 128, 0)); // light green for playing voice with modulation enabled
}
if (vc.Noise) {
if (vc.Noise)
{
SetDCBrushColor(hdc, RGB(128, 0, 0)); // light red for playing voice with noise enabled
}
}
@ -127,19 +133,24 @@ 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);
}
}
@ -200,16 +211,20 @@ 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;
@ -219,12 +234,14 @@ 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;
@ -234,7 +251,8 @@ void UpdateDebugDialog()
else
val = -val;
if (val != 0) {
if (val != 0)
{
FillRectangle(hdc, JX + 136 + j, JY + 30 - y, 1, val);
}
}
@ -254,7 +272,8 @@ 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

@ -51,9 +51,9 @@ private:
HANDLE thread;
DWORD tid;
IDirectSound8 *dsound;
IDirectSoundBuffer8 *buffer;
IDirectSoundNotify8 *buffer_notify;
IDirectSound8* dsound;
IDirectSoundBuffer8* buffer;
IDirectSoundNotify8* buffer_notify;
HANDLE buffer_events[MAX_BUFFER_COUNT];
WAVEFORMATEX wfx;
@ -61,7 +61,7 @@ private:
HANDLE waitEvent;
template <typename T>
static DWORD CALLBACK RThread(DSound *obj)
static DWORD CALLBACK RThread(DSound* obj)
{
return obj->Thread<T>();
}
@ -71,7 +71,8 @@ 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;
@ -80,7 +81,8 @@ 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;
@ -108,14 +110,17 @@ public:
//
GUID cGuid;
try {
try
{
if (m_Device.empty())
throw std::runtime_error("screw it");
if ((FAILED(IIDFromString(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!");
@ -130,7 +135,7 @@ public:
DWORD speakerConfig = 2;
//dsound->GetSpeakerConfig( &speakerConfig );
IDirectSoundBuffer *buffer_;
IDirectSoundBuffer* buffer_;
DSBUFFERDESC desc;
// Set up WAV format structure.
@ -160,8 +165,10 @@ 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;
@ -171,15 +178,16 @@ public:
throw std::runtime_error("DirectSound Error: Buffer could not be created.");
}
if (FAILED(buffer_->QueryInterface(IID_IDirectSoundBuffer8, (void **)&buffer)) || buffer == NULL)
if (FAILED(buffer_->QueryInterface(IID_IDirectSoundBuffer8, (void**)&buffer)) || buffer == NULL)
throw std::runtime_error("DirectSound Error: Interface could not be queried.");
buffer_->Release();
verifyc(buffer->QueryInterface(IID_IDirectSoundNotify8, (void **)&buffer_notify));
verifyc(buffer->QueryInterface(IID_IDirectSoundNotify8, (void**)&buffer_notify));
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];
@ -221,10 +229,12 @@ 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;
@ -243,10 +253,13 @@ private:
{
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++;
@ -261,8 +274,10 @@ private:
int wmId, wmEvent;
int tSel = 0;
switch (uMsg) {
case WM_INITDIALOG: {
switch (uMsg)
{
case WM_INITDIALOG:
{
wchar_t temp[128];
haveGuid = !FAILED(IIDFromString(m_Device, &DevGuid));
@ -272,7 +287,8 @@ 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;
@ -288,21 +304,28 @@ 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,
@ -326,7 +349,8 @@ private:
m_NumBuffers = MAX_BUFFER_COUNT;
EndDialog(hWnd, 0);
} break;
}
break;
case IDCANCEL:
EndDialog(hWnd, 0);
@ -338,12 +362,15 @@ private:
default:
return FALSE;
}
} break;
}
break;
case WM_HSCROLL: {
case WM_HSCROLL:
{
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId) {
switch (wmId)
{
case TB_LINEUP:
case TB_LINEDOWN:
case TB_PAGEUP:
@ -352,7 +379,8 @@ private:
case TB_BOTTOM:
wmEvent = (int)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0);
case TB_THUMBPOSITION:
case TB_THUMBTRACK: {
case TB_THUMBTRACK:
{
wchar_t temp[128];
if (wmEvent < 2)
wmEvent = 2;
@ -366,7 +394,8 @@ private:
default:
return FALSE;
}
} break;
}
break;
default:
return FALSE;
@ -382,7 +411,8 @@ 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;
}
@ -407,12 +437,12 @@ public:
return empty / 2;
}
const wchar_t *GetIdent() const
const wchar_t* GetIdent() const
{
return L"dsound";
}
const wchar_t *GetLongName() const
const wchar_t* GetLongName() const
{
return L"DirectSound (Nice)";
}
@ -452,4 +482,4 @@ BOOL CALLBACK DSound::DSEnumCallback(LPGUID lpGuid, LPCTSTR lpcstrDescription, L
return DS._DSEnumCallback(lpGuid, lpcstrDescription, lpcstrModule, lpContext);
}
SndOutModule *DSoundOut = &DS;
SndOutModule* DSoundOut = &DS;

View File

@ -27,14 +27,15 @@
namespace Exception
{
class XAudio2Error : public std::runtime_error
{
private:
static std::string CreateErrorMessage(const HRESULT result, const std::string &msg)
class XAudio2Error : public std::runtime_error
{
private:
static std::string CreateErrorMessage(const HRESULT result, const std::string& msg)
{
std::stringstream ss;
ss << " (code 0x" << std::hex << result << ")\n\n";
switch (result) {
switch (result)
{
case XAUDIO2_E_INVALID_CALL:
ss << "Invalid call for the XA2 object state.";
break;
@ -48,13 +49,13 @@ private:
return msg + ss.str();
}
public:
explicit XAudio2Error(const HRESULT result, const std::string &msg)
public:
explicit XAudio2Error(const HRESULT result, const std::string& msg)
: std::runtime_error(CreateErrorMessage(result, msg))
{
}
};
}
};
} // namespace Exception
static const double SndOutNormalizer = (double)(1UL << (SndOutVolumeShift + 16));
@ -67,7 +68,7 @@ private:
class BaseStreamingVoice : public IXAudio2VoiceCallback
{
protected:
IXAudio2SourceVoice *pSourceVoice;
IXAudio2SourceVoice* pSourceVoice;
std::unique_ptr<s16[]> m_buffer;
const uint m_nBuffers;
@ -100,12 +101,12 @@ private:
InitializeCriticalSection(&cs);
}
virtual void Init(IXAudio2 *pXAudio2) = 0;
virtual void Init(IXAudio2* pXAudio2) = 0;
protected:
// Several things must be initialized separate of the constructor, due to the fact that
// virtual calls can't be made from the constructor's context.
void _init(IXAudio2 *pXAudio2, uint chanConfig)
void _init(IXAudio2* pXAudio2, uint chanConfig)
{
WAVEFORMATEXTENSIBLE wfx;
@ -122,8 +123,9 @@ private:
wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
HRESULT hr;
if (FAILED(hr = pXAudio2->CreateSourceVoice(&pSourceVoice, (WAVEFORMATEX *)&wfx,
XAUDIO2_VOICE_NOSRC, 1.0f, this))) {
if (FAILED(hr = pXAudio2->CreateSourceVoice(&pSourceVoice, (WAVEFORMATEX*)&wfx,
XAUDIO2_VOICE_NOSRC, 1.0f, this)))
{
throw Exception::XAudio2Error(hr, "XAudio2 CreateSourceVoice failure: ");
}
@ -135,11 +137,12 @@ private:
m_buffer = std::make_unique<s16[]>(m_nBuffers * m_BufferSize);
// 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 = &m_buffer[i * m_BufferSize];
buf.pAudioData = (BYTE *)buf.pContext;
buf.pAudioData = (BYTE*)buf.pContext;
pSourceVoice->SubmitSourceBuffer(&buf);
}
@ -155,11 +158,11 @@ private:
STDMETHOD_(void, OnStreamEnd)
() {}
STDMETHOD_(void, OnBufferStart)
(void *) {}
(void*) {}
STDMETHOD_(void, OnLoopEnd)
(void *) {}
(void*) {}
STDMETHOD_(void, OnVoiceError)
(THIS_ void *pBufferContext, HRESULT Error) {}
(THIS_ void* pBufferContext, HRESULT Error) {}
};
template <typename T>
@ -173,11 +176,12 @@ private:
virtual ~StreamingVoice()
{
IXAudio2SourceVoice *killMe = pSourceVoice;
IXAudio2SourceVoice* killMe = pSourceVoice;
// XXX: Potentially leads to a race condition that causes a nullptr
// dereference when SubmitSourceBuffer is called in OnBufferEnd?
pSourceVoice = nullptr;
if (killMe != nullptr) {
if (killMe != nullptr)
{
killMe->FlushSourceBuffers();
killMe->DestroyVoice();
}
@ -191,10 +195,11 @@ private:
LeaveCriticalSection(&cs);
}
void Init(IXAudio2 *pXAudio2)
void Init(IXAudio2* pXAudio2)
{
int chanMask = 0;
switch (m_nChannels) {
switch (m_nChannels)
{
case 1:
chanMask |= SPEAKER_FRONT_CENTER;
break;
@ -222,26 +227,27 @@ private:
protected:
STDMETHOD_(void, OnBufferEnd)
(void *context)
(void* context)
{
EnterCriticalSection(&cs);
// All of these checks are necessary because XAudio2 is wonky shizat.
// XXX: The pSourceVoice nullptr check seems a bit self-inflicted
// due to the destructor logic.
if (pSourceVoice == nullptr || context == nullptr) {
if (pSourceVoice == nullptr || context == nullptr)
{
LeaveCriticalSection(&cs);
return;
}
T *qb = (T *)context;
T* qb = (T*)context;
for (int p = 0; p < PacketsPerBuffer; p++, qb += SndOutPacketSize)
SndBuffer::ReadSamples(qb);
XAUDIO2_BUFFER buf = {0};
buf.AudioBytes = m_BufferSizeBytes;
buf.pAudioData = (BYTE *)context;
buf.pAudioData = (BYTE*)context;
buf.pContext = context;
pSourceVoice->SubmitSourceBuffer(&buf);
@ -252,7 +258,7 @@ private:
HMODULE xAudio2DLL = nullptr;
decltype(&XAudio2Create) pXAudio2Create = nullptr;
CComPtr<IXAudio2> pXAudio2;
IXAudio2MasteringVoice *pMasteringVoice = nullptr;
IXAudio2MasteringVoice* pMasteringVoice = nullptr;
std::unique_ptr<BaseStreamingVoice> m_voiceContext;
public:
@ -260,7 +266,8 @@ public:
{
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
try {
try
{
HRESULT hr;
xAudio2DLL = LoadLibraryEx(XAUDIO2_DLL, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
@ -280,7 +287,8 @@ public:
int speakers;
// speakers = (numSpeakers + 1) *2; ?
switch (numSpeakers) {
switch (numSpeakers)
{
case 0: // Stereo
speakers = 2;
break;
@ -300,7 +308,8 @@ public:
if (FAILED(hr = pXAudio2->CreateMasteringVoice(&pMasteringVoice, speakers, SampleRate)))
throw Exception::XAudio2Error(hr, "Failed creating mastering voice: ");
switch (speakers) {
switch (speakers)
{
case 2:
ConLog("* SPU2 > Using normal 2 speaker stereo output.\n");
m_voiceContext = std::make_unique<StreamingVoice<StereoOut16>>();
@ -319,7 +328,8 @@ public:
break;
case 6:
case 7:
switch (dplLevel) {
switch (dplLevel)
{
case 0: // "normal" stereo upmix
ConLog("* SPU2 > 5.1 speaker expansion enabled.\n");
m_voiceContext = std::make_unique<StreamingVoice<Stereo51Out16>>();
@ -341,7 +351,9 @@ public:
}
m_voiceContext->Init(pXAudio2);
} catch (std::runtime_error &ex) {
}
catch (std::runtime_error& ex)
{
SysMessage(ex.what());
Close();
return -1;
@ -371,7 +383,8 @@ public:
pXAudio2.Release();
CoUninitialize();
if (xAudio2DLL) {
if (xAudio2DLL)
{
FreeLibrary(xAudio2DLL);
xAudio2DLL = nullptr;
pXAudio2Create = nullptr;
@ -394,12 +407,12 @@ public:
return m_voiceContext->GetEmptySampleCount();
}
const wchar_t *GetIdent() const
const wchar_t* GetIdent() const
{
return L"xaudio2";
}
const wchar_t *GetLongName() const
const wchar_t* GetLongName() const
{
return L"XAudio 2 (Recommended)";
}
@ -418,4 +431,4 @@ public:
} static XA2;
SndOutModule *XAudio2Out = &XA2;
SndOutModule* XAudio2Out = &XA2;

View File

@ -30,7 +30,7 @@ private:
WAVEFORMATEX wformat;
WAVEHDR whbuffer[MAX_BUFFER_COUNT];
StereoOut16 *qbuffer;
StereoOut16* qbuffer;
#define QBUFFER(x) (qbuffer + BufferSize * (x))
@ -45,17 +45,19 @@ private:
{
static const int BufferSizeBytes = BufferSize * sizeof(T);
while (waveout_running) {
while (waveout_running)
{
bool didsomething = false;
for (u32 i = 0; i < numBuffers; i++) {
for (u32 i = 0; i < numBuffers; i++)
{
if (!(whbuffer[i].dwFlags & WHDR_DONE))
continue;
WAVEHDR *buf = whbuffer + i;
WAVEHDR* buf = whbuffer + i;
buf->dwBytesRecorded = buf->dwBufferLength;
T *t = (T *)buf->lpData;
T* t = (T*)buf->lpData;
for (int p = 0; p < PacketsPerBuffer; p++, t += SndOutPacketSize)
SndBuffer::ReadSamples(t);
@ -73,7 +75,7 @@ private:
}
template <typename T>
static DWORD CALLBACK RThread(WaveOutModule *obj)
static DWORD CALLBACK RThread(WaveOutModule* obj)
{
return obj->Thread<T>();
}
@ -88,7 +90,7 @@ public:
if (Test())
return -1;
// TODO : Use dsound to determine the speaker configuration, and expand audio from there.
// TODO : Use dsound to determine the speaker configuration, and expand audio from there.
#if 0
int speakerConfig;
@ -140,15 +142,17 @@ public:
qbuffer = new StereoOut16[BufferSize * numBuffers];
woores = waveOutOpen(&hwodevice, WAVE_MAPPER, &wformat, 0, 0, 0);
if (woores != MMSYSERR_NOERROR) {
waveOutGetErrorText(woores, (wchar_t *)&ErrText, 255);
if (woores != MMSYSERR_NOERROR)
{
waveOutGetErrorText(woores, (wchar_t*)&ErrText, 255);
SysMessage("WaveOut Error: %s", ErrText);
return -1;
}
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;
@ -187,7 +191,8 @@ 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);
@ -200,7 +205,8 @@ private:
{
int wmId, wmEvent;
switch (uMsg) {
switch (uMsg)
{
case WM_INITDIALOG:
wchar_t temp[128];
@ -214,8 +220,10 @@ 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)
@ -236,7 +244,8 @@ private:
case WM_HSCROLL:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId) {
switch (wmId)
{
case TB_LINEUP:
case TB_LINEDOWN:
case TB_PAGEUP:
@ -270,7 +279,8 @@ 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;
}
@ -278,7 +288,8 @@ public:
s32 Test() const
{
if (waveOutGetNumDevs() == 0) {
if (waveOutGetNumDevs() == 0)
{
SysMessage("No waveOut Devices Present\n");
return -1;
}
@ -288,18 +299,19 @@ 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;
}
const wchar_t *GetIdent() const
const wchar_t* GetIdent() const
{
return L"waveout";
}
const wchar_t *GetLongName() const
const wchar_t* GetLongName() const
{
return L"WaveOut (Laggy)";
}
@ -318,4 +330,4 @@ public:
} static WO;
SndOutModule *WaveOut = &WO;
SndOutModule* WaveOut = &WO;

View File

@ -21,9 +21,10 @@ int SendDialogMsg(HWND hwnd, int dlgId, UINT code, WPARAM wParam, LPARAM lParam)
return SendMessage(GetDlgItem(hwnd, dlgId), code, wParam, lParam);
}
__forceinline void Verifyc(HRESULT hr, const char *fn)
__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");
}
@ -52,7 +53,8 @@ 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:

View File

@ -23,14 +23,14 @@
extern "C" {
#include "dsp.h"
typedef winampDSPHeader *(*pWinampDSPGetHeader2)();
typedef winampDSPHeader* (*pWinampDSPGetHeader2)();
}
HMODULE hLib = NULL;
pWinampDSPGetHeader2 pGetHeader = NULL;
winampDSPHeader *pHeader = NULL;
winampDSPHeader* pHeader = NULL;
winampDSPModule *pModule = NULL;
winampDSPModule* pModule = NULL;
HWND hTemp;
@ -44,7 +44,7 @@ bool running;
DWORD WINAPI DspUpdateThread(PVOID param);
#endif
s32 DspLoadLibrary(wchar_t *fileName, int modNum)
s32 DspLoadLibrary(wchar_t* fileName, int modNum)
#ifdef USE_A_THREAD
{
if (!dspPluginEnabled)
@ -55,20 +55,22 @@ s32 DspLoadLibrary(wchar_t *fileName, int modNum)
return (hUpdateThread == INVALID_HANDLE_VALUE);
}
s32 DspLoadLibrary2(wchar_t *fileName, int modNum)
s32 DspLoadLibrary2(wchar_t* fileName, int modNum)
#endif
{
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;
@ -78,7 +80,8 @@ s32 DspLoadLibrary2(wchar_t *fileName, int modNum)
pModule = pHeader->getModule(modNum);
if (!pModule) {
if (!pModule)
{
pGetHeader = NULL;
pHeader = NULL;
FreeLibrary(hLib);
@ -101,7 +104,8 @@ void DspCloseLibrary()
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);
}
@ -113,7 +117,8 @@ void DspCloseLibrary2()
if (!dspPluginEnabled)
return;
if (hLib) {
if (hLib)
{
pModule->Quit(pModule);
FreeLibrary(hLib);
}
@ -123,12 +128,13 @@ void DspCloseLibrary2()
hLib = NULL;
}
int DspProcess(s16 *buffer, int samples)
int DspProcess(s16* buffer, int samples)
{
if (!dspPluginEnabled)
return samples;
if (hLib) {
if (hLib)
{
return pModule->ModifySamples(pModule, buffer, samples, 16, 2, SampleRate);
}
return samples;
@ -148,9 +154,11 @@ DWORD WINAPI DspUpdateThread(PVOID param)
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);
@ -167,7 +175,8 @@ DWORD WINAPI DspUpdateThread(PVOID param)
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

@ -26,32 +26,32 @@
typedef struct winampDSPModule
{
char *description; // description
char* description; // description
HWND hwndParent; // parent window (filled in by calling app)
HINSTANCE hDllInstance; // instance handle to this DLL (filled in by calling app)
void (*Config)(struct winampDSPModule *this_mod); // configuration dialog (if needed)
int (*Init)(struct winampDSPModule *this_mod); // 0 on success, creates window, etc (if needed)
void (*Config)(struct winampDSPModule* this_mod); // configuration dialog (if needed)
int (*Init)(struct winampDSPModule* this_mod); // 0 on success, creates window, etc (if needed)
// modify waveform samples: returns number of samples to actually write
// (typically numsamples, but no more than twice numsamples, and no less than half numsamples)
// numsamples should always be at least 128. should, but I'm not sure
int (*ModifySamples)(struct winampDSPModule *this_mod, short int *samples, int numsamples, int bps, int nch, int srate);
int (*ModifySamples)(struct winampDSPModule* this_mod, short int* samples, int numsamples, int bps, int nch, int srate);
void (*Quit)(struct winampDSPModule *this_mod); // called when unloading
void (*Quit)(struct winampDSPModule* this_mod); // called when unloading
void *userData; // user data, optional
void* userData; // user data, optional
} winampDSPModule;
typedef struct
{
int version; // DSP_HDRVER
char *description; // description of library
winampDSPModule *(*getModule)(int); // module retrieval function
char* description; // description of library
winampDSPModule* (*getModule)(int); // module retrieval function
} winampDSPHeader;
// exported symbols
typedef winampDSPHeader *(*winampDSPGetHeaderType)();
typedef winampDSPHeader* (*winampDSPGetHeaderType)();
// header version: 0x20 == 0.20 == winamp 2.0
#define DSP_HDRVER 0x20

View File

@ -22,10 +22,10 @@
// SPU2 Memory Indexers
// --------------------------------------------------------------------------------------
#define spu2Rs16(mmem) (*(s16 *)((s8 *)spu2regs + ((mmem)&0x1fff)))
#define spu2Ru16(mmem) (*(u16 *)((s8 *)spu2regs + ((mmem)&0x1fff)))
#define spu2Rs16(mmem) (*(s16*)((s8*)spu2regs + ((mmem)&0x1fff)))
#define spu2Ru16(mmem) (*(u16*)((s8*)spu2regs + ((mmem)&0x1fff)))
extern s16 *GetMemPtr(u32 addr);
extern s16* GetMemPtr(u32 addr);
extern s16 spu2M_Read(u32 addr);
extern void spu2M_Write(u32 addr, s16 value);
extern void spu2M_Write(u32 addr, u16 value);
@ -45,7 +45,7 @@ struct V_VolumeLR
{
}
void DebugDump(FILE *dump, const char *title);
void DebugDump(FILE* dump, const char* title);
};
struct V_VolumeSlide
@ -70,7 +70,7 @@ public:
void Update();
void RegSet(u16 src); // used to set the volume from a register source (16 bit signed)
void DebugDump(FILE *dump, const char *title, const char *nameLR);
void DebugDump(FILE* dump, const char* title, const char* nameLR);
};
struct V_VolumeSlideLR
@ -94,7 +94,7 @@ public:
Right.Update();
}
void DebugDump(FILE *dump, const char *title);
void DebugDump(FILE* dump, const char* title);
};
struct V_ADSR
@ -182,7 +182,7 @@ struct V_Voice
s32 NextCrest; // temp value for Crest calculation
// SBuffer now points directly to an ADPCM cache entry.
s16 *SBuffer;
s16* SBuffer;
// sample position within the current decoded packet.
s32 SCurrent;
@ -362,7 +362,7 @@ struct VoiceMixSet
StereoOut32 Dry, Wet;
VoiceMixSet() {}
VoiceMixSet(const StereoOut32 &dry, const StereoOut32 &wet)
VoiceMixSet(const StereoOut32& dry, const StereoOut32& wet)
: Dry(dry)
, Wet(wet)
{
@ -435,7 +435,7 @@ struct V_Core
u32 AutoDmaFree;
// old dma only
u16 *DMAPtr;
u16* DMAPtr;
u32 MADR;
u32 TADR;
@ -476,9 +476,9 @@ struct V_Core
// Mixer Section
// --------------------------------------------------------------------------------------
StereoOut32 Mix(const VoiceMixSet &inVoices, const StereoOut32 &Input, const StereoOut32 &Ext);
StereoOut32 Mix(const VoiceMixSet& inVoices, const StereoOut32& Input, const StereoOut32& Ext);
void Reverb_AdvanceBuffer();
StereoOut32 DoReverb(const StereoOut32 &Input);
StereoOut32 DoReverb(const StereoOut32& Input);
s32 RevbGetIndexer(s32 offset);
StereoOut32 ReadInput();
@ -515,19 +515,19 @@ struct V_Core
TSA &= 0xfffff;
}
void LogAutoDMA(FILE *fp);
void LogAutoDMA(FILE* fp);
s32 NewDmaRead(u32 *data, u32 bytesLeft, u32 *bytesProcessed);
s32 NewDmaWrite(u32 *data, u32 bytesLeft, u32 *bytesProcessed);
s32 NewDmaRead(u32* data, u32 bytesLeft, u32* bytesProcessed);
s32 NewDmaWrite(u32* data, u32 bytesLeft, u32* bytesProcessed);
void NewDmaInterrupt();
// old dma only
void DoDMAwrite(u16 *pMem, u32 size);
void DoDMAread(u16 *pMem, u32 size);
void DoDMAwrite(u16* pMem, u32 size);
void DoDMAread(u16* pMem, u32 size);
void AutoDMAReadBuffer(int mode);
void StartADMAWrite(u16 *pMem, u32 sz);
void PlainDMAWrite(u16 *pMem, u32 sz);
void StartADMAWrite(u16* pMem, u32 sz);
void PlainDMAWrite(u16* pMem, u32 sz);
};
extern V_Core Cores[2];
@ -540,25 +540,25 @@ extern s16 InputPos;
// SPU Mixing Cycles ("Ticks mixed" counter)
extern u32 Cycles;
extern s16 *spu2regs;
extern s16 *_spu2mem;
extern s16* spu2regs;
extern s16* _spu2mem;
extern int PlayMode;
extern void SetIrqCall(int core);
extern void StartVoices(int core, u32 value);
extern void StopVoices(int core, u32 value);
extern void InitADSR();
extern void CalculateADSR(V_Voice &vc);
extern void CalculateADSR(V_Voice& vc);
extern void UpdateSpdifMode();
namespace SPU2Savestate
{
struct DataBlock;
struct DataBlock;
extern s32 __fastcall FreezeIt(DataBlock &spud);
extern s32 __fastcall ThawIt(DataBlock &spud);
extern s32 __fastcall SizeIt();
}
extern s32 __fastcall FreezeIt(DataBlock& spud);
extern s32 __fastcall ThawIt(DataBlock& spud);
extern s32 __fastcall SizeIt();
} // namespace SPU2Savestate
// --------------------------------------------------------------------------------------
// ADPCM Decoder Cache
@ -584,4 +584,4 @@ struct PcmCacheEntry
s16 Sampledata[pcm_DecodedSamplesPerBlock];
};
extern PcmCacheEntry *pcm_cache_data;
extern PcmCacheEntry* pcm_cache_data;

View File

@ -184,10 +184,10 @@ Core attributes (SD_C)
// SPU2-X Register Table LUT
// --------------------------------------------------------------------------------------
#define U16P(x) ((u16 *)&(x))
#define U16P(x) ((u16*)&(x))
// Returns the hiword of a 32 bit integer.
#define U16P_HI(x) (((u16 *)&(x)) + 1)
#define U16P_HI(x) (((u16*)&(x)) + 1)
extern u16 *regtable[0x401];
extern u16 const *const regtable_original[0x401];
extern u16* regtable[0x401];
extern u16 const* const regtable_original[0x401];

View File

@ -41,7 +41,7 @@ static bool IsInitialized = false;
static u32 pClocks = 0;
u32 *cyclePtr = NULL;
u32* cyclePtr = NULL;
u32 lClocks = 0;
@ -77,7 +77,7 @@ void SPU2configure()
// DMA 4/7 Callbacks from Core Emulator
// --------------------------------------------------------------------------------------
u16 *DMABaseAddr;
u16* DMABaseAddr;
u32 SPU2ReadMemAddr(int core)
{
@ -90,20 +90,20 @@ void SPU2WriteMemAddr(int core, u32 value)
void SPU2setDMABaseAddr(uptr baseaddr)
{
DMABaseAddr = (u16 *)baseaddr;
DMABaseAddr = (u16*)baseaddr;
}
void SPU2setSettingsDir(const char *dir)
void SPU2setSettingsDir(const char* dir)
{
CfgSetSettingsDir(dir);
}
void SPU2setLogDir(const char *dir)
void SPU2setLogDir(const char* dir)
{
CfgSetLogDir(dir);
}
void SPU2readDMA4Mem(u16 *pMem, u32 size) // size now in 16bit units
void SPU2readDMA4Mem(u16* pMem, u32 size) // size now in 16bit units
{
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
@ -112,7 +112,7 @@ void SPU2readDMA4Mem(u16 *pMem, u32 size) // size now in 16bit units
Cores[0].DoDMAread(pMem, size);
}
void SPU2writeDMA4Mem(u16 *pMem, u32 size) // size now in 16bit units
void SPU2writeDMA4Mem(u16* pMem, u32 size) // size now in 16bit units
{
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
@ -139,7 +139,7 @@ void SPU2interruptDMA7()
//Cores[1].Regs.ATTR &= ~0x30;
}
void SPU2readDMA7Mem(u16 *pMem, u32 size)
void SPU2readDMA7Mem(u16* pMem, u32 size)
{
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
@ -148,7 +148,7 @@ void SPU2readDMA7Mem(u16 *pMem, u32 size)
Cores[1].DoDMAread(pMem, size);
}
void SPU2writeDMA7Mem(u16 *pMem, u32 size)
void SPU2writeDMA7Mem(u16* pMem, u32 size)
{
if (cyclePtr != NULL)
TimeUpdate(*cyclePtr);
@ -168,10 +168,12 @@ s32 SPU2reset()
SampleRate = 48000;
SndBuffer::Cleanup();
try {
try
{
SndBuffer::Init();
}
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;
@ -197,10 +199,12 @@ s32 SPU2ps1reset()
SampleRate = 44100;
SndBuffer::Cleanup();
try {
try
{
SndBuffer::Init();
}
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;
@ -221,7 +225,8 @@ s32 SPU2init()
{
assert(regtable[0x400] == NULL);
if (IsInitialized) {
if (IsInitialized)
{
printf(" * SPU2-X: Already initialized - Ignoring SPU2init signal.");
return 0;
}
@ -232,7 +237,8 @@ s32 SPU2init()
ReadSettings();
#ifdef SPU2_LOG
if (AccessLog()) {
if (AccessLog())
{
spu2Log = OpenLog(AccessLogFileName);
setvbuf(spu2Log, NULL, _IONBF, 0);
FileLog("SPU2init\n");
@ -240,8 +246,8 @@ s32 SPU2init()
#endif
srand((unsigned)time(NULL));
spu2regs = (s16 *)malloc(0x010000);
_spu2mem = (s16 *)malloc(0x200000);
spu2regs = (s16*)malloc(0x010000);
_spu2mem = (s16*)malloc(0x200000);
// adpcm decoder cache:
// the cache data size is determined by taking the number of adpcm blocks
@ -250,9 +256,10 @@ s32 SPU2init()
// Expanded: 16 bytes expands to 56 bytes [3.5:1 ratio]
// Resulting in 2MB * 3.5.
pcm_cache_data = (PcmCacheEntry *)calloc(pcm_BlockCount, sizeof(PcmCacheEntry));
pcm_cache_data = (PcmCacheEntry*)calloc(pcm_BlockCount, sizeof(PcmCacheEntry));
if ((spu2regs == NULL) || (_spu2mem == NULL) || (pcm_cache_data == NULL)) {
if ((spu2regs == NULL) || (_spu2mem == NULL) || (pcm_cache_data == NULL))
{
SysMessage("SPU2-X: Error allocating Memory\n");
return -1;
}
@ -261,9 +268,11 @@ s32 SPU2init()
memcpy(regtable, regtable_original, sizeof(regtable));
for (uint mem = 0; mem < 0x800; mem++) {
u16 *ptr = regtable[mem >> 1];
if (!ptr) {
for (uint mem = 0; mem < 0x800; mem++)
{
u16* ptr = regtable[mem >> 1];
if (!ptr)
{
regtable[mem >> 1] = &(spu2Ru16(mem));
}
}
@ -289,17 +298,21 @@ static INT_PTR CALLBACK DebugProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
{
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;
@ -318,28 +331,32 @@ static INT_PTR CALLBACK DebugProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
#endif
uptr gsWindowHandle = 0;
s32 SPU2open(void *pDsp)
s32 SPU2open(void* pDsp)
{
ScopedLock lock( mtx_SPU2Status );
ScopedLock lock(mtx_SPU2Status);
if (IsOpened)
return 0;
FileLog("[%10d] SPU2 Open\n", Cycles);
if (pDsp != NULL)
gsWindowHandle = *(uptr *)pDsp;
gsWindowHandle = *(uptr*)pDsp;
else
gsWindowHandle = 0;
#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;
}
@ -349,14 +366,17 @@ 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;
@ -368,7 +388,7 @@ s32 SPU2open(void *pDsp)
void SPU2close()
{
ScopedLock lock( mtx_SPU2Status );
ScopedLock lock(mtx_SPU2Status);
if (!IsOpened)
return;
IsOpened = false;
@ -425,7 +445,7 @@ void SPU2shutdown()
#endif
}
void SPU2setClockPtr(u32 *ptr)
void SPU2setClockPtr(u32* ptr)
{
cyclePtr = ptr;
}
@ -439,25 +459,31 @@ 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");
}
@ -465,9 +491,11 @@ void SPU2async(u32 cycles)
lState[i] = cState[i];
}
if (Interpolation != oldI) {
if (Interpolation != oldI)
{
printf("Interpolation set to %d", Interpolation);
switch (Interpolation) {
switch (Interpolation)
{
case 0:
printf(" - Nearest.\n");
break;
@ -501,23 +529,32 @@ u16 SPU2read(u32 rmem)
u16 ret = 0xDEAD;
u32 core = 0, mem = rmem & 0xFFFF, omem = mem;
if (mem & 0x400) {
if (mem & 0x400)
{
omem ^= 0x400;
core = 1;
}
if (omem == 0x1f9001AC) {
if (omem == 0x1f9001AC)
{
ret = Cores[core].DmaRead();
} else {
}
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);
@ -543,7 +580,8 @@ 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);
}
@ -562,29 +600,33 @@ int SPU2setupRecording(int start, std::wstring* filename)
return 0;
}
s32 SPU2freeze(int mode, freezeData *data)
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 = SPU2Savestate::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;
}
SPU2Savestate::DataBlock &spud = (SPU2Savestate::DataBlock &)*(data->data);
SPU2Savestate::DataBlock& spud = (SPU2Savestate::DataBlock&)*(data->data);
switch (mode) {
switch (mode)
{
case FREEZE_LOAD:
return SPU2Savestate::ThawIt(spud);
case FREEZE_SAVE:
@ -597,37 +639,39 @@ s32 SPU2freeze(int mode, freezeData *data)
return 0;
}
void SPU2DoFreezeOut( void* dest )
void SPU2DoFreezeOut(void* dest)
{
ScopedLock lock( mtx_SPU2Status );
ScopedLock lock(mtx_SPU2Status);
freezeData fP = { 0, (s8*)dest };
if (SPU2freeze( FREEZE_SIZE, &fP)!=0) return;
if (!fP.size) return;
freezeData fP = {0, (s8*)dest};
if (SPU2freeze(FREEZE_SIZE, &fP) != 0)
return;
if (!fP.size)
return;
Console.Indent().WriteLn( "Saving SPU-2");
Console.Indent().WriteLn("Saving SPU-2");
if (SPU2freeze(FREEZE_SAVE, &fP)!=0)
if (SPU2freeze(FREEZE_SAVE, &fP) != 0)
throw std::runtime_error(" * SPU-2: Error saving state!\n");
}
void SPU2DoFreezeIn( pxInputStream& infp )
void SPU2DoFreezeIn(pxInputStream& infp)
{
ScopedLock lock( mtx_SPU2Status );
ScopedLock lock(mtx_SPU2Status);
freezeData fP = { 0, NULL };
if (SPU2freeze( FREEZE_SIZE, &fP )!=0)
freezeData fP = {0, NULL};
if (SPU2freeze(FREEZE_SIZE, &fP) != 0)
fP.size = 0;
Console.Indent().WriteLn( "Loading SPU-2");
Console.Indent().WriteLn("Loading SPU-2");
if (!infp.IsOk() || !infp.Length())
{
// no state data to read, but SPU-2 expects some state data?
// Issue a warning to console...
if( fP.size != 0 )
Console.Indent().Warning( "Warning: No data for SPU-2 found. Status may be unpredictable." );
if (fP.size != 0)
Console.Indent().Warning("Warning: No data for SPU-2 found. Status may be unpredictable.");
return;
@ -637,10 +681,10 @@ void SPU2DoFreezeIn( pxInputStream& infp )
// on the status of the plugin when loading, so let's ignore it.
}
ScopedAlloc<s8> data( fP.size );
ScopedAlloc<s8> data(fP.size);
fP.data = data.GetPtr();
infp.Read( fP.data, fP.size );
if (SPU2freeze(FREEZE_LOAD, &fP)!=0)
infp.Read(fP.data, fP.size);
if (SPU2freeze(FREEZE_LOAD, &fP) != 0)
throw std::runtime_error(" * SPU-2: Error loading state!\n");
}

View File

@ -26,7 +26,7 @@ extern bool SPU2_dummy_callback;
s32 SPU2init();
s32 SPU2reset();
s32 SPU2ps1reset();
s32 SPU2open(void *pDsp);
s32 SPU2open(void* pDsp);
void SPU2close();
void SPU2shutdown();
void SPU2write(u32 mem, u16 value);
@ -38,40 +38,40 @@ u16 SPU2read(u32 mem);
// for now, pData is not used
int SPU2setupRecording(int start, std::wstring* filename);
void SPU2setClockPtr(u32 *ptr);
void SPU2setClockPtr(u32* ptr);
void SPU2async(u32 cycles);
s32 SPU2freeze(int mode, freezeData *data);
void SPU2DoFreezeIn( pxInputStream& infp );
void SPU2DoFreezeOut( void* dest );
s32 SPU2freeze(int mode, freezeData* data);
void SPU2DoFreezeIn(pxInputStream& infp);
void SPU2DoFreezeOut(void* dest);
void SPU2configure();
u32 SPU2ReadMemAddr(int core);
void SPU2WriteMemAddr(int core, u32 value);
void SPU2setDMABaseAddr(uptr baseaddr);
void SPU2setSettingsDir(const char *dir);
void SPU2setLogDir(const char *dir);
void SPU2readDMA4Mem(u16 *pMem, u32 size);
void SPU2writeDMA4Mem(u16 *pMem, u32 size);
void SPU2setSettingsDir(const char* dir);
void SPU2setLogDir(const char* dir);
void SPU2readDMA4Mem(u16* pMem, u32 size);
void SPU2writeDMA4Mem(u16* pMem, u32 size);
void SPU2interruptDMA4();
void SPU2interruptDMA7();
void SPU2readDMA7Mem(u16 *pMem, u32 size);
void SPU2writeDMA7Mem(u16 *pMem, u32 size);
void SPU2readDMA7Mem(u16* pMem, u32 size);
void SPU2writeDMA7Mem(u16* pMem, u32 size);
#include "spu2replay.h"
extern u8 callirq;
extern s16 *input_data;
extern s16* input_data;
extern u32 input_data_ptr;
extern double srate_pv;
extern int recording;
extern u32 lClocks;
extern u32 *cyclePtr;
extern u32* cyclePtr;
extern void SPU2writeLog(const char *action, u32 rmem, u16 value);
extern void SPU2writeLog(const char* action, u32 rmem, u16 value);
extern void TimeUpdate(u32 cClocks);
extern void SPU2_FastWrite(u32 rmem, u16 value);

View File

@ -18,18 +18,18 @@
namespace SPU2Savestate
{
// Arbitrary ID to identify SPU2-X saves.
static const u32 SAVE_ID = 0x1227521;
// Arbitrary ID to identify SPU2-X saves.
static const u32 SAVE_ID = 0x1227521;
// versioning for saves.
// Increment this when changes to the savestate system are made.
static const u32 SAVE_VERSION = 0x000e;
// versioning for saves.
// Increment this when changes to the savestate system are made.
static const u32 SAVE_VERSION = 0x000e;
static void wipe_the_cache()
{
static void wipe_the_cache()
{
memset(pcm_cache_data, 0, pcm_BlockCount * sizeof(PcmCacheEntry));
}
}
}
} // namespace SPU2Savestate
struct SPU2Savestate::DataBlock
{
@ -47,7 +47,7 @@ struct SPU2Savestate::DataBlock
int PlayMode;
};
s32 __fastcall SPU2Savestate::FreezeIt(DataBlock &spud)
s32 __fastcall SPU2Savestate::FreezeIt(DataBlock& spud)
{
spud.spu2id = SAVE_ID;
spud.version = SAVE_VERSION;
@ -76,9 +76,10 @@ s32 __fastcall SPU2Savestate::FreezeIt(DataBlock &spud)
return 0;
}
s32 __fastcall SPU2Savestate::ThawIt(DataBlock &spud)
s32 __fastcall SPU2Savestate::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 PCSX2.\n");
@ -97,7 +98,9 @@ s32 __fastcall SPU2Savestate::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 components are shut down. That's a no-no! It shouldn't crash, but the savestate will probably be corrupted.");
@ -122,8 +125,10 @@ s32 __fastcall SPU2Savestate::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

@ -20,7 +20,7 @@
#include "Windows.h"
#endif
FILE *s2rfile;
FILE* s2rfile;
void s2r_write16(s16 data)
{
@ -37,7 +37,7 @@ static void EMITC(u32 i, u32 a)
s2r_write32(((i & 0x7u) << 29u) | (a & 0x1FFFFFFFu));
}
int s2r_open(u32 ticks, char *filename)
int s2r_open(u32 ticks, char* filename)
{
s2rfile = fopen(filename, "wb");
if (s2rfile)
@ -62,7 +62,7 @@ void s2r_writereg(u32 ticks, u32 addr, s16 value)
s2r_write16(value);
}
void s2r_writedma4(u32 ticks, u16 *data, u32 len)
void s2r_writedma4(u32 ticks, u16* data, u32 len)
{
u32 i;
if (!s2rfile)
@ -73,7 +73,7 @@ void s2r_writedma4(u32 ticks, u16 *data, u32 len)
s2r_write16(*data);
}
void s2r_writedma7(u32 ticks, u16 *data, u32 len)
void s2r_writedma7(u32 ticks, u16* data, u32 len)
{
u32 i;
if (!s2rfile)
@ -112,7 +112,7 @@ bool Running = false;
#ifdef _MSC_VER
int conprintf(const char *fmt, ...)
int conprintf(const char* fmt, ...)
{
#ifdef _WIN32
char s[1024];
@ -144,7 +144,7 @@ u64 HighResFrequency()
{
u64 freq;
#ifdef _WIN32
QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
#else
// TODO
#endif
@ -155,7 +155,7 @@ u64 HighResCounter()
{
u64 time;
#ifdef _WIN32
QueryPerformanceCounter((LARGE_INTEGER *)&time);
QueryPerformanceCounter((LARGE_INTEGER*)&time);
#else
// TODO
#endif
@ -214,16 +214,18 @@ s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdShow)
#endif
// load file
FILE *file = fopen(filename, "rb");
FILE* file = fopen(filename, "rb");
if (!file) {
if (!file)
{
conprintf("Could not open the replay file.");
return;
}
// if successful, init the plugin
// if successful, init the plugin
#define TryRead(dest, size, count, file) \
if (fread(dest, size, count, file) < count) { \
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 */ \
}
@ -243,7 +245,8 @@ s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdShow)
SPU2async(0);
while (!feof(file) && Running) {
while (!feof(file) && Running)
{
u32 ccycle = 0;
u32 evid = 0;
u32 sval = 0;
@ -257,12 +260,14 @@ s2r_replay(HWND hwnd, HINSTANCE hinst, LPSTR filename, int nCmdShow)
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

@ -18,11 +18,11 @@
//#define S2R_ENABLE
// s2r dumping
int s2r_open(u32 ticks, char *filename);
int s2r_open(u32 ticks, char* filename);
void s2r_readreg(u32 ticks, u32 addr);
void s2r_writereg(u32 ticks, u32 addr, s16 value);
void s2r_writedma4(u32 ticks, u16 *data, u32 len);
void s2r_writedma7(u32 ticks, u16 *data, u32 len);
void s2r_writedma4(u32 ticks, u16* data, u32 len);
void s2r_writedma7(u32 ticks, u16* data, u32 len);
void s2r_close();
extern bool replay_mode;

View File

@ -26,8 +26,8 @@
#include "spu2.h" // needed until I figure out a nice solution for irqcallback dependencies.
s16 *spu2regs = NULL;
s16 *_spu2mem = NULL;
s16* spu2regs = NULL;
s16* _spu2mem = NULL;
V_CoreDebug DebugCores[2];
V_Core Cores[2];
@ -53,7 +53,7 @@ void SetIrqCall(int core)
has_to_call_irq = true;
}
__forceinline s16 *GetMemPtr(u32 addr)
__forceinline s16* GetMemPtr(u32 addr)
{
#ifndef DEBUG_FAST
// In case you're wondering, this assert is the reason SPU2-X
@ -76,7 +76,8 @@ __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;
@ -156,7 +157,8 @@ 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;
}
@ -183,7 +185,8 @@ void V_Core::Init(int index)
IRQA = 0x800;
IRQEnable = false; // 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;
@ -325,7 +328,8 @@ 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;
@ -335,8 +339,10 @@ 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;
}
@ -355,7 +361,8 @@ bool V_Voice::Start()
PV3 = PV4 = 0;
NextCrest = -0x8000;
return true;
} else
}
else
return false;
}
@ -384,7 +391,8 @@ __forceinline void TimeUpdate(u32 cClocks)
// 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 (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;
@ -402,42 +410,52 @@ __forceinline void TimeUpdate(u32 cClocks)
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(!SPU2_dummy_callback)
if (!SPU2_dummy_callback)
spu2Irq();
}
//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(!SPU2_dummy_callback)
if (!SPU2_dummy_callback)
spu2DMA4Irq();
else
SPU2interruptDMA4();
} else {
}
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(!SPU2_dummy_callback)
if (!SPU2_dummy_callback)
spu2DMA7Irq();
else
SPU2interruptDMA7();
} else {
}
else
{
Cores[1].MADR += TickInterval << 1;
}
}
@ -471,17 +489,22 @@ __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);
}
@ -517,15 +540,17 @@ 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)
{
V_VolumeSlide &thisvol = vval == 0 ? Voices[voice].Volume.Left : Voices[voice].Volume.Right;
V_VolumeSlide& thisvol = vval == 0 ? Voices[voice].Volume.Left : Voices[voice].Volume.Right;
thisvol.Reg_VOL = value;
if (value & 0x8000) // +Lin/-Lin/+Exp/-Exp
@ -535,7 +560,9 @@ void V_Core::WriteRegPS1(u32 mem, u16 value)
// 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 {
}
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:
@ -582,7 +609,8 @@ void V_Core::WriteRegPS1(u32 mem, u16 value)
}
else
switch (reg) {
switch (reg)
{
case 0x1d80: // Mainvolume left
MasterVol.Left.Mode = 0;
MasterVol.Left.RegSet(value);
@ -680,7 +708,8 @@ 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);
@ -694,9 +723,10 @@ 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);
if(!SPU2_dummy_callback)
if (!SPU2_dummy_callback)
spu2Irq();
}
DmaWrite(value);
@ -848,11 +878,13 @@ 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;
@ -890,8 +922,10 @@ u16 V_Core::ReadRegPS1(u32 mem)
jNO_DEFAULT;
}
} else
switch (reg) {
}
else
switch (reg)
{
case 0x1d80:
value = MasterVol.Left.Value >> 16;
break;
@ -980,24 +1014,24 @@ u16 V_Core::ReadRegPS1(u32 mem)
}
// Ah the joys of endian-specific code! :D
static __forceinline void SetHiWord(u32 &src, u16 value)
static __forceinline void SetHiWord(u32& src, u16 value)
{
((u16 *)&src)[1] = value;
((u16*)&src)[1] = value;
}
static __forceinline void SetLoWord(u32 &src, u16 value)
static __forceinline void SetLoWord(u32& src, u16 value)
{
((u16 *)&src)[0] = value;
((u16*)&src)[0] = value;
}
static __forceinline u16 GetHiWord(u32 &src)
static __forceinline u16 GetHiWord(u32& src)
{
return ((u16 *)&src)[1];
return ((u16*)&src)[1];
}
static __forceinline u16 GetLoWord(u32 &src)
static __forceinline u16 GetLoWord(u32& src)
{
return ((u16 *)&src)[0];
return ((u16*)&src)[0];
}
template <int CoreIdx, int VoiceIdx, int param>
@ -1006,13 +1040,14 @@ static void __fastcall RegWrite_VoiceParams(u16 value)
const int core = CoreIdx;
const int voice = VoiceIdx;
V_Voice &thisvoice = Cores[core].Voices[voice];
V_Voice& thisvoice = Cores[core].Voices[voice];
switch (param) {
switch (param)
{
case 0: //VOLL (Volume L)
case 1: //VOLR (Volume R)
{
V_VolumeSlide &thisvol = (param == 0) ? thisvoice.Volume.Left : thisvoice.Volume.Right;
V_VolumeSlide& thisvol = (param == 0) ? thisvoice.Volume.Left : thisvoice.Volume.Right;
thisvol.Reg_VOL = value;
if (value & 0x8000) // +Lin/-Lin/+Exp/-Exp
@ -1022,7 +1057,9 @@ static void __fastcall RegWrite_VoiceParams(u16 value)
// 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 {
}
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:
@ -1031,7 +1068,8 @@ static void __fastcall RegWrite_VoiceParams(u16 value)
thisvol.Mode = 0;
thisvol.Increment = 0;
}
} break;
}
break;
case 2:
if (value > 0x3fff)
@ -1074,9 +1112,10 @@ static void __fastcall RegWrite_VoiceAddr(u16 value)
const int core = CoreIdx;
const int voice = VoiceIdx;
V_Voice &thisvoice = Cores[core].Voices[voice];
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)
@ -1125,9 +1164,10 @@ static void __fastcall RegWrite_Core(u16 value)
{
const int omem = cAddr;
const int core = CoreIdx;
V_Core &thiscore = Cores[core];
V_Core& thiscore = Cores[core];
switch (omem) {
switch (omem)
{
case REG__1AC:
// ----------------------------------------------------------------------------
// 0x1ac / 0x5ac : direct-write to DMA address : special register (undocumented)
@ -1141,15 +1181,18 @@ 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;
@ -1169,36 +1212,41 @@ 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 (value & 0x000E)
{
if (MsgToConsole())
ConLog("* SPU2-X: Core %d ATTR unknown bits SET! value=%04x\n", core, value);
}
if (thiscore.AttrBit0 != bit0) {
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);
if (!thiscore.IRQEnable)
Spdif.Info &= ~(4 << thiscore.Index);
}
} break;
}
break;
case REG_S_PMON:
for (int vc = 1; vc < 16; ++vc)
@ -1274,7 +1322,8 @@ 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. :)
@ -1292,7 +1341,8 @@ 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);
@ -1336,7 +1386,8 @@ 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;
@ -1345,7 +1396,8 @@ 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;
@ -1354,7 +1406,8 @@ 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;
@ -1369,7 +1422,8 @@ static void __fastcall RegWrite_Core(u16 value)
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) {
if (value == 32767)
{
psxmode = true;
//memset(_spu2mem, 0, 0x200000);
Cores[1].FxEnable = 0;
@ -1381,7 +1435,8 @@ 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;
@ -1397,37 +1452,44 @@ 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;
}
}
template <int CoreIdx, int addr>
static void __fastcall RegWrite_CoreExt(u16 value)
{
V_Core &thiscore = Cores[CoreIdx];
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: {
V_VolumeSlide &thisvol = (addr == REG_P_MVOLL) ? thiscore.MasterVol.Left : thiscore.MasterVol.Right;
case REG_P_MVOLR:
{
V_VolumeSlide& thisvol = (addr == REG_P_MVOLL) ? thiscore.MasterVol.Left : thiscore.MasterVol.Right;
if (value & 0x8000) // +Lin/-Lin/+Exp/-Exp
{
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:
@ -1437,7 +1499,8 @@ 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);
@ -1470,10 +1533,12 @@ static void __fastcall RegWrite_CoreExt(u16 value)
case REG_P_MVOLXR:
break;
default: {
default:
{
const int raddr = addr + ((core == 1) ? 0x28 : 0);
*(regtable[raddr >> 1]) = value;
} break;
}
break;
}
}
@ -1546,7 +1611,7 @@ static void __fastcall RegWrite_Null(u16 value)
// --------------------------------------------------------------------------------------
typedef void __fastcall RegWriteHandler(u16 value);
static RegWriteHandler *const tbl_reg_writes[0x401] =
static RegWriteHandler* const tbl_reg_writes[0x401] =
{
VoiceParamsCore(0), // 0x000 -> 0x180
CoreParamsPair(0, REG_S_PMON),
@ -1795,21 +1860,23 @@ void StartVoices(int core, u32 value)
Cores[core].KeyOn |= value;
for (u8 vc = 0; vc < V_Core::NumVoices; vc++) {
for (u8 vc = 0; vc < V_Core::NumVoices; vc++)
{
if (!((value >> vc) & 1))
continue;
Cores[core].Voices[vc].QueueStart();
if (IsDevBuild) {
V_Voice &thisvc(Cores[core].Voices[vc]);
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",
core, vc, thisvc.StartA,
(Cores[core].VoiceGates[vc].DryL) ? "+" : "-", (Cores[core].VoiceGates[vc].DryR) ? "+" : "-",
(Cores[core].VoiceGates[vc].WetL) ? "+" : "-", (Cores[core].VoiceGates[vc].WetR) ? "+" : "-",
*(u16 *)GetMemPtr(thisvc.StartA),
*(u16*)GetMemPtr(thisvc.StartA),
thisvc.Pitch,
thisvc.Volume.Left.Value >> 16, thisvc.Volume.Right.Value >> 16,
thisvc.ADSR.regADSR1, thisvc.ADSR.regADSR2);
@ -1821,7 +1888,8 @@ void StopVoices(int core, u32 value)
{
if (value == 0)
return;
for (u8 vc = 0; vc < V_Core::NumVoices; vc++) {
for (u8 vc = 0; vc < V_Core::NumVoices; vc++)
{
if (!((value >> vc) & 1))
continue;

View File

@ -116,10 +116,10 @@ SyncTab::SyncTab(wxWindow* parent)
auto* adv_box = new wxStaticBoxSizer(wxVERTICAL, this, "Advanced");
auto* babble_label = new wxStaticText(this, wxID_ANY, \
"For fine-tuning time stretching.\n"\
"Larger is better for slowdown, && smaller for speedup (60+ fps).\n"\
"All options in microseconds.",\
auto* babble_label = new wxStaticText(this, wxID_ANY,
"For fine-tuning time stretching.\n"
"Larger is better for slowdown, && smaller for speedup (60+ fps).\n"
"All options in microseconds.",
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
babble_label->Wrap(300);