X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fdfsound%2Ffreeze.c;h=0601bf5c0c0353c491b83e5d6b91948512603f77;hp=12fdc1fdba2a663e91fd1b61c57a633365b8ef3a;hb=6f6fe96900374d8744473ce240279e66d1260191;hpb=ef79bbde537d6b9c745a7d86cb9df1d04c35590d diff --git a/plugins/dfsound/freeze.c b/plugins/dfsound/freeze.c index 12fdc1fd..0601bf5c 100644 --- a/plugins/dfsound/freeze.c +++ b/plugins/dfsound/freeze.c @@ -22,12 +22,90 @@ #include "externals.h" #include "registers.h" #include "spu.h" -#include "regs.h" //////////////////////////////////////////////////////////////////////// // freeze structs //////////////////////////////////////////////////////////////////////// +typedef struct +{ + int AttackModeExp; + int AttackTime; + int DecayTime; + int SustainLevel; + int SustainModeExp; + int SustainModeDec; + int SustainTime; + int ReleaseModeExp; + unsigned int ReleaseVal; + int ReleaseTime; + int ReleaseStartTime; + int ReleaseVol; + int lTime; + int lVolume; +} ADSRInfo; + +typedef struct +{ + int State; + int AttackModeExp; + int AttackRate; + int DecayRate; + int SustainLevel; + int SustainModeExp; + int SustainIncrease; + int SustainRate; + int ReleaseModeExp; + int ReleaseRate; + int EnvelopeVol; + int lVolume; + int lDummy1; + int lDummy2; +} ADSRInfoEx_orig; + +typedef struct +{ + // no mutexes used anymore... don't need them to sync access + //HANDLE hMutex; + + int bNew; // start flag + + int iSBPos; // mixing stuff + int spos; + int sinc; + int SB[32+32]; // Pete added another 32 dwords in 1.6 ... prevents overflow issues with gaussian/cubic interpolation (thanx xodnizel!), and can be used for even better interpolations, eh? :) + int sval; + + int iStart; // start ptr into sound mem + int iCurr; // current pos in sound mem + int iLoop; // loop ptr in sound mem + + int bOn; // is channel active (sample playing?) + int bStop; // is channel stopped (sample _can_ still be playing, ADSR Release phase) + int bReverb; // can we do reverb on this channel? must have ctrl register bit, to get active + int iActFreq; // current psx pitch + int iUsedFreq; // current pc pitch + int iLeftVolume; // left volume + int iLeftVolRaw; // left psx volume value + int bIgnoreLoop; // ignore loop bit, if an external loop address is used + int iMute; // mute mode + int iRightVolume; // right volume + int iRightVolRaw; // right psx volume value + int iRawPitch; // raw pitch (0...3fff) + int iIrqDone; // debug irq done flag + int s_1; // last decoding infos + int s_2; + int bRVBActive; // reverb active flag + int iRVBOffset; // reverb offset + int iRVBRepeat; // reverb repeat + int bNoise; // noise active flag + int bFMod; // freq mod (0=off, 1=sound channel, 2=freq channel) + int iRVBNum; // another reverb helper + int iOldNoise; // old noise val for this channel + ADSRInfo ADSR; // active ADSR settings + ADSRInfoEx_orig ADSRX; // next ADSR settings (will be moved to active on sample start) +} SPUCHAN_orig; + typedef struct { char szSPUName[8]; @@ -47,7 +125,7 @@ typedef struct uint32_t dummy2; uint32_t dummy3; - SPUCHAN s_chan[MAXCHAN]; + SPUCHAN_orig s_chan[MAXCHAN]; } SPUOSSFreeze_t; @@ -58,6 +136,82 @@ void LoadStateUnknown(SPUFreeze_t * pF); // unknown format extern int lastch; +// we want to retain compatibility between versions, +// so use original channel struct +static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch) +{ + memset(d, 0, sizeof(*d)); + d->bNew = !!(dwNewChannel & (1<iSBPos = s->iSBPos; + d->spos = s->spos; + d->sinc = s->sinc; + memcpy(d->SB, s->SB, sizeof(d->SB)); + d->iStart = (regAreaGet(ch,6)&~1)<<3; + d->iCurr = 0; // set by the caller + d->iLoop = 0; // set by the caller + d->bOn = !!(dwChannelOn & (1<bStop = s->bStop; + d->bReverb = s->bReverb; + d->iActFreq = 1; + d->iUsedFreq = 2; + d->iLeftVolume = s->iLeftVolume; + // this one is nasty but safe, save compat is important + d->bIgnoreLoop = (s->prevflags ^ 2) << 1; + d->iRightVolume = s->iRightVolume; + d->iRawPitch = s->iRawPitch; + d->s_1 = s->SB[27]; // yes it's reversed + d->s_2 = s->SB[26]; + d->bRVBActive = s->bRVBActive; + d->bNoise = s->bNoise; + d->bFMod = s->bFMod; + d->ADSRX.State = s->ADSRX.State; + d->ADSRX.AttackModeExp = s->ADSRX.AttackModeExp; + d->ADSRX.AttackRate = s->ADSRX.AttackRate; + d->ADSRX.DecayRate = s->ADSRX.DecayRate; + d->ADSRX.SustainLevel = s->ADSRX.SustainLevel; + d->ADSRX.SustainModeExp = s->ADSRX.SustainModeExp; + d->ADSRX.SustainIncrease = s->ADSRX.SustainIncrease; + d->ADSRX.SustainRate = s->ADSRX.SustainRate; + d->ADSRX.ReleaseModeExp = s->ADSRX.ReleaseModeExp; + d->ADSRX.ReleaseRate = s->ADSRX.ReleaseRate; + d->ADSRX.EnvelopeVol = s->ADSRX.EnvelopeVol; + d->ADSRX.lVolume = d->bOn; // hmh +} + +static void load_channel(SPUCHAN *d, const SPUCHAN_orig *s, int ch) +{ + memset(d, 0, sizeof(*d)); + if (s->bNew) dwNewChannel |= 1<iSBPos = s->iSBPos; + d->spos = s->spos; + d->sinc = s->sinc; + memcpy(d->SB, s->SB, sizeof(d->SB)); + d->pCurr = (void *)((long)s->iCurr & 0x7fff0); + d->pLoop = (void *)((long)s->iLoop & 0x7fff0); + d->bStop = s->bStop; + d->bReverb = s->bReverb; + d->iLeftVolume = s->iLeftVolume; + d->iRightVolume = s->iRightVolume; + d->iRawPitch = s->iRawPitch; + d->bRVBActive = s->bRVBActive; + d->bNoise = s->bNoise; + d->bFMod = s->bFMod; + d->prevflags = (s->bIgnoreLoop >> 1) ^ 2; + d->ADSRX.State = s->ADSRX.State; + d->ADSRX.AttackModeExp = s->ADSRX.AttackModeExp; + d->ADSRX.AttackRate = s->ADSRX.AttackRate; + d->ADSRX.DecayRate = s->ADSRX.DecayRate; + d->ADSRX.SustainLevel = s->ADSRX.SustainLevel; + d->ADSRX.SustainModeExp = s->ADSRX.SustainModeExp; + d->ADSRX.SustainIncrease = s->ADSRX.SustainIncrease; + d->ADSRX.SustainRate = s->ADSRX.SustainRate; + d->ADSRX.ReleaseModeExp = s->ADSRX.ReleaseModeExp; + d->ADSRX.ReleaseRate = s->ADSRX.ReleaseRate; + d->ADSRX.EnvelopeVol = s->ADSRX.EnvelopeVol; + if (s->bOn) dwChannelOn |= 1<ADSRX.EnvelopeVol = 0; +} + //////////////////////////////////////////////////////////////////////// // SPUFREEZE: called by main emu on savestate load/save //////////////////////////////////////////////////////////////////////// @@ -79,8 +233,6 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF) if(ulFreezeMode==2) return 1; // info mode? ok, bye // save mode: - RemoveTimer(); // stop timer - memcpy(pF->cSPURam,spuMem,0x80000); // copy common infos memcpy(pF->cSPUPort,regArea,0x200); @@ -101,25 +253,19 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF) for(i=0;is_chan[i],(void *)&s_chan[i],sizeof(SPUCHAN)); - if(pFO->s_chan[i].pStart) - pFO->s_chan[i].pStart-=(unsigned long)spuMemC; - if(pFO->s_chan[i].pCurr) - pFO->s_chan[i].pCurr-=(unsigned long)spuMemC; - if(pFO->s_chan[i].pLoop) - pFO->s_chan[i].pLoop-=(unsigned long)spuMemC; + save_channel(&pFO->s_chan[i],&s_chan[i],i); + if(s_chan[i].pCurr) + pFO->s_chan[i].iCurr=s_chan[i].pCurr-spuMemC; + if(s_chan[i].pLoop) + pFO->s_chan[i].iLoop=s_chan[i].pLoop-spuMemC; } - SetupTimer(); // sound processing on again - return 1; //--------------------------------------------------// } if(ulFreezeMode!=0) return 0; // bad mode? bye - RemoveTimer(); // we stop processing while doing the save! - memcpy(spuMem,pF->cSPURam,0x80000); // get ram memcpy(regArea,pF->cSPUPort,0x200); @@ -149,7 +295,7 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF) // fix to prevent new interpolations from crashing for(i=0;ispuIrq; - if(pFO->pSpuIrq) pSpuIrq = pFO->pSpuIrq+spuMemC; else pSpuIrq=NULL; + if(pFO->pSpuIrq) pSpuIrq = spuMemC+((long)pFO->pSpuIrq&0x7fff0); else pSpuIrq=NULL; if(pFO->spuAddr) { @@ -171,15 +317,15 @@ void LoadStateV5(SPUFreeze_t * pF) if (spuAddr == 0xbaadf00d) spuAddr = 0; } + dwNewChannel=0; + dwChannelOn=0; + dwChannelDead=0; for(i=0;is_chan[i],sizeof(SPUCHAN)); + load_channel(&s_chan[i],&pFO->s_chan[i],i); - s_chan[i].pStart+=(unsigned long)spuMemC; s_chan[i].pCurr+=(unsigned long)spuMemC; s_chan[i].pLoop+=(unsigned long)spuMemC; - s_chan[i].iMute=0; - s_chan[i].iIrqDone=0; } } @@ -191,18 +337,13 @@ void LoadStateUnknown(SPUFreeze_t * pF) for(i=0;i