From 6c2d95f27d6ad59a5117f9115728cc2e5565fb6b Mon Sep 17 00:00:00 2001 From: ramapcsx2 Date: Thu, 16 Oct 2008 13:46:17 +0000 Subject: [PATCH] SPU2Ghz: Part one of a bigger update git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@202 a6443dda-0b58-4228-96e9-037be469359c --- plugins/spu2ghz/mixer.cpp | 26 ++++++++++++++++---------- plugins/spu2ghz/sndout.cpp | 24 ++++++++++++------------ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/plugins/spu2ghz/mixer.cpp b/plugins/spu2ghz/mixer.cpp index 3a08222559..d4b5476a08 100644 --- a/plugins/spu2ghz/mixer.cpp +++ b/plugins/spu2ghz/mixer.cpp @@ -363,7 +363,8 @@ void GetVoiceValues(s32& Value) { vc.SP+=pitch; while(vc.SP>=4096) { - DT=0; + //this isn't needed. it's garaunteed to be assigned a valid value. + //DT=0; if(vc.Noise) GetNoiseValues(DT); @@ -379,7 +380,6 @@ void GetVoiceValues(s32& Value) { } CalculateADSR(); -// CalculateADSR(); if(vc.ADSR.Phase==0) { @@ -388,12 +388,18 @@ void GetVoiceValues(s32& Value) { } else { - if(Interpolation==0) { + // if SP is zero then we landed perfectly on a sample source, no + // interpolation necessary (this is important too, since the + // interpolator will pick the wrong sample to mix). + + if(Interpolation==0 || vc.SP == 0) { Data = vc.PV1; } else if(Interpolation==1) //linear { - s64 t0 = vc.PV1 - vc.PV2; + // [Air]: Inverted the interpolation delta. The old way was generating + // inverted waveforms. + s64 t0 = vc.PV2 - vc.PV1; s64 t1 = vc.PV1; Data = (((t0*vc.SP)>>12) + t1); } @@ -403,11 +409,11 @@ void GetVoiceValues(s32& Value) { s64 a1 = vc.PV4 - vc.PV3 - a0; s64 a2 = vc.PV1 - vc.PV4; s64 a3 = vc.PV2; - s64 mu = vc.SP; + s64 mu = 4096-vc.SP; - s64 t0 = ((a0 )*mu)>>12; - s64 t1 = ((t0+a1)*mu)>>12; - s64 t2 = ((t1+a2)*mu)>>12; + s64 t0 = ((a0 )*mu)>>18; //all 3 were >>12, was causing ugly, loud overflow sound + s64 t1 = ((t0+a1)*mu)>>18; + s64 t2 = ((t1+a2)*mu)>>18; s64 t3 = ((t2+a3)); Data = t3; @@ -417,7 +423,7 @@ void GetVoiceValues(s32& Value) { vc.OutX=abs(Value); } - if(vc.PeakXGetBufferSize(); //Emergency stretch to compensate for FPS fluctuations and keep the buffers happy - bool a=(bufferUsage < CurBufferSize * 2.5); - bool b=(bufferUsage >= (bufferSize - CurBufferSize * 2.5)); + bool a=(bufferUsage < CurBufferSize * 4); + bool b=(bufferUsage >= (bufferSize - CurBufferSize * 4)); if(a!=b) { - if (bufferUsage < CurBufferSize) { cTempo*=0.7f; } - else if(bufferUsage < CurBufferSize * 2) { cTempo*=0.90f; } - else if(bufferUsage < CurBufferSize * 2.5) { cTempo*=0.95f; } + if (bufferUsage < CurBufferSize * 1.5) { cTempo*=0.70f; } + else if(bufferUsage < CurBufferSize * 2) { cTempo*=0.90f; } + else if(bufferUsage < CurBufferSize * 3.9) { cTempo*=0.95f; } - if (bufferUsage > (bufferSize - CurBufferSize)) { cTempo*=1.3f; } - else if(bufferUsage > (bufferSize - CurBufferSize * 2)) { cTempo*=1.10f; } - else if(bufferUsage > (bufferSize - CurBufferSize * 2.5)) { cTempo*=1.05f; } + if (bufferUsage > (bufferSize - CurBufferSize * 1.5)) { cTempo*=1.30f; } + else if(bufferUsage > (bufferSize - CurBufferSize * 2)) { cTempo*=1.10f; } + else if(bufferUsage > (bufferSize - CurBufferSize * 3.9)) { cTempo*=1.05f; } if (cTempo != lastTempo) { - printf("%f %d\n",cTempo,bufferUsage); + //printf("%f %d\n",cTempo,bufferUsage); pSoundTouch->setTempo(cTempo); } } @@ -354,12 +354,12 @@ void UpdateTempoChange() if((valAccum < 1.05f) && (valAccum > 0.95f) /*&& (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.0f; } else { - printf("Timestretch Debug > Playbackpeed: %f\n",valAccum); + // printf("Timestretch Debug > Playbackpeed: %f\n",valAccum); } if (valAccum != lastTempo) //only update soundtouch object when needed