add in some SPU interpolation code, conditionally compiled. enabled it in windows so we can see what it sounds like.

This commit is contained in:
zeromus 2008-09-14 06:34:08 +00:00
parent 649a4c49ac
commit 1de6f8e460
4 changed files with 49 additions and 7 deletions

View File

@ -13,6 +13,7 @@
- Convert to c++!
- Added gfx3d module which emulates the whole GE as part of the core emu. Moved the windows/cocoa OGLRender to the
emu core and replace ogl_collector. Now every platform shares the same 3d code. [zeromus]
- Add in some crude interpolation in the SPU (conditionally compiled) so that I can bear to listen to it. [zeromus]
Mac OS X port:
- Fixed: Filenames and paths with unicode characters now work. [Jeff]
- Fixed: Load state from file button works again. [Jeff]

View File

@ -221,6 +221,7 @@ void SPU_KeyOn(int channel)
chan->buf8 = (s8*)&MMU.MMU_MEM[1][(chan->addr>>20)&0xFF][(chan->addr & MMU.MMU_MASK[1][(chan->addr >> 20) & 0xFF])];
chan->pcm16b = (s16)((chan->buf8[1] << 8) | chan->buf8[0]);
chan->pcm16b_last = 0;
chan->index = chan->buf8[2] & 0x7F;
chan->lastsampcnt = 7;
chan->sampcnt = 8;
@ -694,18 +695,46 @@ void SPU_WriteLong(u32 addr, u32 val)
T1WriteLong(MMU.ARM7_REG, addr, val);
}
static s32 Interpolate(s32 a, s32 b, double ratio)
{
ratio = ratio - (int)ratio;
return (1-ratio)*a + ratio*b;
}
//////////////////////////////////////////////////////////////////////////////
static INLINE void Fetch8BitData(channel_struct *chan, s32 *data)
{
#ifdef SPU_INTERPOLATE
int loc = (int)chan->sampcnt;
s32 a = (s32)chan->buf8[loc] << 8;
if(loc<chan->length-1) {
double ratio = chan->sampcnt-loc;
s32 b = (s32)chan->buf8[loc+1] << 8;
a = (1-ratio)*a + ratio*b;
}
*data = a;
#else
*data = (s32)chan->buf8[(int)chan->sampcnt] << 8;
#endif
}
//////////////////////////////////////////////////////////////////////////////
static INLINE void Fetch16BitData(channel_struct *chan, s32 *data)
{
*data = (s32)chan->buf16[(int)chan->sampcnt];
#ifdef SPU_INTERPOLATE
int loc = (int)chan->sampcnt;
s32 a = (s32)chan->buf16[loc];
if(loc<chan->length-1) {
double ratio = chan->sampcnt-loc;
s32 b = (s32)chan->buf16[loc+1];
a = (1-ratio)*a + ratio*b;
}
*data = a;
#else
*data = (s32)chan->buf16[(int)chan->sampcnt];
#endif
}
//////////////////////////////////////////////////////////////////////////////
@ -731,7 +760,11 @@ static INLINE void FetchADPCMData(channel_struct *chan, s32 *data)
if (chan->lastsampcnt == (int)chan->sampcnt)
{
// No sense decoding, just return the last sample
*data = (s32)chan->pcm16b;
#ifdef SPU_INTERPOLATE
*data = Interpolate((s32)chan->pcm16b_last,(s32)chan->pcm16b,chan->sampcnt);
#else
*data = (s32)chan->pcm16b;
#endif
return;
}
@ -746,12 +779,20 @@ static INLINE void FetchADPCMData(channel_struct *chan, s32 *data)
if (data4bit & 0x8)
diff = -diff;
#ifdef SPU_INTERPOLATE
chan->pcm16b_last = chan->pcm16b;
#endif
chan->pcm16b = (s16)MinMax(chan->pcm16b+diff, -0x8000, 0x7FFF);
chan->index = MinMax(chan->index+indextbl[data4bit & 0x7], 0, 88);
}
chan->lastsampcnt = chan->sampcnt;
*data = (s32)chan->pcm16b;
#ifdef SPU_INTERPOLATE
*data = Interpolate((s32)chan->pcm16b_last,(s32)chan->pcm16b,chan->sampcnt);
#else
*data = (s32)chan->pcm16b;
#endif
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -62,7 +62,7 @@ typedef struct
double sampinc;
// ADPCM specific
int lastsampcnt;
s16 pcm16b;
s16 pcm16b, pcm16b_last;
int index;
} channel_struct;

View File

@ -54,7 +54,7 @@
EnableFiberSafeOptimizations="false"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="..;.\zlib123;.\zziplib"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;VERSION=\&quot;0.8.0b2 DEBUG\&quot;;WIN32;BETA_VERSION"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;VERSION=\&quot;0.8.0b2 DEBUG\&quot;;WIN32;BETA_VERSION;SPU_INTERPOLATE"
ExceptionHandling="0"
BufferSecurityCheck="false"
EnableEnhancedInstructionSet="0"
@ -140,7 +140,7 @@
EnableFiberSafeOptimizations="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..;.\zlib123;.\zziplib"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;VERSION=\&quot;0.8.0b2\&quot;;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;BETA_VERSION;GDB_STUB"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;VERSION=\&quot;0.8.0b2\&quot;;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;BETA_VERSION;GDB_STUB;SPU_INTERPOLATE"
StringPooling="true"
ExceptionHandling="0"
BufferSecurityCheck="false"
@ -228,7 +228,7 @@
EnableFiberSafeOptimizations="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..;.\zlib123;.\zziplib"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;VERSION=\&quot;0.8.0b2 SSE2\&quot;;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SSE2;BETA_VERSION;GDB_STUB"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;VERSION=\&quot;0.8.0b2 SSE2\&quot;;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SSE2;BETA_VERSION;GDB_STUB;SPU_INTERPOLATE"
StringPooling="true"
ExceptionHandling="0"
BufferSecurityCheck="false"