diff --git a/Gamecube/GamecubeMain.cpp b/Gamecube/GamecubeMain.cpp index 5d460a98..f47d7659 100644 --- a/Gamecube/GamecubeMain.cpp +++ b/Gamecube/GamecubeMain.cpp @@ -85,6 +85,7 @@ void LidInterrupt(); void CheckPsxType(); void psxResetRcntRate(); void plugin_call_rearmed_cbs(unsigned long autoDwActFixes, int cfgUseDithering); +void setSpuInterpolation(int spuInterpolation); } u32* xfb[3] = { NULL, NULL, NULL }; /*** Framebuffers ***/ @@ -108,7 +109,7 @@ char frameLimit[2]; char frameSkip; char useDithering; extern char audioEnabled; -char volume; +char spuInterpolation; char showFPSonScreen; char printToScreen; char menuActive; @@ -163,7 +164,7 @@ static struct { char min, max; } OPTIONS[] = { { "Audio", &audioEnabled, AUDIO_DISABLE, AUDIO_ENABLE }, - { "Volume", &volume, VOLUME_LOUDEST, VOLUME_LOW }, + { "Interpolation", &spuInterpolation, SIMPLE_INTERPOLATION, GAUSSI_INTERPOLATION }, { "FPS", &showFPSonScreen, FPS_HIDE, FPS_SHOW }, // { "Debug", &printToScreen, DEBUG_HIDE, DEBUG_SHOW }, { "ScreenMode", &screenMode, SCREENMODE_4x3, SCREENMODE_16x9_PILLARBOX }, @@ -331,7 +332,7 @@ void loadSettings(int argc, char *argv[]) { // Default Settings audioEnabled = 1; // Audio - volume = VOLUME_MEDIUM; + spuInterpolation = SIMPLE_INTERPOLATION; #ifdef RELEASE showFPSonScreen = 0; // Don't show FPS on Screen #else @@ -376,7 +377,6 @@ void loadSettings(int argc, char *argv[]) Config.Xa = 0; //XA enabled Config.Cdda = 0; //CDDA enabled Config.cycle_multiplier = CYCLE_MULT_DEFAULT; - iVolume = volume; //Volume="medium" in PEOPSspu Config.PsxAuto = 1; //Autodetect LoadCdBios = BOOTTHRUBIOS_NO; lang = 0; @@ -433,7 +433,7 @@ void loadSettings(int argc, char *argv[]) //Synch settings with Config Config.Cpu=dynacore; //iUseDither = useDithering; - iVolume = volume; + setSpuInterpolation(spuInterpolation); } void ScanPADSandReset(u32 dummy) diff --git a/Gamecube/menu/SettingsFrame.cpp b/Gamecube/menu/SettingsFrame.cpp index 91c19cf1..61e39457 100644 --- a/Gamecube/menu/SettingsFrame.cpp +++ b/Gamecube/menu/SettingsFrame.cpp @@ -143,6 +143,7 @@ FILE* IplFont_getFontFile(char* sdUsb); void psxResetRcntRate(); void pl_chg_psxtype(int is_pal_); void gpuChangePsxType(); +void setSpuInterpolation(int spuInterpolation); } #define NUM_FRAME_BUTTONS 64 @@ -238,9 +239,9 @@ static char FRAME_STRINGS[79][24] = "Disable Audio", "Disable XA", "Disable CDDA", - "Volume", - "loudest", //iVolume=1 - "loud", + "Interpolation", + "Simple", //iVolume=1 + "Gaussi", "medium", "low", //iVolume=4 //Strings for Saves tab (starting at FRAME_STRINGS[51]) ..was[55] @@ -640,18 +641,12 @@ void SettingsFrame::activateSubmenu(int submenu) else FRAME_BUTTONS[42].button->setSelected(true); if (Config.Cdda == CDDA_DISABLE) FRAME_BUTTONS[43].button->setSelected(true); else FRAME_BUTTONS[44].button->setSelected(true); - FRAME_BUTTONS[45].buttonString = FRAME_STRINGS[46+iVolume]; + FRAME_BUTTONS[45].buttonString = FRAME_STRINGS[46 + spuInterpolation]; for (int i = 39; i < 46; i++) { FRAME_BUTTONS[i].button->setVisible(true); FRAME_BUTTONS[i].button->setActive(true); } - // upd xjsxjs197 start - /*for (int i = 43; i <= 44; i++) //disable CDDA buttons - { - FRAME_BUTTONS[i].button->setActive(false); - }*/ - // upd xjsxjs197 end break; case SUBMENU_SAVES: setDefaultFocus(FRAME_BUTTONS[4].button); @@ -1669,16 +1664,18 @@ void Func_DisableCddaNo() //menu::MessageBox::getInstance().setMessage("CDDA audio is not implemented"); } -extern "C" void SetVolume(void); - void Func_VolumeToggle() { - iVolume--; - if (iVolume<1) - iVolume = 4; - FRAME_BUTTONS[45].buttonString = FRAME_STRINGS[46+iVolume]; - volume = iVolume; - SetVolume(); + if (spuInterpolation == SIMPLE_INTERPOLATION) + { + spuInterpolation = GAUSSI_INTERPOLATION; + } + else + { + spuInterpolation = SIMPLE_INTERPOLATION; + } + FRAME_BUTTONS[45].buttonString = FRAME_STRINGS[46 + spuInterpolation]; + setSpuInterpolation(spuInterpolation); } void Func_MemcardSaveSD() diff --git a/Gamecube/wiiSXconfig.h b/Gamecube/wiiSXconfig.h index 4b776bbb..9f37d1e1 100644 --- a/Gamecube/wiiSXconfig.h +++ b/Gamecube/wiiSXconfig.h @@ -44,14 +44,11 @@ enum ConfigCdda //Config.Cdda CDDA_DISABLE }; -extern int iVolume; -extern char volume; -enum iVolume -{ - VOLUME_LOUDEST=1, - VOLUME_LOUD, - VOLUME_MEDIUM, - VOLUME_LOW +extern char spuInterpolation; +enum spuInterpolationEnum +{ + SIMPLE_INTERPOLATION = 1, + GAUSSI_INTERPOLATION, }; extern char showFPSonScreen; diff --git a/dfsound/dfspu.c b/dfsound/dfspu.c index 1509b485..5aaf27f3 100644 --- a/dfsound/dfspu.c +++ b/dfsound/dfspu.c @@ -18,6 +18,7 @@ * * ***************************************************************************/ +#include #include "stdafx.h" #define _IN_SPU @@ -127,8 +128,14 @@ int ChanBuf[NSSIZE]; // / // -static void InterpolateUp(s16 *SB, int sinc) +static void InterpolateUp(sample_buf *sb, int sinc) { + s16 *SB = sb->SB; + if (sb->sinc_old != sinc) + { + sb->sinc_old = sinc; + SB[32] = 1; + } if (SB[32] == 1) // flag == 1? calc step and set flag... and don't change the value in this pass { int id1 = SB[30] - SB[29]; // curr delta to next val @@ -190,8 +197,9 @@ static void InterpolateUp(s16 *SB, int sinc) // even easier interpolation on downsampling, also no special filter, again just "Pete's common sense" tm // -static void InterpolateDown(s16 *SB, int sinc) +static void InterpolateDown(sample_buf *sb, int sinc) { + s16 *SB = sb->SB; if (sinc >= 0x20000L) // we would skip at least one val? { int temp; @@ -204,15 +212,8 @@ static void InterpolateDown(s16 *SB, int sinc) } //////////////////////////////////////////////////////////////////////// -// helpers for gauss interpolation - -#define gval0 (((short*)(&SB[29]))[gpos&3]) -#define gval(x) ((int)((short*)(&SB[29]))[(gpos+x)&3]) #include "gauss_i.h" - -//////////////////////////////////////////////////////////////////////// - #include "xa.c" static void do_irq(int cycles_after) @@ -261,15 +262,17 @@ void do_irq_io(int cycles_after) // START SOUND... called by main thread to setup a new sound on a channel //////////////////////////////////////////////////////////////////////// -static void StartSoundSB(s16 *SB) +static void ResetInterpolation(sample_buf *sb) { - SB[26]=0; // init mixing vars - SB[27]=0; + memset(&sb->interp, 0, sizeof(sb->interp)); + sb->sinc_old = -1; +} - SB[28]=0; - SB[29]=0; // init our interpolation helpers - SB[30]=0; - SB[31]=0; +static void StartSoundSB(sample_buf *sb) +{ + sb->SB[26]=0; // init mixing vars + sb->SB[27]=0; + ResetInterpolation(sb); } static void StartSoundMain(int ch) @@ -297,123 +300,67 @@ static void StartSoundMain(int ch) static void StartSound(int ch) { StartSoundMain(ch); - StartSoundSB(spu.SB + ch * SB_SIZE); + StartSoundSB(&spu.sb[ch]); } //////////////////////////////////////////////////////////////////////// // ALL KIND OF HELPERS //////////////////////////////////////////////////////////////////////// -INLINE int FModChangeFrequency(s16 *SB, int pitch, int ns) +INLINE int FModChangeFrequency(int pitch, int ns, int *fmod_buf) { - unsigned int NP=pitch; - int sinc; - - NP=((32768L+iFMod[ns])*NP)>>15; + pitch = (signed short)pitch; + pitch = ((32768 + fmod_buf[ns]) * pitch) >> 15; + pitch &= 0xffff; + if (pitch > 0x3fff) + pitch = 0x3fff; - if(NP>0x3fff) NP=0x3fff; - if(NP<0x1) NP=0x1; + fmod_buf[ns] = 0; - sinc=NP<<4; // calc frequency - iFMod[ns]=0; - SB[32]=1; // reset interpolation - - return sinc; + return pitch << 4; } -//////////////////////////////////////////////////////////////////////// - -INLINE void StoreInterpolationVal(s16 *SB, int sinc, s16 fa, int fmod_freq) +INLINE void StoreInterpolationGaussCubic(sample_buf *sb, s16 fa) { - if(fmod_freq) // fmod freq channel - SB[29]=fa; - else - { - //ssat32_to_16(fa); - - /*if(spu_config.iUseInterpolation>=2) // gauss/cubic interpolation - { - int gpos = SB[28]; - gval0 = fa; - gpos = (gpos+1) & 3; - SB[28] = gpos; - } - else - if(spu_config.iUseInterpolation==1)*/ // simple interpolation - { - SB[28] = 0; - SB[29] = SB[30]; // -> helpers for simple linear interpolation: delay real val for two slots, and calc the two deltas, for a 'look at the future behaviour' - SB[30] = SB[31]; - SB[31] = fa; - SB[32] = 1; // -> flag: calc new interolation - } - //else SB[29]=fa; // no interpolation - } + int gpos = sb->interp.gauss.pos & 3; + sb->interp.gauss.val[gpos++] = fa; + sb->interp.gauss.pos = gpos & 3; } -//////////////////////////////////////////////////////////////////////// +#define gval(x) (int)sb->interp.gauss.val[(gpos + x) & 3] -INLINE int iGetInterpolationVal(s16 *SB, int sinc, int spos, int fmod_freq) +INLINE int GetInterpolationCubic(const sample_buf *sb, int spos) { + int gpos = sb->interp.gauss.pos; + int xd = (spos >> 1) + 1; int fa; - if(fmod_freq) return (int)(SB[29]); + fa = gval(3) - 3*gval(2) + 3*gval(1) - gval(0); + fa *= (xd - (2<<15)) / 6; + fa >>= 15; + fa += gval(2) - gval(1) - gval(1) + gval(0); + fa *= (xd - (1<<15)) >> 1; + fa >>= 15; + fa += gval(1) - gval(0); + fa *= xd; + fa >>= 15; + fa = fa + gval(0); + //ssat32_to_16(fa); + return fa; +} - /*switch(spu_config.iUseInterpolation) - { - //--------------------------------------------------// - case 3: // cubic interpolation - { - long xd;int gpos; - xd = (spos >> 1)+1; - gpos = SB[28]; - - fa = gval(3) - 3*gval(2) + 3*gval(1) - gval0; - fa *= (xd - (2<<15)) / 6; - fa >>= 15; - fa += gval(2) - gval(1) - gval(1) + gval0; - fa *= (xd - (1<<15)) >> 1; - fa >>= 15; - fa += gval(1) - gval0; - fa *= xd; - fa >>= 15; - fa = fa + gval0; - - } break; - //--------------------------------------------------// - case 2: // gauss interpolation - { - int vl, vr;int gpos; - vl = (spos >> 6) & ~3; - gpos = SB[28]; - vr=(gauss[vl]*(int)gval0) >> 15; - vr+=(gauss[vl+1]*gval(1)) >> 15; - vr+=(gauss[vl+2]*gval(2)) >> 15; - vr+=(gauss[vl+3]*gval(3)) >> 15; - fa = vr; - } break; - //--------------------------------------------------// - case 1: // simple interpolation - { - if(sinc<0x10000L) // -> upsampling? - InterpolateUp(SB, sinc); // --> interpolate up - else InterpolateDown(SB, sinc); // --> else down - fa=SB[29]; - } break; - //--------------------------------------------------// - default: // no interpolation - { - fa=SB[29]; - } break; - //--------------------------------------------------// - }*/ - if(sinc<0x10000L) // -> upsampling? - InterpolateUp(SB, sinc); // --> interpolate up - else - InterpolateDown(SB, sinc); // --> else down - fa=(int)(SB[29]); - return fa; +INLINE int GetInterpolationGauss(const sample_buf *sb, int spos) +{ + int gpos = sb->interp.gauss.pos; + int vl = (spos >> 6) & ~3; + int vr; + vr = (gauss[vl+0] * gval(0)) >> 15; + vr += (gauss[vl+1] * gval(1)) >> 15; + vr += (gauss[vl+2] * gval(2)) >> 15; + vr += (gauss[vl+3] * gval(3)) >> 15; + //ssat32_to_16(vr); + return vr; } static f32 FK0[16] = { @@ -486,8 +433,11 @@ static int decode_block(void *unused, int ch, s16 *SB) int ret = 0; start = s_chan->pCurr; // set up the current pos - if (start == spu.spuMemC) // ? + if (start - spu.spuMemC < 0x1000) { // ? + //log_unhandled("ch%02d plays decode bufs @%05lx\n", + // ch, (long)(start - spu.spuMemC)); ret = 1; + } if (s_chan->prevflags & 1) // 1: stop/loop { @@ -589,10 +539,10 @@ static void scan_for_irq(int ch, unsigned int *upd_samples) } } -#define make_do_samples(name, fmod_code, interp_start, interp1_code, interp2_code, interp_end) \ -static noinline int do_samples_##name( \ +#define make_do_samples(name, fmod_code, interp_start, interp_store, interp_get, interp_end) \ +static noinline int name(int *dst, \ int (*decode_f)(void *context, int ch, int *SB), void *ctx, \ - int ch, int ns_to, s16 *SB, int sinc, int *spos, int *sbpos) \ + int ch, int ns_to, sample_buf *sb, int sinc, int *spos, int *sbpos) \ { \ int ns, d; \ s16 fa; \ @@ -606,20 +556,20 @@ static noinline int do_samples_##name( \ *spos += sinc; \ while (*spos >= 0x10000) \ { \ - fa = SB[(*sbpos)++]; \ + fa = sb->SB[(*sbpos)++]; \ if (*sbpos >= 28) \ { \ *sbpos = 0; \ - d = decode_f(ctx, ch, SB); \ + d = decode_f(ctx, ch, sb->SB); \ if (d && ns < ret) \ ret = ns; \ } \ \ - interp1_code; \ + interp_store; \ *spos -= 0x10000; \ } \ \ - interp2_code; \ + interp_get; \ } \ \ interp_end; \ @@ -627,30 +577,56 @@ static noinline int do_samples_##name( \ return ret; \ } -#define fmod_recv_check \ - if(spu.s_chan[ch].bFMod==1 && iFMod[ns]) \ - sinc = FModChangeFrequency(SB, spu.s_chan[ch].iRawPitch, ns) - -make_do_samples(default, fmod_recv_check, , - StoreInterpolationVal(SB, sinc, fa, spu.s_chan[ch].bFMod==2), - ChanBuf[ns] = iGetInterpolationVal(SB, sinc, *spos, spu.s_chan[ch].bFMod==2), ) -make_do_samples(noint, , fa = SB[29], , ChanBuf[ns] = fa, SB[29] = fa) - +// helpers for simple linear interpolation: delay real val for two slots, +// and calc the two deltas, for a 'look at the future behaviour' #define simple_interp_store \ - SB[28] = 0; \ - SB[29] = SB[30]; \ - SB[30] = SB[31]; \ - SB[31] = fa; \ - SB[32] = 1 + sb->SB[28] = 0; \ + sb->SB[29] = sb->SB[30]; \ + sb->SB[30] = sb->SB[31]; \ + sb->SB[31] = fa; \ + sb->SB[32] = 1 #define simple_interp_get \ if(sinc<0x10000) /* -> upsampling? */ \ - InterpolateUp(SB, sinc); /* --> interpolate up */ \ - else InterpolateDown(SB, sinc); /* --> else down */ \ - ChanBuf[ns] = (int)(SB[29]) + InterpolateUp(sb, sinc); /* --> interpolate up */ \ + else InterpolateDown(sb, sinc); /* --> else down */ \ + dst[ns] = sb->SB[29] -make_do_samples(simple, , , +make_do_samples(do_samples_nointerp, , fa = sb->SB[29], + , dst[ns] = fa, sb->SB[29] = fa) +make_do_samples(do_samples_simple, , , simple_interp_store, simple_interp_get, ) +make_do_samples(do_samples_gauss, , , + StoreInterpolationGaussCubic(sb, fa), + dst[ns] = GetInterpolationGauss(sb, *spos), ) +make_do_samples(do_samples_cubic, , , + StoreInterpolationGaussCubic(sb, fa), + dst[ns] = GetInterpolationCubic(sb, *spos), ) +make_do_samples(do_samples_fmod, + sinc = FModChangeFrequency(spu.s_chan[ch].iRawPitch, ns, iFMod), , + StoreInterpolationGaussCubic(sb, fa), + dst[ns] = GetInterpolationGauss(sb, *spos), ) + +INLINE int do_samples_adpcm(int *dst, + int (*decode_f)(void *context, int ch, s16 *SB), void *ctx, + int ch, int ns_to, int fmod, sample_buf *sb, int sinc, int *spos, int *sbpos) +{ + int interp = spu.interpolation; + if (fmod == 1) + return do_samples_fmod(dst, decode_f, ctx, ch, ns_to, sb, sinc, spos, sbpos); + if (fmod) + interp = 2; + switch (interp) { + case 0: + return do_samples_nointerp(dst, decode_f, ctx, ch, ns_to, sb, sinc, spos, sbpos); + case 1: + return do_samples_simple (dst, decode_f, ctx, ch, ns_to, sb, sinc, spos, sbpos); + default: + return do_samples_gauss (dst, decode_f, ctx, ch, ns_to, sb, sinc, spos, sbpos); + case 3: + return do_samples_cubic (dst, decode_f, ctx, ch, ns_to, sb, sinc, spos, sbpos); + } +} static int do_samples_skip(int ch, int ns_to) { @@ -679,7 +655,33 @@ static int do_samples_skip(int ch, int ns_to) return ret; } -static void do_lsfr_samples(int ns_to, int ctrl, +static int do_samples_skip_fmod(int ch, int ns_to, int *fmod_buf) +{ + SPUCHAN *s_chan = &spu.s_chan[ch]; + int spos = s_chan->spos; + int ret = ns_to, ns, d; + + spos += s_chan->iSBPos << 16; + + for (ns = 0; ns < ns_to; ns++) + { + spos += FModChangeFrequency(s_chan->iRawPitch, ns, fmod_buf); + while (spos >= 28*0x10000) + { + d = skip_block(ch); + if (d && ns < ret) + ret = ns; + spos -= 28*0x10000; + } + } + + s_chan->iSBPos = spos >> 16; + s_chan->spos = spos & 0xffff; + + return ret; +} + +static void do_lsfr_samples(int *dst, int ns_to, int ctrl, unsigned int *dwNoiseCount, unsigned int *dwNoiseVal) { unsigned int counter = *dwNoiseCount; @@ -703,20 +705,20 @@ static void do_lsfr_samples(int ns_to, int ctrl, val = (val << 1) | bit; } - ChanBuf[ns] = (signed short)val; + dst[ns] = (signed short)val; } *dwNoiseCount = counter; *dwNoiseVal = val; } -static int do_samples_noise(int ch, int ns_to) +static int do_samples_noise(int *dst, int ch, int ns_to) { int ret; ret = do_samples_skip(ch, ns_to); - do_lsfr_samples(ns_to, spu.spuCtrl, &spu.dwNoiseCount, &spu.dwNoiseVal); + do_lsfr_samples(dst, ns_to, spu.spuCtrl, &spu.dwNoiseCount, &spu.dwNoiseVal); return ret; } @@ -825,8 +827,15 @@ static void do_channels(int ns_to) unsigned int mask; int do_rvb, ch, d; SPUCHAN *s_chan; - s16 *SB; - int sinc; + + if (unlikely(spu.interpolation != spu_config.iUseInterpolation)) + { + spu.interpolation = spu_config.iUseInterpolation; + mask = spu.dwChannelsAudible & 0xffffff; + for (ch = 0; mask != 0; ch++, mask >>= 1) + if (mask & 1) + ResetInterpolation(&spu.sb[ch]); + } do_rvb = spu.rvb->StartAddr && spu_config.iUseReverb; if (do_rvb) @@ -844,24 +853,11 @@ static void do_channels(int ns_to) if (!(mask & 1)) continue; // channel not playing? next s_chan = &spu.s_chan[ch]; - SB = spu.SB + ch * SB_SIZE; - sinc = s_chan->sinc; - //if (spu.s_chan[ch].bNewPitch) - // SB[32] = 1; // reset interpolation - //spu.s_chan[ch].bNewPitch = 0; - if (s_chan->bNoise) - d = do_samples_noise(ch, ns_to); - else if (s_chan->bFMod == 2 - || (s_chan->bFMod == 0 && spu_config.iUseInterpolation == 0)) - d = do_samples_noint(decode_block, NULL, ch, ns_to, - SB, sinc, &s_chan->spos, &s_chan->iSBPos); - else if (s_chan->bFMod == 0 && spu_config.iUseInterpolation == 1) - d = do_samples_simple(decode_block, NULL, ch, ns_to, - SB, sinc, &s_chan->spos, &s_chan->iSBPos); + d = do_samples_noise(ChanBuf, ch, ns_to); else - d = do_samples_default(decode_block, NULL, ch, ns_to, - SB, sinc, &s_chan->spos, &s_chan->iSBPos); + d = do_samples_adpcm(ChanBuf, decode_block, NULL, ch, ns_to, s_chan->bFMod, + &spu.sb[ch], s_chan->sinc, &s_chan->spos, &s_chan->iSBPos); if (!s_chan->bStarting) { d = MixADSR(&s_chan->ADSRX, d); @@ -911,7 +907,7 @@ static void do_samples_finish(int *SSumLR, int ns_to, // here is the main job handler... //////////////////////////////////////////////////////////////////////// -void do_samples(unsigned int cycles_to, int do_direct) +void do_samples(unsigned int cycles_to, int force_no_thread) { unsigned int silentch; int cycle_diff; @@ -927,7 +923,7 @@ void do_samples(unsigned int cycles_to, int do_direct) silentch = ~(spu.dwChannelsAudible | spu.dwNewChannel) & 0xffffff; - do_direct |= (silentch == 0xffffff); + force_no_thread |= (silentch == 0xffffff); if (cycle_diff < 4 * 768) { @@ -1018,8 +1014,8 @@ static void do_samples_finish(int *SSumLR, int ns_to, spu.decode_dirty_ch &= ~(1<<3); } - vol_l = vol_l * spu_config.iVolume >> 10; - vol_r = vol_r * spu_config.iVolume >> 10; + //vol_l = vol_l * spu_config.iVolume >> 10; + //vol_r = vol_r * spu_config.iVolume >> 10; if (!(vol_l | vol_r)) { @@ -1095,7 +1091,6 @@ void CALLBACK DF_SPUasync(unsigned int cycle, unsigned int flags, unsigned int p schedule_next_irq(); if (flags & 1) { - //lastBytes = out_current->feed(spu.pSpuBuffer, (unsigned char *)spu.pS - spu.pSpuBuffer); out_current->feed(spu.pSpuBuffer, (unsigned char *)spu.pS - spu.pSpuBuffer); spu.pS = (short *)spu.pSpuBuffer; @@ -1103,11 +1098,7 @@ void CALLBACK DF_SPUasync(unsigned int cycle, unsigned int flags, unsigned int p if (!out_current->busy()) { // cause more samples to be generated // (and break some games because of bad sync) - //if (psxType) { - // spu.cycles_played -= PS_SPU_FREQ / 50 / 2 * 768; // Config.PsxType = 1, PAL 50Fps/1s - //} else { spu.cycles_played -= PS_SPU_FREQ / 60 / 2 * 768; // Config.PsxType = 0, PAL 60Fps/1s - //} } } } @@ -1174,10 +1165,8 @@ void ClearWorkingState(void) spu.pS=(short *)spu.pSpuBuffer; // setup soundbuffer pointer } -//extern char spuMemC[512 * 1024]; extern char s_chan[(MAXCHAN + 1) * sizeof(spu.s_chan[0])]; extern char rvb[sizeof(REVERBInfo)]; -extern char SB[MAXCHAN * sizeof(spu.SB[0]) * SB_SIZE]; extern char pSpuBuffer[WII_SPU_FREQ]; extern char SSumLR[NSSIZE * 2 * sizeof(spu.SSumLR[0])]; @@ -1244,22 +1233,17 @@ long DF_SPUinit(void) spu_config.iUseReverb = 1; spu_config.idiablofix = 0; - spu_config.iUseInterpolation = 1; + //spu_config.iUseInterpolation = 2; spu_config.iXAPitch = 0; - spu_config.iVolume = 768; + spu_config.iVolume = 1024; spu_config.iTempo = 0; spu_config.iUseThread = 0; // no effect if only 1 core is detected - //spu.spuMemC = calloc(1, 512 * 1024); spu.spuMemC = (unsigned char *)SPU_BUF_LO; InitADSR(); - // spu.s_chan = calloc(MAXCHAN+1, sizeof(spu.s_chan[0])); // channel + 1 infos (1 is security for fmod handling) - // spu.rvb = calloc(1, sizeof(REVERBInfo)); - // spu.SB = calloc(MAXCHAN, sizeof(spu.SB[0]) * SB_SIZE); spu.s_chan = (SPUCHAN *)s_chan; spu.rvb = (REVERBInfo *)rvb; - spu.SB = (s16 *)SB; spu.spuAddr = 0; spu.decode_pos = 0; @@ -1268,7 +1252,7 @@ long DF_SPUinit(void) SetupStreams(); // prepare streaming if (spu_config.iVolume == 0) - spu_config.iVolume = 768; // 1024 is 1.0 + spu_config.iVolume = 1024; // 1024 is 1.0 for (i = 0; i < MAXCHAN; i++) // loop sound channels { diff --git a/dfsound/externals.h b/dfsound/externals.h index c2ad6a37..ab1ddd19 100644 --- a/dfsound/externals.h +++ b/dfsound/externals.h @@ -88,18 +88,7 @@ typedef struct int EnvelopeVol; int EnvelopeCounter; } ADSRInfoEx; - -/////////////////////////////////////////////////////////// - -// Tmp Flags - -// used for debug channel muting -#define FLAG_MUTE 1 - -// used for simple interpolation -#define FLAG_IPOL0 2 -#define FLAG_IPOL1 4 - + /////////////////////////////////////////////////////////// // MAIN CHANNEL STRUCT @@ -185,8 +174,21 @@ typedef struct // psx buffers / addresses -#define SB_SIZE (32 + 4) -#define NUM_SPU_BUFFERS 4 +typedef union +{ + s16 SB[28 + 4 + 4]; + struct { + s16 sample[28]; + union { + struct { + s16 pos; + s16 val[4]; + } gauss; + s16 simple[5]; // 28-32 + } interp; + int sinc_old; + }; +} sample_buf; typedef struct { @@ -251,10 +253,9 @@ typedef struct unsigned int * CDDAStart; unsigned int * CDDAEnd; - // buffers - s16 * SB; - unsigned short regArea[0x400]; + + sample_buf sb[MAXCHAN]; int interpolation; } SPUInfo; diff --git a/dfsound/freeze.c b/dfsound/freeze.c index efc7e839..853fb68d 100644 --- a/dfsound/freeze.c +++ b/dfsound/freeze.c @@ -15,6 +15,7 @@ * * ***************************************************************************/ +#include #include "stdafx.h" #define _IN_FREEZE @@ -156,7 +157,8 @@ static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch) d->iSBPos = s->iSBPos; d->spos = s->spos; d->sinc = s->sinc; - memcpy(d->SB, spu.SB + ch * SB_SIZE, sizeof(d->SB[0]) * SB_SIZE); + assert(sizeof(d->SB) >= sizeof(spu.sb[ch])); + memcpy(d->SB, &spu.sb[ch], sizeof(spu.sb[ch])); d->iStart = (regAreaGetCh(ch, 6) & ~1) << 3; d->iCurr = 0; // set by the caller d->iLoop = 0; // set by the caller @@ -170,8 +172,8 @@ static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch) d->bIgnoreLoop = (s->prevflags ^ 2) << 1; d->iRightVolume = s->iRightVolume; d->iRawPitch = s->iRawPitch; - d->s_1 = spu.SB[ch * SB_SIZE + 27]; // yes it's reversed - d->s_2 = spu.SB[ch * SB_SIZE + 26]; + d->s_1 = spu.sb[ch].SB[27]; // yes it's reversed + d->s_2 = spu.sb[ch].SB[26]; d->lastF0F1[0] = s->lastF0F1[0]; d->lastF0F1[1] = s->lastF0F1[1]; d->bRVBActive = s->bRVBActive; @@ -201,15 +203,15 @@ static void load_channel(SPUCHAN *d, const SPUCHAN_orig *s, int ch) d->spos = s->spos; d->sinc = s->sinc; d->sinc_inv = 0; - memcpy(spu.SB + ch * SB_SIZE, s->SB, sizeof(spu.SB[0]) * SB_SIZE); + memcpy(&spu.sb[ch], s->SB, sizeof(spu.sb[ch])); d->pCurr = (void *)((long)s->iCurr & 0x7fff0); d->pLoop = (void *)((long)s->iLoop & 0x7fff0); d->bReverb = s->bReverb; d->iLeftVolume = s->iLeftVolume; d->iRightVolume = s->iRightVolume; d->iRawPitch = s->iRawPitch; - spu.SB[ch * SB_SIZE + 27] = s->s_1; - spu.SB[ch * SB_SIZE + 26] = s->s_2; + spu.sb[ch].SB[27] = s->s_1; + spu.sb[ch].SB[26] = s->s_2; d->lastF0F1[0] = s->lastF0F1[0]; d->lastF0F1[1] = s->lastF0F1[1]; d->bRVBActive = s->bRVBActive; diff --git a/dfsound/sdl.c b/dfsound/sdl.c index 12aa7e31..ab46a9b4 100644 --- a/dfsound/sdl.c +++ b/dfsound/sdl.c @@ -62,9 +62,8 @@ static void SOUND_FillAudio(void *unused, Uint8 *stream, int len) { sposTmp -= 0x10000L; } - // Because it is in BIG_ENDIAN format, it is necessary to swap the left and right audio channels. - *p++ = lastSampleR; *p++ = lastSampleL; + *p++ = lastSampleR; sposTmp += SINC; --len; } diff --git a/dfsound/spu_config.h b/dfsound/spu_config.h index 44faefd0..8406eb6d 100644 --- a/dfsound/spu_config.h +++ b/dfsound/spu_config.h @@ -12,7 +12,6 @@ typedef struct int iTempo; int idiablofix; int iUseThread; - //int iUseFixedUpdates; // output fixed number of samples/frame // status int iThreadAvail; diff --git a/dfsound/xa.c b/dfsound/xa.c index 149740fe..ed369079 100644 --- a/dfsound/xa.c +++ b/dfsound/xa.c @@ -313,7 +313,7 @@ void FeedXA(const xa_decode_t *xap) { for(i=0;i=0x10000L) { @@ -335,7 +335,7 @@ void FeedXA(const xa_decode_t *xap) vr+=(gauss[vl+3]*gvalr(3)) >> 15; l |= vr << 16; } - else*/ + else { while(spos>=0x10000L) { @@ -412,7 +412,7 @@ void FeedXA(const xa_decode_t *xap) { for(i=0;i=0x10000L) { @@ -427,7 +427,7 @@ void FeedXA(const xa_decode_t *xap) vr+=(gauss[vl+3]*gvall(3)) >> 15; l=s= vr; } - else*/ + else { while(spos>=0x10000L) { diff --git a/lang/de.lang b/lang/de.lang index 68a046a3..2be0fad9 100644 --- a/lang/de.lang +++ b/lang/de.lang @@ -570,3 +570,7 @@ msgstr "FastLoad" msgid "Because the language has changed, please restart" msgstr "Da die Sprache geändert wurde, bitte neu starten" + +msgid "Simple" +msgstr "Einfach" + diff --git a/lang/es.lang b/lang/es.lang index a80ccbdc..79832e87 100644 --- a/lang/es.lang +++ b/lang/es.lang @@ -571,3 +571,6 @@ msgstr "Carga rápida" msgid "Because the language has changed, please restart" msgstr "Idioma ha sido cambiado, por favor reinicia" + +msgid "Interpolation" +msgstr "Interpolación" diff --git a/lang/it.lang b/lang/it.lang index 29bff95e..17791bc3 100644 --- a/lang/it.lang +++ b/lang/it.lang @@ -574,3 +574,9 @@ msgstr "Carico veloce" msgid "Because the language has changed, please restart" msgstr "Poiché la lingua è cambiata, riavviare" + +msgid "Interpolation" +msgstr "Interpolazione" + +msgid "Simple" +msgstr "Semplice" diff --git a/lang/kr.lang b/lang/kr.lang index 6116eaab..917e739a 100644 --- a/lang/kr.lang +++ b/lang/kr.lang @@ -597,7 +597,7 @@ msgid "Pte" msgstr "포르투갈어" msgid "It" -msgstr "이탈리아어" +msgstr "이탈리아어" msgid "Select language" msgstr "언어 선택" @@ -613,3 +613,12 @@ msgstr "별도 저장" msgid "Unable to read different versions of Save State" msgstr "다른 버전의 저장 상태를 읽을 수 없습니다." + +msgid "Interpolation" +msgstr "인터폴레이션" + +msgid "Simple" +msgstr "심플" + +msgid "Gaussi" +msgstr "가우시안" diff --git a/lang/pt.lang b/lang/pt.lang index 5bef8ed7..2ee21704 100644 --- a/lang/pt.lang +++ b/lang/pt.lang @@ -571,3 +571,6 @@ msgstr "Carga Rápida" msgid "Because the language has changed, please restart" msgstr "Idioma alterado, por favor reinicie" + +msgid "Interpolation" +msgstr "Interpolação" diff --git a/lang/zh.lang b/lang/zh.lang index 4c744f85..f4afd3c4 100644 --- a/lang/zh.lang +++ b/lang/zh.lang @@ -580,3 +580,12 @@ msgstr "单独保存" msgid "Unable to read different versions of Save State" msgstr "无法读取不同版本的即时存档" + +msgid "Interpolation" +msgstr "音频插值" + +msgid "Simple" +msgstr "简单插值" + +msgid "Gaussi" +msgstr "高斯插值" diff --git a/spu.c b/spu.c index 0ab4fbb9..f5fd7e03 100644 --- a/spu.c +++ b/spu.c @@ -23,11 +23,10 @@ #include "spu.h" #include "dfsound/externals.h" +#include "dfsound/spu_config.h" -//char spuMemC[512 * 1024] __attribute__((aligned(32))); char s_chan[(MAXCHAN + 1) * sizeof(spu.s_chan[0])] __attribute__((aligned(32))); char rvb[sizeof(REVERBInfo)] __attribute__((aligned(32))); -char SB[MAXCHAN * sizeof(spu.SB[0]) * SB_SIZE] __attribute__((aligned(32))); char pSpuBuffer[WII_SPU_FREQ] __attribute__((aligned(32))); char SSumLR[NSSIZE * 2 * sizeof(spu.SSumLR[0])] __attribute__((aligned(32))); @@ -57,3 +56,8 @@ void CALLBACK SPUschedule(unsigned int cycles_after) { void spuUpdate() { SPU_async(psxRegs.cycle, 0, Config.PsxType); } + +void setSpuInterpolation(int spuInterpolation) +{ + spu_config.iUseInterpolation = spuInterpolation; +}