From d97cde6583ad7a30fa31c7086bafeacd8fc9dcfc Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Wed, 18 Feb 2009 14:20:06 +0000 Subject: [PATCH] SPU2-X: Some bugfixes to reverb that were introduced in my last commit. Still some minor problems in this build. I'll fix them soon. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@527 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/spu2-x/src/BaseTypes.h | 7 +- plugins/spu2-x/src/Reverb.cpp | 47 +++---- plugins/spu2-x/src/Spu2.cpp | 144 +++++++++++---------- plugins/spu2-x/src/Win32/SndOut_DSound.cpp | 4 +- 4 files changed, 107 insertions(+), 95 deletions(-) diff --git a/plugins/spu2-x/src/BaseTypes.h b/plugins/spu2-x/src/BaseTypes.h index 25f3e40dd2..99a7ffc8cc 100644 --- a/plugins/spu2-x/src/BaseTypes.h +++ b/plugins/spu2-x/src/BaseTypes.h @@ -113,13 +113,18 @@ struct StereoOut32 StereoOut16 DownSample() const; - StereoOut32 operator+( const StereoOut32& right ) + StereoOut32 operator+( const StereoOut32& right ) const { return StereoOut32( Left + right.Left, Right + right.Right ); } + + StereoOut32 operator/( int src ) const + { + return StereoOut32( Left / src, Right / src ); + } }; #endif diff --git a/plugins/spu2-x/src/Reverb.cpp b/plugins/spu2-x/src/Reverb.cpp index 8520830356..124dfed56d 100644 --- a/plugins/spu2-x/src/Reverb.cpp +++ b/plugins/spu2-x/src/Reverb.cpp @@ -50,7 +50,11 @@ void Reverb_AdvanceBuffer( V_Core& thiscore ) { if( (Cycles & 1) && (thiscore.EffectsBufferSize > 0) ) { - thiscore.ReverbX = RevbGetIndexer( thiscore, 1 ); + //thiscore.ReverbX = RevbGetIndexer( thiscore, 1 ); + thiscore.ReverbX += 1; + + if( thiscore.ReverbX >= thiscore.EffectsBufferSize ) thiscore.ReverbX = 0; + //thiscore.ReverbX += 1; //if(thiscore.ReverbX >= (u32)thiscore.EffectsBufferSize ) // thiscore.ReverbX %= (u32)thiscore.EffectsBufferSize; @@ -64,17 +68,10 @@ StereoOut32 DoReverb( V_Core& thiscore, const StereoOut32& Input ) // Reverb processing occurs at 24khz, so we skip processing every other sample, // and use the previous calculation for this core instead. - if( thiscore.EffectsBufferSize <= 0 ) - { - // StartA is past EndA, so effects are disabled. - //ConLog( " * SPU2: Effects disabled due to leapfrogged EffectsStart." ); - return Input; - } - if( (Cycles&1)==0 ) { StereoOut32 retval( thiscore.LastEffect ); - thiscore.LastEffect = Input; + thiscore.LastEffect = Input/2; return retval; } else @@ -82,6 +79,13 @@ StereoOut32 DoReverb( V_Core& thiscore, const StereoOut32& Input ) if( thiscore.RevBuffers.NeedsUpdated ) thiscore.UpdateEffectsBufferSize(); + if( thiscore.EffectsBufferSize <= 0 ) + { + // StartA is past EndA, so effects are disabled. + //ConLog( " * SPU2: Effects disabled due to leapfrogged EffectsStart." ); + return Input; + } + // Advance the current reverb buffer pointer, and cache the read/write addresses we'll be // needing for this session of reverb. @@ -131,21 +135,20 @@ StereoOut32 DoReverb( V_Core& thiscore, const StereoOut32& Input ) const s32 IIR_INPUT_B0 = ((_spu2mem[src_b0] * thiscore.Revb.IIR_COEF) + (INPUT_SAMPLE.Left * thiscore.Revb.IN_COEF_L))>>16; const s32 IIR_INPUT_B1 = ((_spu2mem[src_b1] * thiscore.Revb.IIR_COEF) + (INPUT_SAMPLE.Right * thiscore.Revb.IN_COEF_R))>>16; - //const s32 IIR_A0 = (IIR_INPUT_A0 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_a0] * (0x7fff - thiscore.Revb.IIR_ALPHA)); - //const s32 IIR_A1 = (IIR_INPUT_A1 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_a1] * (0x7fff - thiscore.Revb.IIR_ALPHA)); - //const s32 IIR_B0 = (IIR_INPUT_B0 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_b0] * (0x7fff - thiscore.Revb.IIR_ALPHA)); - //const s32 IIR_B1 = (IIR_INPUT_B1 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_b1] * (0x7fff - thiscore.Revb.IIR_ALPHA)); - - //_spu2mem[dest2_a0] = clamp_mix( IIR_A0 >> 16 ); - //_spu2mem[dest2_a1] = clamp_mix( IIR_A1 >> 16 ); - //_spu2mem[dest2_b0] = clamp_mix( IIR_B0 >> 16 ); - //_spu2mem[dest2_b1] = clamp_mix( IIR_B1 >> 16 ); + /*const s32 IIR_A0 = (IIR_INPUT_A0 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_a0] * (0x7fff - thiscore.Revb.IIR_ALPHA)); + const s32 IIR_A1 = (IIR_INPUT_A1 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_a1] * (0x7fff - thiscore.Revb.IIR_ALPHA)); + const s32 IIR_B0 = (IIR_INPUT_B0 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_b0] * (0x7fff - thiscore.Revb.IIR_ALPHA)); + const s32 IIR_B1 = (IIR_INPUT_B1 * thiscore.Revb.IIR_ALPHA) + (_spu2mem[dest_b1] * (0x7fff - thiscore.Revb.IIR_ALPHA)); + _spu2mem[dest2_a0] = clamp_mix( IIR_A0 >> 16 ); + _spu2mem[dest2_a1] = clamp_mix( IIR_A1 >> 16 ); + _spu2mem[dest2_b0] = clamp_mix( IIR_B0 >> 16 ); + _spu2mem[dest2_b1] = clamp_mix( IIR_B1 >> 16 );*/ // Faster single-mul approach to interpolation: - const s32 IIR_A0 = IIR_INPUT_A0 + ((_spu2mem[dest_a0]-IIR_INPUT_A0) * thiscore.Revb.IIR_ALPHA)>>16; - const s32 IIR_A1 = IIR_INPUT_A1 + ((_spu2mem[dest_a1]-IIR_INPUT_A1) * thiscore.Revb.IIR_ALPHA)>>16; - const s32 IIR_B0 = IIR_INPUT_B0 + ((_spu2mem[dest_b0]-IIR_INPUT_B0) * thiscore.Revb.IIR_ALPHA)>>16; - const s32 IIR_B1 = IIR_INPUT_B1 + ((_spu2mem[dest_b1]-IIR_INPUT_B1) * thiscore.Revb.IIR_ALPHA)>>16; + const s32 IIR_A0 = IIR_INPUT_A0 + (((_spu2mem[dest_a0]-IIR_INPUT_A0) * thiscore.Revb.IIR_ALPHA)>>16); + const s32 IIR_A1 = IIR_INPUT_A1 + (((_spu2mem[dest_a1]-IIR_INPUT_A1) * thiscore.Revb.IIR_ALPHA)>>16); + const s32 IIR_B0 = IIR_INPUT_B0 + (((_spu2mem[dest_b0]-IIR_INPUT_B0) * thiscore.Revb.IIR_ALPHA)>>16); + const s32 IIR_B1 = IIR_INPUT_B1 + (((_spu2mem[dest_b1]-IIR_INPUT_B1) * thiscore.Revb.IIR_ALPHA)>>16); _spu2mem[dest2_a0] = clamp_mix( IIR_A0 ); _spu2mem[dest2_a1] = clamp_mix( IIR_A1 ); diff --git a/plugins/spu2-x/src/Spu2.cpp b/plugins/spu2-x/src/Spu2.cpp index 8dfbc7db62..b249b02e69 100644 --- a/plugins/spu2-x/src/Spu2.cpp +++ b/plugins/spu2-x/src/Spu2.cpp @@ -200,18 +200,18 @@ void V_Core::Reset() s32 V_Core::EffectsBufferIndexer( s32 offset ) const { - u32 pos = EffectsStartA + ReverbX + offset; + u32 pos = EffectsStartA + offset; // Need to use modulus here, because games can and will drop the buffer size // without notice, and it leads to offsets several times past the end of the buffer. if( pos > EffectsEndA ) { - pos = EffectsStartA + ((ReverbX + offset) % (u32)EffectsBufferSize); + pos = EffectsStartA + (offset % EffectsBufferSize); } else if( pos < EffectsStartA ) { - pos = EffectsEndA+1 - ((ReverbX + offset) % (u32)EffectsBufferSize ); + pos = EffectsEndA+1 - (offset % EffectsBufferSize ); } return pos; } @@ -230,12 +230,11 @@ void V_Core::UpdateFeedbackBuffersB() void V_Core::UpdateEffectsBufferSize() { - ReverbX = 0; - const s32 newbufsize = EffectsEndA - EffectsStartA + 1; if( !RevBuffers.NeedsUpdated && newbufsize == EffectsBufferSize ) return; RevBuffers.NeedsUpdated = false; + EffectsBufferSize = newbufsize; if( EffectsBufferSize == 0 ) return; @@ -675,6 +674,7 @@ u16 SPU_ps1_read(u32 mem) { value = Cores[0].EffectsStartA>>3; Cores[0].UpdateEffectsBufferSize(); + Cores[0].ReverbX = 0; } break; case 0x1da4: value = Cores[0].IRQA>>3; break; @@ -862,52 +862,53 @@ __forceinline void SPU2_FastWrite( u32 rmem, u16 value ) } else { + V_Core& thiscore = Cores[core]; switch(omem) { case REG_C_ATTR: { - int irqe = Cores[core].IRQEnable; - int bit0 = Cores[core].AttrBit0; - int bit4 = Cores[core].AttrBit4; + int irqe = thiscore.IRQEnable; + int bit0 = thiscore.AttrBit0; + int bit4 = thiscore.AttrBit4; - if( ((value>>15)&1) && (!Cores[core].CoreEnabled) && (Cores[core].InitDelay==0) ) // on init/reset + if( ((value>>15)&1) && (!thiscore.CoreEnabled) && (thiscore.InitDelay==0) ) // on init/reset { if(hasPtr) { - Cores[core].InitDelay=1; - Cores[core].Regs.STATX=0; + thiscore.InitDelay=1; + thiscore.Regs.STATX=0; } else { - Cores[core].Reset(); + thiscore.Reset(); } } - Cores[core].AttrBit0 =(value>> 0) & 0x01; //1 bit - Cores[core].DMABits =(value>> 1) & 0x07; //3 bits - Cores[core].AttrBit4 =(value>> 4) & 0x01; //1 bit - Cores[core].AttrBit5 =(value>> 5) & 0x01; //1 bit - Cores[core].IRQEnable =(value>> 6) & 0x01; //1 bit - Cores[core].FxEnable =(value>> 7) & 0x01; //1 bit - Cores[core].NoiseClk =(value>> 8) & 0x3f; //6 bits - //Cores[core].Mute =(value>>14) & 0x01; //1 bit - Cores[core].Mute=0; - Cores[core].CoreEnabled=(value>>15) & 0x01; //1 bit - Cores[core].Regs.ATTR =value&0x7fff; + thiscore.AttrBit0 =(value>> 0) & 0x01; //1 bit + thiscore.DMABits =(value>> 1) & 0x07; //3 bits + thiscore.AttrBit4 =(value>> 4) & 0x01; //1 bit + thiscore.AttrBit5 =(value>> 5) & 0x01; //1 bit + thiscore.IRQEnable =(value>> 6) & 0x01; //1 bit + thiscore.FxEnable =(value>> 7) & 0x01; //1 bit + thiscore.NoiseClk =(value>> 8) & 0x3f; //6 bits + //thiscore.Mute =(value>>14) & 0x01; //1 bit + thiscore.Mute=0; + thiscore.CoreEnabled=(value>>15) & 0x01; //1 bit + thiscore.Regs.ATTR =value&0x7fff; if(value&0x000E) { ConLog(" * SPU2: Core %d ATTR unknown bits SET! value=%04x\n",core,value); } - if(Cores[core].AttrBit0!=bit0) + if(thiscore.AttrBit0!=bit0) { - ConLog(" * SPU2: ATTR bit 0 set to %d\n",Cores[core].AttrBit0); + ConLog(" * SPU2: ATTR bit 0 set to %d\n",thiscore.AttrBit0); } - if(Cores[core].IRQEnable!=irqe) + if(thiscore.IRQEnable!=irqe) { - ConLog(" * SPU2: IRQ %s\n",((Cores[core].IRQEnable==0)?"disabled":"enabled")); - if(!Cores[core].IRQEnable) + ConLog(" * SPU2: IRQ %s\n",((thiscore.IRQEnable==0)?"disabled":"enabled")); + if(!thiscore.IRQEnable) Spdif.Info=0; } @@ -915,23 +916,23 @@ __forceinline void SPU2_FastWrite( u32 rmem, u16 value ) break; case REG_S_PMON: - vx=2; for (vc=1;vc<16;vc++) { Cores[core].Voices[vc].Modulated=(s8)((value & vx)/vx); vx<<=1; } - SetLoWord( Cores[core].Regs.PMON, value ); + vx=2; for (vc=1;vc<16;vc++) { thiscore.Voices[vc].Modulated=(s8)((value & vx)/vx); vx<<=1; } + SetLoWord( thiscore.Regs.PMON, value ); break; case (REG_S_PMON + 2): - vx=1; for (vc=16;vc<24;vc++) { Cores[core].Voices[vc].Modulated=(s8)((value & vx)/vx); vx<<=1; } - SetHiWord( Cores[core].Regs.PMON, value ); + vx=1; for (vc=16;vc<24;vc++) { thiscore.Voices[vc].Modulated=(s8)((value & vx)/vx); vx<<=1; } + SetHiWord( thiscore.Regs.PMON, value ); break; case REG_S_NON: - vx=1; for (vc=0;vc<16;vc++) { Cores[core].Voices[vc].Noise=(s8)((value & vx)/vx); vx<<=1; } - SetLoWord( Cores[core].Regs.NON, value ); + vx=1; for (vc=0;vc<16;vc++) { thiscore.Voices[vc].Noise=(s8)((value & vx)/vx); vx<<=1; } + SetLoWord( thiscore.Regs.NON, value ); break; case (REG_S_NON + 2): - vx=1; for (vc=16;vc<24;vc++) { Cores[core].Voices[vc].Noise=(s8)((value & vx)/vx); vx<<=1; } - SetHiWord( Cores[core].Regs.NON, value ); + vx=1; for (vc=16;vc<24;vc++) { thiscore.Voices[vc].Noise=(s8)((value & vx)/vx); vx<<=1; } + SetHiWord( thiscore.Regs.NON, value ); break; // Games like to repeatedly write these regs over and over with the same value, hence @@ -940,12 +941,12 @@ __forceinline void SPU2_FastWrite( u32 rmem, u16 value ) { \ const uint start_bit = hiword ? 16 : 0; \ const uint end_bit = hiword ? 24 : 16; \ - const u32 result = hiword ? SetHiWord( Cores[core].Regs.reg_out, value ) : SetLoWord( Cores[core].Regs.reg_out, value ); \ - if( result == Cores[core].Regs.reg_out ) return; \ + const u32 result = hiword ? SetHiWord( thiscore.Regs.reg_out, value ) : SetLoWord( thiscore.Regs.reg_out, value ); \ + if( result == thiscore.Regs.reg_out ) return; \ \ - Cores[core].Regs.reg_out = result; \ + thiscore.Regs.reg_out = result; \ for (uint vc=start_bit, vx=1; vc