return 0;
}
-static const char *men_spu_reverb[] = { "Off", "Fake", "On", NULL };
static const char *men_spu_interp[] = { "None", "Simple", "Gaussian", "Cubic", NULL };
static const char h_spu_irq_wait[] = "Wait for CPU (recommended set to ON)";
static const char h_spu_thread[] = "Run sound emulation in main thread (recommended)";
static menu_entry e_menu_plugin_spu[] =
{
- mee_enum ("Reverb", 0, iUseReverb, men_spu_reverb),
+ mee_onoff ("Reverb", 0, iUseReverb, 2),
mee_enum ("Interpolation", 0, iUseInterpolation, men_spu_interp),
mee_onoff ("Adjust XA pitch", 0, iXAPitch, 1),
mee_onoff_h ("SPU IRQ Wait", 0, iSPUIRQWait, 1, h_spu_irq_wait),
\r
// ~ 1 ms of data\r
// note: must be even due to the way reverb works now\r
-#define NSSIZE 46\r
+#define FRAG_MSECS 2\r
+#define NSSIZE ((44100 * FRAG_MSECS / 1000 + 1) & ~1)\r
\r
///////////////////////////////////////////////////////////\r
// struct defines\r
int iUsedFreq; // current pc pitch\r
int iLeftVolume; // left volume\r
int iRightVolume; // right volume\r
- int s_1; // last decoding infos\r
- int s_2;\r
ADSRInfoEx ADSRX;\r
int iRawPitch; // raw pitch (0...3fff)\r
\r
- int iRVBOffset; // reverb offset\r
- int iRVBRepeat; // reverb repeat\r
- int iRVBNum; // another reverb helper\r
- int iOldNoise; // old noise val for this channel \r
-\r
- int SB[32+32];\r
+ int SB[32+4];\r
} SPUCHAN;\r
\r
///////////////////////////////////////////////////////////\r
\r
// we want to retain compatibility between versions,\r
// so use original channel struct\r
-static void save_channel(SPUCHAN_orig *d, SPUCHAN *s, int ch)\r
+static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch)\r
{\r
memset(d, 0, sizeof(*d));\r
d->bNew = !!(dwNewChannel & (1<<ch));\r
d->bIgnoreLoop = s->bIgnoreLoop;\r
d->iRightVolume = s->iRightVolume;\r
d->iRawPitch = s->iRawPitch;\r
- d->s_1 = s->s_1;\r
- d->s_2 = s->s_2;\r
+ d->s_1 = s->SB[27]; // yes it's reversed\r
+ d->s_2 = s->SB[26];\r
d->bRVBActive = s->bRVBActive;\r
- d->iRVBOffset = s->iRVBOffset;\r
- d->iRVBRepeat = s->iRVBRepeat;\r
d->bNoise = s->bNoise;\r
d->bFMod = s->bFMod;\r
- d->iRVBNum = s->iRVBNum;\r
- d->iOldNoise = s->iOldNoise;\r
d->ADSRX.State = s->ADSRX.State;\r
d->ADSRX.AttackModeExp = s->ADSRX.AttackModeExp;\r
d->ADSRX.AttackRate = s->ADSRX.AttackRate;\r
d->ADSRX.lVolume = d->bOn; // hmh\r
}\r
\r
-static void load_channel(SPUCHAN *d, SPUCHAN_orig *s, int ch)\r
+static void load_channel(SPUCHAN *d, const SPUCHAN_orig *s, int ch)\r
{\r
memset(d, 0, sizeof(*d));\r
if (s->bNew) dwNewChannel |= 1<<ch;\r
d->bIgnoreLoop = s->bIgnoreLoop;\r
d->iRightVolume = s->iRightVolume;\r
d->iRawPitch = s->iRawPitch;\r
- d->s_1 = s->s_1;\r
- d->s_2 = s->s_2;\r
d->bRVBActive = s->bRVBActive;\r
- d->iRVBOffset = s->iRVBOffset;\r
- d->iRVBRepeat = s->iRVBRepeat;\r
d->bNoise = s->bNoise;\r
d->bFMod = s->bFMod;\r
- d->iRVBNum = s->iRVBNum;\r
- d->iOldNoise = s->iOldNoise;\r
d->ADSRX.State = s->ADSRX.State;\r
d->ADSRX.AttackModeExp = s->ADSRX.AttackModeExp;\r
d->ADSRX.AttackRate = s->ADSRX.AttackRate;\r
//s_chan[ch].bStop=0;
//s_chan[ch].bOn=1;
- s_chan[ch].s_1=0; // init mixing vars
- s_chan[ch].s_2=0;
+ s_chan[ch].SB[26]=0; // init mixing vars
+ s_chan[ch].SB[27]=0;
s_chan[ch].iSBPos=28;
s_chan[ch].SB[29]=0; // init our interpolation helpers
s_chan[ch].SB[29]=fa;
else
{
- if((spuCtrl&0x4000)==0) fa=0; // muted?
- else // else adjust
- {
- if(fa>32767L) fa=32767L;
- if(fa<-32767L) fa=-32767L;
- }
+ ssat32_to_16(fa);
if(iUseInterpolation>=2) // gauss/cubic interpolation
{
}
}
+static void decode_block_data(int *dest, const unsigned char *src, int predict_nr, int shift_factor)
+{
+ int nSample;
+ int fa, s_1, s_2, d, s;
+
+ s_1 = dest[27];
+ s_2 = dest[26];
+
+ for (nSample = 0; nSample < 28; src++)
+ {
+ d = (int)*src;
+ s = (int)(signed short)((d & 0x0f) << 12);
+
+ fa = s >> shift_factor;
+ fa += ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
+ s_2=s_1;s_1=fa;
+
+ dest[nSample++] = fa;
+
+ s = (int)(signed short)((d & 0xf0) << 8);
+ fa = s >> shift_factor;
+ fa += ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
+ s_2=s_1;s_1=fa;
+
+ dest[nSample++] = fa;
+ }
+}
+
static int decode_block(int ch)
{
unsigned char *start;
- unsigned int nSample;
- int predict_nr,shift_factor,flags,d,s;
- int fa,s_1,s_2;
+ int predict_nr,shift_factor,flags;
int ret = 0;
- s_chan[ch].iSBPos=0;
-
start=s_chan[ch].pCurr; // set up the current pos
if(start == (unsigned char*)-1 || // special "stop" sign
(dwPendingChanOff&(1<<ch)))
}
}
- s_1=s_chan[ch].s_1;
- s_2=s_chan[ch].s_2;
-
- predict_nr=(int)*start;start++;
+ predict_nr=(int)start[0];
shift_factor=predict_nr&0xf;
predict_nr >>= 4;
- flags=(int)*start;start++;
-
- // -------------------------------------- //
-
- for (nSample=0;nSample<28;start++)
- {
- d=(int)*start;
- s=((d&0xf)<<12);
- if(s&0x8000) s|=0xffff0000;
- fa=(s >> shift_factor);
- fa=fa + ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
- s_2=s_1;s_1=fa;
- s=((d & 0xf0) << 8);
-
- s_chan[ch].SB[nSample++]=fa;
-
- if(s&0x8000) s|=0xffff0000;
- fa=(s>>shift_factor);
- fa=fa + ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
- s_2=s_1;s_1=fa;
-
- s_chan[ch].SB[nSample++]=fa;
- }
+ decode_block_data(s_chan[ch].SB, start + 2, predict_nr, shift_factor);
//////////////////////////////////////////// flag handler
- if((flags&4) && (!s_chan[ch].bIgnoreLoop))
- s_chan[ch].pLoop=start-16; // loop adress
+ flags=(int)start[1];
+ if(flags&4)
+ s_chan[ch].pLoop=start; // loop adress
+ start+=16;
if(flags&1) // 1: stop/loop
{
if(!(flags&2))
if (start - spuMemC >= 0x80000)
start = (unsigned char*)-1;
- s_chan[ch].pCurr=start; // store values for next cycle
- s_chan[ch].s_1=s_1;
- s_chan[ch].s_2=s_2;
+ s_chan[ch].pCurr = start; // store values for next cycle
return ret;
}
ret = 1;
}
- if((flags & 4) && !s_chan[ch].bIgnoreLoop)
+ if(flags & 4)
s_chan[ch].pLoop=start;
s_chan[ch].pCurr += 16;
{ \
int sinc = s_chan[ch].sinc; \
int spos = s_chan[ch].spos; \
+ int sbpos = s_chan[ch].iSBPos; \
+ int *SB = s_chan[ch].SB; \
int ret = -1; \
int d, fa; \
interp_start; \
\
while (spos >= 0x10000) \
{ \
- if(s_chan[ch].iSBPos == 28) \
+ if(sbpos == 28) \
{ \
+ sbpos = 0; \
d = decode_block(ch); \
if(d && iSPUIRQWait) \
{ \
} \
} \
\
- fa = s_chan[ch].SB[s_chan[ch].iSBPos++]; \
+ fa = SB[sbpos++]; \
interp1_code; \
spos -= 0x10000; \
} \
out: \
s_chan[ch].sinc = sinc; \
s_chan[ch].spos = spos; \
+ s_chan[ch].iSBPos = sbpos; \
interp_end; \
\
return ret; \
// feed the sound
// wanna have around 1/60 sec (16.666 ms) updates
- if (iCycle++ > 16)
+ if (iCycle++ > 16/FRAG_MSECS)
{
SoundFeedStreamData((unsigned char *)pSpuBuffer,
((unsigned char *)pS) - ((unsigned char *)pSpuBuffer));
if(iSpuAsyncWait)
{
iSpuAsyncWait++;
- if(iSpuAsyncWait<=16) return;
+ if(iSpuAsyncWait<=16/FRAG_MSECS) return;
iSpuAsyncWait=0;
}
{
l=*CDDAPlay++;
if(CDDAPlay==CDDAEnd) CDDAPlay=CDDAStart;
- SSumLR[ns++]+=(((short)(l&0xffff)) * iLeftXAVol)/32767;
- SSumLR[ns++]+=(((short)((l>>16)&0xffff)) * iRightXAVol)/32767;
+ SSumLR[ns++]+=(((short)(l&0xffff)) * iLeftXAVol) >> 15;
+ SSumLR[ns++]+=(((short)((l>>16)&0xffff)) * iRightXAVol) >> 15;
}
}
s=(short)LOWORD(l);
l1=s;
l1=(l1*iPlace)/iSize;
- if(l1<-32767) l1=-32767;
- if(l1> 32767) l1=32767;
+ ssat32_to_16(l1);
s=(short)HIWORD(l);
l2=s;
l2=(l2*iPlace)/iSize;
- if(l2<-32767) l2=-32767;
- if(l2> 32767) l2=32767;
+ ssat32_to_16(l2);
l=(l1&0xffff)|(l2<<16);
*XAFeed++=l;
}
l1=(l1*iPlace)/iSize;
- if(l1<-32767) l1=-32767;
- if(l1> 32767) l1=32767;
+ ssat32_to_16(l1);
l=(l1&0xffff)|(l1<<16);
*XAFeed++=l;