// will be included from spu.c
#ifdef _IN_SPU
+#define XA_HACK
+
////////////////////////////////////////////////////////////////////////
// XA GLOBALS
////////////////////////////////////////////////////////////////////////
int ns;
uint32_t l;
- for(ns=0;ns<NSSIZE && XAPlay!=XAFeed;ns++)
+ for(ns=0;ns<NSSIZE*2 && XAPlay!=XAFeed;)
{
XALastVal=*XAPlay++;
if(XAPlay==XAEnd) XAPlay=XAStart;
#ifdef XA_HACK
- SSumL[ns]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32768;
- SSumR[ns]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32768;
+ SSumLR[ns++]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32768;
+ SSumLR[ns++]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32768;
#else
- SSumL[ns]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32767;
- SSumR[ns]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32767;
+ SSumLR[ns++]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32767;
+ SSumLR[ns++]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32767;
#endif
}
if(XAPlay==XAFeed && XARepeat)
{
XARepeat--;
- for(;ns<NSSIZE;ns++)
+ for(;ns<NSSIZE*2;)
{
#ifdef XA_HACK
- SSumL[ns]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32768;
- SSumR[ns]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32768;
+ SSumLR[ns++]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32768;
+ SSumLR[ns++]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32768;
#else
- SSumL[ns]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32767;
- SSumR[ns]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32767;
+ SSumLR[ns++]+=(((short)(XALastVal&0xffff)) * iLeftXAVol)/32767;
+ SSumLR[ns++]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32767;
#endif
}
}
- for(ns=0;ns<NSSIZE && CDDAPlay!=CDDAFeed && (CDDAPlay!=CDDAEnd-1||CDDAFeed!=CDDAStart);ns++)
+ for(ns=0;ns<NSSIZE*2 && CDDAPlay!=CDDAFeed && (CDDAPlay!=CDDAEnd-1||CDDAFeed!=CDDAStart);)
{
l=*CDDAPlay++;
if(CDDAPlay==CDDAEnd) CDDAPlay=CDDAStart;
- SSumL[ns]+=(((short)(l&0xffff)) * iLeftXAVol)/32767;
- SSumR[ns]+=(((short)((l>>16)&0xffff)) * iRightXAVol)/32767;
+ SSumLR[ns++]+=(((short)(l&0xffff)) * iLeftXAVol) >> 15;
+ SSumLR[ns++]+=(((short)((l>>16)&0xffff)) * iRightXAVol) >> 15;
}
}
xapGlobal = xap; // store info for save states
XARepeat = 100; // set up repeat
-#ifdef XA_HACK
+#if 0//def XA_HACK
iSize=((45500*xap->nsamples)/xap->freq); // get size
#else
iSize=((44100*xap->nsamples)/xap->freq); // get size
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;
vr+=(gauss[vl+2]*gvall(2))&~2047;
vr+=(gauss[vl+3]*gvall(3))&~2047;
l=s= vr >> 11;
- l &= 0xffff;
}
else
{
l=s;
}
+ l &= 0xffff;
*XAFeed++=(l|(l<<16));
if(XAFeed==XAEnd) XAFeed=XAStart;
// FEED CDDA
////////////////////////////////////////////////////////////////////////
-INLINE void FeedCDDA(unsigned char *pcm, int nBytes)
+INLINE int FeedCDDA(unsigned char *pcm, int nBytes)
{
+ int space;
+ space=(CDDAPlay-CDDAFeed-1)*4 & (CDDA_BUFFER_SIZE - 1);
+ if(space<nBytes)
+ return 0x7761; // rearmed_wait
+
while(nBytes>0)
{
if(CDDAFeed==CDDAEnd) CDDAFeed=CDDAStart;
- while(CDDAFeed==CDDAPlay-1||
- (CDDAFeed==CDDAEnd-1&&CDDAPlay==CDDAStart))
- {
- if (!iUseTimer) usleep(1000);
- else return;
- }
- *CDDAFeed++=(*pcm | (*(pcm+1)<<8) | (*(pcm+2)<<16) | (*(pcm+3)<<24));
- nBytes-=4;
- pcm+=4;
+ space=(CDDAPlay-CDDAFeed-1)*4 & (CDDA_BUFFER_SIZE - 1);
+ if(CDDAFeed+space/4>CDDAEnd)
+ space=(CDDAEnd-CDDAFeed)*4;
+ if(space>nBytes)
+ space=nBytes;
+
+ memcpy(CDDAFeed,pcm,space);
+ CDDAFeed+=space/4;
+ nBytes-=space;
+ pcm+=space;
}
+
+ return 0x676f; // rearmed_go
}
#endif