A bit more work on SPU2Ghz. Removed old code, made timestretch code a bit more clear, etc.

git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@198 a6443dda-0b58-4228-96e9-037be469359c
This commit is contained in:
ramapcsx2 2008-10-14 10:47:02 +00:00 committed by Gregory Hainaut
parent 254411d304
commit 9e05d9146e
4 changed files with 24 additions and 74 deletions

View File

@ -228,8 +228,6 @@ void DoDMAWrite(int core,u16 *pMem,u32 size)
void SPU2readDMA(int core, u16* pMem, u32 size) void SPU2readDMA(int core, u16* pMem, u32 size)
{ {
ENTER_CS(&threadSync);
if(hasPtr) TimeUpdate(*cPtr,1); if(hasPtr) TimeUpdate(*cPtr,1);
u32 i; u32 i;
@ -252,13 +250,10 @@ void SPU2readDMA(int core, u16* pMem, u32 size)
//Cores[core].Regs.ATTR |= 0x30; //Cores[core].Regs.ATTR |= 0x30;
Cores[core].TADR=Cores[core].MADR+(size<<1); Cores[core].TADR=Cores[core].MADR+(size<<1);
LEAVE_CS(&threadSync);
} }
void SPU2writeDMA(int core, u16* pMem, u32 size) void SPU2writeDMA(int core, u16* pMem, u32 size)
{ {
ENTER_CS(&threadSync);
if(hasPtr) TimeUpdate(*cPtr,1); if(hasPtr) TimeUpdate(*cPtr,1);
Cores[core].DMAPtr=pMem; Cores[core].DMAPtr=pMem;
@ -269,7 +264,6 @@ void SPU2writeDMA(int core, u16* pMem, u32 size)
//Cores[core].Regs.ATTR |= 0x30; //Cores[core].Regs.ATTR |= 0x30;
Cores[core].DMAICounter=1; Cores[core].DMAICounter=1;
LEAVE_CS(&threadSync);
return; return;
} }
@ -289,8 +283,6 @@ void SPU2writeDMA(int core, u16* pMem, u32 size)
} }
Cores[core].Regs.STATX &= ~0x80; Cores[core].Regs.STATX &= ~0x80;
//Cores[core].Regs.ATTR |= 0x30; //Cores[core].Regs.ATTR |= 0x30;
LEAVE_CS(&threadSync);
} }
u32 CALLBACK SPU2ReadMemAddr(int core) u32 CALLBACK SPU2ReadMemAddr(int core)

View File

@ -312,6 +312,7 @@ void UpdateTempoChange()
s32 bufferUsage = sndBuffer->GetBufferUsage(); s32 bufferUsage = sndBuffer->GetBufferUsage();
s32 bufferSize = sndBuffer->GetBufferSize(); s32 bufferSize = sndBuffer->GetBufferSize();
//Emergency stretch to compensate for FPS fluctuations and keep the buffers happy
bool a=(bufferUsage < CurBufferSize * 4); bool a=(bufferUsage < CurBufferSize * 4);
bool b=(bufferUsage >= (bufferSize - CurBufferSize * 4)); bool b=(bufferUsage >= (bufferSize - CurBufferSize * 4));
@ -333,6 +334,7 @@ void UpdateTempoChange()
{ {
cTempo = cTempo * 0.9f + lastTempo * 0.1f; cTempo = cTempo * 0.9f + lastTempo * 0.1f;
} }
//////////////////////////////////////////////////////////////////////////////
sndBuffer->GetStats(cWritten,cRead,false); sndBuffer->GetStats(cWritten,cRead,false);
@ -343,6 +345,7 @@ void UpdateTempoChange()
oldRead = cRead; oldRead = cRead;
oldInput = cInput; oldInput = cInput;
//normal stretch, scales sound to game speed
if(numAccum >= numUpdates) if(numAccum >= numUpdates)
{ {
float valAccum = 1.0; float valAccum = 1.0;
@ -350,16 +353,17 @@ void UpdateTempoChange()
if (valAccum1 != 0) if (valAccum1 != 0)
valAccum=valAccum2 / valAccum1; valAccum=valAccum2 / valAccum1;
if((valAccum<1.05)&&(valAccum>0.95)&&(valAccum!=1)) if((valAccum < 1.05) && (valAccum > 0.95) /*&& (valAccum != 1)*/)
{ {
printf("Timestretch Debug > Playbackpeed: %f (difference disregarded, using 1.0).\n",valAccum); // printf("Timestretch Debug > Playbackpeed: %f (difference disregarded, using 1.0).\n",valAccum);
valAccum = 1; valAccum = 1;
} }
else /*else
{ {
printf("Timestretch Debug > Playbackpeed: %f\n",valAccum); printf("Timestretch Debug > Playbackpeed: %f\n",valAccum);
} }*/
if (valAccum != lastTempo) //only update soundtouch object when needed
pSoundTouch->setTempo(valAccum); pSoundTouch->setTempo(valAccum);
lastTempo = valAccum; lastTempo = valAccum;

View File

@ -43,7 +43,6 @@ static char *libraryName = "GiGaHeRz's SPU2 ("
DWORD CALLBACK TimeThread(PVOID /* unused param */); DWORD CALLBACK TimeThread(PVOID /* unused param */);
bool EnableThread=false;
const char *ParamNames[8]={"VOLL","VOLR","PITCH","ADSR1","ADSR2","ENVX","VOLXL","VOLXR"}; const char *ParamNames[8]={"VOLL","VOLR","PITCH","ADSR1","ADSR2","ENVX","VOLXL","VOLXR"};
const char *AddressNames[6]={"SSAH","SSAL","LSAH","LSAL","NAXH","NAXL"}; const char *AddressNames[6]={"SSAH","SSAL","LSAH","LSAL","NAXH","NAXL"};
@ -343,16 +342,6 @@ s32 CALLBACK SPU2open(void *pDsp) {
spu2open=1; spu2open=1;
if (!SndInit()) if (!SndInit())
{ {
if(EnableThread)
{
InitializeCriticalSection(&threadSync);
if ((hThreadFunc=CreateThread(NULL,0,&TimeThread,0,0,(LPDWORD)&ThreadFuncID))==NULL) {
SysMessage("CreateThread Failed.");
SPU2close(); return -1;
}
SetThreadPriority(hThreadFunc,THREAD_PRIORITY_TIME_CRITICAL);
}
srate_pv=(double)SampleRate/48000.0; srate_pv=(double)SampleRate/48000.0;
spdif_init(); spdif_init();
@ -377,15 +366,6 @@ void CALLBACK SPU2close()
spdif_shutdown(); spdif_shutdown();
if(EnableThread)
{
if(hasPtr) TimeUpdate(*cPtr,2);
printf("Waiting for spu2 thread to finish...\n");
WaitForSingleObject(hThreadFunc,INFINITE);
DeleteCriticalSection(&threadSync);
}
SndClose(); SndClose();
} }
@ -571,10 +551,8 @@ DWORD CALLBACK TimeThread(PVOID /* unused param */)
} }
else else
{ {
ENTER_CS(&threadSync);
Mix(); Mix();
TicksThread++; TicksThread++;
LEAVE_CS(&threadSync);
} }
} }
return 0; return 0;
@ -654,17 +632,10 @@ void CALLBACK TimeUpdate(u32 cClocks, u32 syncType)
lClocks+=TickInterval; lClocks+=TickInterval;
Cycles++; Cycles++;
if(EnableThread)
{
TicksCore++;
}
else
{
Mix(); Mix();
} }
} }
} }
}
bool numpad_minus_old=false; bool numpad_minus_old=false;
bool numpad_minus = false; bool numpad_minus = false;
@ -696,8 +667,6 @@ void CALLBACK SPU2async(u32 cycles)
numpad_minus_old = numpad_minus; numpad_minus_old = numpad_minus;
} }
ENTER_CS(&threadSync);
if(hasPtr) if(hasPtr)
{ {
TimeUpdate(*cPtr,0); TimeUpdate(*cPtr,0);
@ -707,8 +676,6 @@ void CALLBACK SPU2async(u32 cycles)
pClocks+=cycles; pClocks+=cycles;
TimeUpdate(pClocks,0); TimeUpdate(pClocks,0);
} }
LEAVE_CS(&threadSync);
} }
void CALLBACK SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)()) void CALLBACK SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)())
@ -1183,8 +1150,6 @@ void CALLBACK SPU2writeLog(u32 rmem, u16 value)
void CALLBACK SPU2write(u32 rmem, u16 value) void CALLBACK SPU2write(u32 rmem, u16 value)
{ {
ENTER_CS(&threadSync);
#ifdef S2R_ENABLE #ifdef S2R_ENABLE
if(!replay_mode) if(!replay_mode)
s2r_writereg(Cycles,rmem,value); s2r_writereg(Cycles,rmem,value);
@ -1201,7 +1166,6 @@ void CALLBACK SPU2write(u32 rmem, u16 value)
spu2Mu16(Cores[0].TSA++)=value; spu2Mu16(Cores[0].TSA++)=value;
Cores[0].TSA&=0xfffff; Cores[0].TSA&=0xfffff;
LEAVE_CS(&threadSync);
return; return;
} }
else if(rmem==0x1f9005ac) else if(rmem==0x1f9005ac)
@ -1215,7 +1179,6 @@ void CALLBACK SPU2write(u32 rmem, u16 value)
spu2Mu16(Cores[1].TSA++)=value; spu2Mu16(Cores[1].TSA++)=value;
Cores[1].TSA&=0xfffff; Cores[1].TSA&=0xfffff;
LEAVE_CS(&threadSync);
return; return;
} }
@ -1507,13 +1470,10 @@ void CALLBACK SPU2write(u32 rmem, u16 value)
{ {
UpdateSpdifMode(); UpdateSpdifMode();
} }
LEAVE_CS(&threadSync);
} }
u16 CALLBACK SPU2read(u32 rmem) u16 CALLBACK SPU2read(u32 rmem)
{ {
ENTER_CS(&threadSync);
// if(!replay_mode) // if(!replay_mode)
// s2r_readreg(Cycles,rmem); // s2r_readreg(Cycles,rmem);
@ -1544,8 +1504,6 @@ u16 CALLBACK SPU2read(u32 rmem)
FileLog("[%10d] SPU2 read mem %x (core %d, register %x): %x\n",Cycles, mem, core, (omem & 0x7ff), ret); FileLog("[%10d] SPU2 read mem %x (core %d, register %x): %x\n",Cycles, mem, core, (omem & 0x7ff), ret);
} }
LEAVE_CS(&threadSync);
return ret; return ret;
} }

View File

@ -101,13 +101,9 @@ extern CRITICAL_SECTION threadSync;
extern u32 lClocks; extern u32 lClocks;
extern bool EnableThread;
#define ENTER_CS(cs) do { if(EnableThread) EnterCriticalSection(cs); } while(0)
#define LEAVE_CS(cs) do { if(EnableThread) LeaveCriticalSection(cs); } while(0)
extern u32* cPtr; extern u32* cPtr;
extern bool hasPtr; extern bool hasPtr;
void CALLBACK TimeUpdate(u32 cClocks, u32 syncType); void CALLBACK TimeUpdate(u32 cClocks, u32 syncType);
void TimestretchUpdate(int bufferusage,int buffersize); void TimestretchUpdate(int bufferusage,int buffersize);