1 /***************************************************************************
4 begin : Wed May 15 2002
5 copyright : (C) 2002 by Pete Bernert
6 email : BlackDove@addcom.de
7 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. See also the license.txt file for *
14 * additional informations. *
16 ***************************************************************************/
22 // will be included from spu.c
25 ////////////////////////////////////////////////////////////////////////
27 ////////////////////////////////////////////////////////////////////////
29 static int gauss_ptr = 0;
30 static int gauss_window[8] = {0, 0, 0, 0, 0, 0, 0, 0};
32 #define gvall0 gauss_window[gauss_ptr]
33 #define gvall(x) gauss_window[(gauss_ptr+x)&3]
34 #define gvalr0 gauss_window[4+gauss_ptr]
35 #define gvalr(x) gauss_window[4+((gauss_ptr+x)&3)]
37 ////////////////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////////////////
41 INLINE void MixXA(int *SSumLR, int ns_to, int decode_pos)
43 int cursor = decode_pos;
46 uint32_t v = spu.XALastVal;
48 if(spu.XAPlay != spu.XAFeed || spu.XARepeat > 0)
50 if(spu.XAPlay == spu.XAFeed)
53 for(ns = 0; ns < ns_to*2; )
55 if(spu.XAPlay != spu.XAFeed) v=*spu.XAPlay++;
56 if(spu.XAPlay == spu.XAEnd) spu.XAPlay=spu.XAStart;
58 l = ((int)(short)v * spu.iLeftXAVol) >> 15;
59 r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15;
63 spu.spuMem[cursor] = v;
64 spu.spuMem[cursor + 0x400/2] = v >> 16;
65 cursor = (cursor + 1) & 0x1ff;
69 // occasionally CDDAFeed underflows by a few samples due to poor timing,
70 // hence this 'ns_to < 8'
71 else if(spu.CDDAPlay != spu.CDDAFeed || ns_to < 8)
73 for(ns = 0; ns < ns_to*2; )
75 if(spu.CDDAPlay != spu.CDDAFeed) v=*spu.CDDAPlay++;
76 if(spu.CDDAPlay == spu.CDDAEnd) spu.CDDAPlay=spu.CDDAStart;
78 l = ((int)(short)v * spu.iLeftXAVol) >> 15;
79 r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15;
83 spu.spuMem[cursor] = v;
84 spu.spuMem[cursor + 0x400/2] = v >> 16;
85 cursor = (cursor + 1) & 0x1ff;
93 ////////////////////////////////////////////////////////////////////////
94 // small linux time helper... only used for watchdog
95 ////////////////////////////////////////////////////////////////////////
97 static unsigned long timeGetTime_spu()
101 #elif defined(_WIN32)
102 return GetTickCount();
105 gettimeofday(&tv, 0); // well, maybe there are better ways
106 return tv.tv_sec * 1000 + tv.tv_usec/1000; // to do that, but at least it works
110 ////////////////////////////////////////////////////////////////////////
112 ////////////////////////////////////////////////////////////////////////
114 INLINE void FeedXA(xa_decode_t *xap)
116 int sinc,spos,i,iSize,iPlace,vl,vr;
118 if(!spu.bSPUIsOpen) return;
120 spu.xapGlobal = xap; // store info for save states
121 spu.XARepeat = 100; // set up repeat
124 iSize=((45500*xap->nsamples)/xap->freq); // get size
126 iSize=((44100*xap->nsamples)/xap->freq); // get size
128 if(!iSize) return; // none? bye
130 if(spu.XAFeed<spu.XAPlay) iPlace=spu.XAPlay-spu.XAFeed; // how much space in my buf?
131 else iPlace=(spu.XAEnd-spu.XAFeed) + (spu.XAPlay-spu.XAStart);
133 if(iPlace==0) return; // no place at all
135 //----------------------------------------------------//
136 if(spu_config.iXAPitch) // pitch change option?
139 static DWORD dwFPS=0;
140 static int iFPSCnt=0;
141 static int iLastSize=0;
143 DWORD dw=timeGetTime_spu(),dw1,dw2;
147 dwFPS+=dw-dwLT;iFPSCnt++;
155 if(dw1>=(dwL1-100) && dw1<=(dwL1+100)) dw1=dwL1;
157 dw2=(xap->freq*100/xap->nsamples);
158 if((!dw1)||((dw2+100)>=dw1)) iLastSize=0;
161 iLastSize=iSize*dw2/dw1;
162 if(iLastSize>iPlace) iLastSize=iPlace;
169 if(iLastSize) iSize=iLastSize;
172 //----------------------------------------------------//
175 sinc = (xap->nsamples << 16) / iSize; // calc freq by num / size
179 uint32_t * pS=(uint32_t *)xap->pcm;
182 if(spu_config.iXAPitch)
184 int32_t l1,l2;short s;
187 if(spu_config.iUseInterpolation==2)
189 while(spos>=0x10000L)
192 gauss_window[gauss_ptr] = (short)LOWORD(l);
193 gauss_window[4+gauss_ptr] = (short)HIWORD(l);
194 gauss_ptr = (gauss_ptr+1) & 3;
197 vl = (spos >> 6) & ~3;
198 vr=(gauss[vl]*gvall0) >> 15;
199 vr+=(gauss[vl+1]*gvall(1)) >> 15;
200 vr+=(gauss[vl+2]*gvall(2)) >> 15;
201 vr+=(gauss[vl+3]*gvall(3)) >> 15;
203 vr=(gauss[vl]*gvalr0) >> 15;
204 vr+=(gauss[vl+1]*gvalr(1)) >> 15;
205 vr+=(gauss[vl+2]*gvalr(2)) >> 15;
206 vr+=(gauss[vl+3]*gvalr(3)) >> 15;
211 while(spos>=0x10000L)
220 l1=(l1*iPlace)/iSize;
224 l2=(l2*iPlace)/iSize;
226 l=(l1&0xffff)|(l2<<16);
230 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
231 if(spu.XAFeed==spu.XAPlay)
233 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
244 if(spu_config.iUseInterpolation==2)
246 while(spos>=0x10000L)
249 gauss_window[gauss_ptr] = (short)LOWORD(l);
250 gauss_window[4+gauss_ptr] = (short)HIWORD(l);
251 gauss_ptr = (gauss_ptr+1) & 3;
254 vl = (spos >> 6) & ~3;
255 vr=(gauss[vl]*gvall0) >> 15;
256 vr+=(gauss[vl+1]*gvall(1)) >> 15;
257 vr+=(gauss[vl+2]*gvall(2)) >> 15;
258 vr+=(gauss[vl+3]*gvall(3)) >> 15;
260 vr=(gauss[vl]*gvalr0) >> 15;
261 vr+=(gauss[vl+1]*gvalr(1)) >> 15;
262 vr+=(gauss[vl+2]*gvalr(2)) >> 15;
263 vr+=(gauss[vl+3]*gvalr(3)) >> 15;
268 while(spos>=0x10000L)
277 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
278 if(spu.XAFeed==spu.XAPlay)
280 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
290 unsigned short * pS=(unsigned short *)xap->pcm;
291 uint32_t l;short s=0;
293 if(spu_config.iXAPitch)
298 if(spu_config.iUseInterpolation==2)
300 while(spos>=0x10000L)
302 gauss_window[gauss_ptr] = (short)*pS++;
303 gauss_ptr = (gauss_ptr+1) & 3;
306 vl = (spos >> 6) & ~3;
307 vr=(gauss[vl]*gvall0) >> 15;
308 vr+=(gauss[vl+1]*gvall(1)) >> 15;
309 vr+=(gauss[vl+2]*gvall(2)) >> 15;
310 vr+=(gauss[vl+3]*gvall(3)) >> 15;
316 while(spos>=0x10000L)
324 l1=(l1*iPlace)/iSize;
326 l=(l1&0xffff)|(l1<<16);
329 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
330 if(spu.XAFeed==spu.XAPlay)
332 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
343 if(spu_config.iUseInterpolation==2)
345 while(spos>=0x10000L)
347 gauss_window[gauss_ptr] = (short)*pS++;
348 gauss_ptr = (gauss_ptr+1) & 3;
351 vl = (spos >> 6) & ~3;
352 vr=(gauss[vl]*gvall0) >> 15;
353 vr+=(gauss[vl+1]*gvall(1)) >> 15;
354 vr+=(gauss[vl+2]*gvall(2)) >> 15;
355 vr+=(gauss[vl+3]*gvall(3)) >> 15;
360 while(spos>=0x10000L)
369 *spu.XAFeed++=(l|(l<<16));
371 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
372 if(spu.XAFeed==spu.XAPlay)
374 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
384 ////////////////////////////////////////////////////////////////////////
386 ////////////////////////////////////////////////////////////////////////
388 INLINE int FeedCDDA(unsigned char *pcm, int nBytes)
391 space=(spu.CDDAPlay-spu.CDDAFeed-1)*4 & (CDDA_BUFFER_SIZE - 1);
393 return 0x7761; // rearmed_wait
397 if(spu.CDDAFeed==spu.CDDAEnd) spu.CDDAFeed=spu.CDDAStart;
398 space=(spu.CDDAPlay-spu.CDDAFeed-1)*4 & (CDDA_BUFFER_SIZE - 1);
399 if(spu.CDDAFeed+space/4>spu.CDDAEnd)
400 space=(spu.CDDAEnd-spu.CDDAFeed)*4;
404 memcpy(spu.CDDAFeed,pcm,space);
405 spu.CDDAFeed+=space/4;
410 return 0x676f; // rearmed_go