X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fdfsound%2Fregisters.c;h=b9c1256a11d1a6ff8f6e6fc356026eee68769b2b;hp=ac495d63e71856cb102c55264cb3e73f6151f26d;hb=92ca1ba64e939942ab05aaa3d578f0d165634275;hpb=3fc2a4c27be8c8cd5f8cf53a0d56c263275b8501 diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c index ac495d63..b9c1256a 100644 --- a/plugins/dfsound/registers.c +++ b/plugins/dfsound/registers.c @@ -21,26 +21,15 @@ #include "externals.h" #include "registers.h" -#include "regs.h" -#include "reverb.h" -/* -// adsr time values (in ms) by James Higgs ... see the end of -// the adsr.c source for details - -#define ATTACK_MS 514L -#define DECAYHALF_MS 292L -#define DECAY_MS 584L -#define SUSTAIN_MS 450L -#define RELEASE_MS 446L -*/ - -// we have a timebase of 1.020408f ms, not 1 ms... so adjust adsr defines -#define ATTACK_MS 494L -#define DECAYHALF_MS 286L -#define DECAY_MS 572L -#define SUSTAIN_MS 441L -#define RELEASE_MS 437L +static void SoundOn(int start,int end,unsigned short val); +static void SoundOff(int start,int end,unsigned short val); +static void FModOn(int start,int end,unsigned short val); +static void NoiseOn(int start,int end,unsigned short val); +static void SetVolumeL(unsigned char ch,short vol); +static void SetVolumeR(unsigned char ch,short vol); +static void SetPitch(int ch,unsigned short val); +static void ReverbOn(int start,int end,unsigned short val); //////////////////////////////////////////////////////////////////////// // WRITE REGISTERS: called by main emu @@ -70,8 +59,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) break; //------------------------------------------------// start case 6: - // Brain Dead 13 - align to 16 boundary - s_chan[ch].pStart= spuMemC+(unsigned long)((val<<3)&~0xf); + // taken from regArea later break; //------------------------------------------------// level with pre-calcs case 8: @@ -83,35 +71,6 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f; s_chan[ch].ADSRX.SustainLevel=lval & 0x000f; //---------------------------------------------// -#if 0 - if(!iDebugMode) break; - //---------------------------------------------// stuff below is only for debug mode - - s_chan[ch].ADSR.AttackModeExp=(lval&0x8000)?1:0; //0x007f - - lx=(((lval>>8) & 0x007f)>>2); // attack time to run from 0 to 100% volume - lx=min(31,lx); // no overflow on shift! - if(lx) - { - lx = (1<>4) & 0x000f; // decay: - if(lx) // our const decay value is time it takes from 100% to 0% of volume - { - lx = ((1<<(lx))*DECAY_MS)/10000L; - if(!lx) lx=1; - } - s_chan[ch].ADSR.DecayTime = // so calc how long does it take to run from 100% to the wanted sus level - (lx*(1024-s_chan[ch].ADSR.SustainLevel))/1024; -#endif } break; //------------------------------------------------// adsr times with pre-calcs @@ -126,39 +85,6 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0; s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f; //----------------------------------------------// -#if 0 - if(!iDebugMode) break; - //----------------------------------------------// stuff below is only for debug mode - - s_chan[ch].ADSR.SustainModeExp = (lval&0x8000)?1:0; - s_chan[ch].ADSR.ReleaseModeExp = (lval&0x0020)?1:0; - - lx=((((lval>>6) & 0x007f)>>2)); // sustain time... often very high - lx=min(31,lx); // values are used to hold the volume - if(lx) // until a sound stop occurs - { // the highest value we reach (due to - lx = (1< no multithread fuckups - s_chan[ch].pLoop=spuMemC+((unsigned long)((val<<3)&~0xf)); - //s_chan[ch].bIgnoreLoop=1; - //ReleaseMutex(s_chan[ch].hMutex); // -> oki, on with the thread + s_chan[ch].pLoop=spuMemC+((val&~1)<<3); break; //------------------------------------------------// } - iSpuAsyncWait=0; return; } @@ -210,8 +132,12 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) { rvb.StartAddr=(unsigned long)val<<2; rvb.CurrAddr=rvb.StartAddr; + // sync-with-decode-buffers hack.. + if(rvb.StartAddr==0x3ff00) + rvb.CurrAddr+=decode_pos/2; } } + rvb.dirty = 1; break; //-------------------------------------------------// case H_SPUirqAddr: @@ -303,19 +229,8 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) ReverbOn(16,24,val); break; //-------------------------------------------------// - case H_Reverb+0: - - rvb.FB_SRC_A=val; - - // OK, here's the fake REVERB stuff... - // depending on effect we do more or less delay and repeats... bah - // still... better than nothing :) - - SetREVERB(val); - break; - - - case H_Reverb+2 : rvb.FB_SRC_B=(short)val; break; + case H_Reverb+0 : rvb.FB_SRC_A=val*4; break; + case H_Reverb+2 : rvb.FB_SRC_B=val*4; break; case H_Reverb+4 : rvb.IIR_ALPHA=(short)val; break; case H_Reverb+6 : rvb.ACC_COEF_A=(short)val; break; case H_Reverb+8 : rvb.ACC_COEF_B=(short)val; break; @@ -324,31 +239,32 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val) case H_Reverb+14 : rvb.IIR_COEF=(short)val; break; case H_Reverb+16 : rvb.FB_ALPHA=(short)val; break; case H_Reverb+18 : rvb.FB_X=(short)val; break; - case H_Reverb+20 : rvb.IIR_DEST_A0=(short)val; break; - case H_Reverb+22 : rvb.IIR_DEST_A1=(short)val; break; - case H_Reverb+24 : rvb.ACC_SRC_A0=(short)val; break; - case H_Reverb+26 : rvb.ACC_SRC_A1=(short)val; break; - case H_Reverb+28 : rvb.ACC_SRC_B0=(short)val; break; - case H_Reverb+30 : rvb.ACC_SRC_B1=(short)val; break; - case H_Reverb+32 : rvb.IIR_SRC_A0=(short)val; break; - case H_Reverb+34 : rvb.IIR_SRC_A1=(short)val; break; - case H_Reverb+36 : rvb.IIR_DEST_B0=(short)val; break; - case H_Reverb+38 : rvb.IIR_DEST_B1=(short)val; break; - case H_Reverb+40 : rvb.ACC_SRC_C0=(short)val; break; - case H_Reverb+42 : rvb.ACC_SRC_C1=(short)val; break; - case H_Reverb+44 : rvb.ACC_SRC_D0=(short)val; break; - case H_Reverb+46 : rvb.ACC_SRC_D1=(short)val; break; - case H_Reverb+48 : rvb.IIR_SRC_B1=(short)val; break; - case H_Reverb+50 : rvb.IIR_SRC_B0=(short)val; break; - case H_Reverb+52 : rvb.MIX_DEST_A0=(short)val; break; - case H_Reverb+54 : rvb.MIX_DEST_A1=(short)val; break; - case H_Reverb+56 : rvb.MIX_DEST_B0=(short)val; break; - case H_Reverb+58 : rvb.MIX_DEST_B1=(short)val; break; + case H_Reverb+20 : rvb.IIR_DEST_A0=val*4; break; + case H_Reverb+22 : rvb.IIR_DEST_A1=val*4; break; + case H_Reverb+24 : rvb.ACC_SRC_A0=val*4; break; + case H_Reverb+26 : rvb.ACC_SRC_A1=val*4; break; + case H_Reverb+28 : rvb.ACC_SRC_B0=val*4; break; + case H_Reverb+30 : rvb.ACC_SRC_B1=val*4; break; + case H_Reverb+32 : rvb.IIR_SRC_A0=val*4; break; + case H_Reverb+34 : rvb.IIR_SRC_A1=val*4; break; + case H_Reverb+36 : rvb.IIR_DEST_B0=val*4; break; + case H_Reverb+38 : rvb.IIR_DEST_B1=val*4; break; + case H_Reverb+40 : rvb.ACC_SRC_C0=val*4; break; + case H_Reverb+42 : rvb.ACC_SRC_C1=val*4; break; + case H_Reverb+44 : rvb.ACC_SRC_D0=val*4; break; + case H_Reverb+46 : rvb.ACC_SRC_D1=val*4; break; + case H_Reverb+48 : rvb.IIR_SRC_B1=val*4; break; + case H_Reverb+50 : rvb.IIR_SRC_B0=val*4; break; + case H_Reverb+52 : rvb.MIX_DEST_A0=val*4; break; + case H_Reverb+54 : rvb.MIX_DEST_A1=val*4; break; + case H_Reverb+56 : rvb.MIX_DEST_B0=val*4; break; + case H_Reverb+58 : rvb.MIX_DEST_B1=val*4; break; case H_Reverb+60 : rvb.IN_COEF_L=(short)val; break; case H_Reverb+62 : rvb.IN_COEF_R=(short)val; break; } - iSpuAsyncWait=0; + if ((r & ~0x3f) == H_Reverb) + rvb.dirty = 1; // recalculate on next update } //////////////////////////////////////////////////////////////////////// @@ -359,8 +275,6 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) { const unsigned long r=reg&0xfff; - iSpuAsyncWait=0; - if(r>=0x0c00 && r<0x0d80) { switch(r&0x0f) @@ -420,23 +334,24 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) // SOUND ON register write //////////////////////////////////////////////////////////////////////// -void SoundOn(int start,int end,unsigned short val) // SOUND ON PSX COMAND +static void SoundOn(int start,int end,unsigned short val) { int ch; for(ch=start;ch>=1) // loop channels { - if((val&1) && s_chan[ch].pStart) // mmm... start has to be set before key on !?! + if((val&1) && regAreaGet(ch,6)) // mmm... start has to be set before key on !?! { - s_chan[ch].bIgnoreLoop=0; - // do this here, not in StartSound // - fixes fussy timing issues s_chan[ch].bStop=0; - s_chan[ch].pCurr=s_chan[ch].pStart; + s_chan[ch].pCurr=spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned + s_chan[ch].pLoop=spuMemC+((regAreaGet(ch,14)&~1)<<3); + s_chan[ch].prevflags=2; dwNewChannel|=(1<>=1) // loop channels @@ -465,7 +380,7 @@ void SoundOff(int start,int end,unsigned short val) // SOUND OFF PSX COMMAND // FMOD register write //////////////////////////////////////////////////////////////////////// -void FModOn(int start,int end,unsigned short val) // FMOD ON PSX COMMAND +static void FModOn(int start,int end,unsigned short val) { int ch; @@ -482,6 +397,8 @@ void FModOn(int start,int end,unsigned short val) // FMOD ON PSX COMMAND else { s_chan[ch].bFMod=0; // --> turn off fmod + if(ch>0&&s_chan[ch-1].bFMod==2) + s_chan[ch-1].bFMod=0; } } } @@ -490,7 +407,7 @@ void FModOn(int start,int end,unsigned short val) // FMOD ON PSX COMMAND // NOISE register write //////////////////////////////////////////////////////////////////////// -void NoiseOn(int start,int end,unsigned short val) // NOISE ON PSX COMMAND +static void NoiseOn(int start,int end,unsigned short val) { int ch; @@ -507,7 +424,7 @@ void NoiseOn(int start,int end,unsigned short val) // NOISE ON PSX COMMAND // please note: sweep and phase invert are wrong... but I've never seen // them used -void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME +static void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME { if(vol&0x8000) // sweep? { @@ -533,7 +450,7 @@ void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME // RIGHT VOLUME register write //////////////////////////////////////////////////////////////////////// -void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME +static void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME { if(vol&0x8000) // comments... see above :) { @@ -559,24 +476,22 @@ void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME // PITCH register write //////////////////////////////////////////////////////////////////////// -void SetPitch(int ch,unsigned short val) // SET PITCH +static void SetPitch(int ch,unsigned short val) // SET PITCH { int NP; if(val>0x3fff) NP=0x3fff; // get pitch val else NP=val; s_chan[ch].iRawPitch=NP; - - NP=(44100L*NP)/4096L; // calc frequency - if(NP<1) NP=1; // some security - s_chan[ch].iActFreq=NP; // store frequency + s_chan[ch].sinc=(NP<<4)|8; + if(iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simple interpolation mode: set flag } //////////////////////////////////////////////////////////////////////// // REVERB register write //////////////////////////////////////////////////////////////////////// -void ReverbOn(int start,int end,unsigned short val) // REVERB ON PSX COMMAND +static void ReverbOn(int start,int end,unsigned short val) { int ch;