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 ns_to)
46 int cursor = spu.decode_pos;
48 if(spu.XAPlay != spu.XAFeed || spu.XARepeat > 0)
50 if(spu.XAPlay == spu.XAFeed)
54 for(ns = 0; ns < ns_to*2; )
56 if(spu.XAPlay != spu.XAFeed) v=*spu.XAPlay++;
57 if(spu.XAPlay == spu.XAEnd) spu.XAPlay=spu.XAStart;
59 l = ((int)(short)v * spu.iLeftXAVol) >> 15;
60 r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15;
64 spu.spuMem[cursor] = v;
65 spu.spuMem[cursor + 0x400/2] = v >> 16;
66 cursor = (cursor + 1) & 0x1ff;
71 for(ns = 0; ns < ns_to * 2 && spu.CDDAPlay!=spu.CDDAFeed && (spu.CDDAPlay!=spu.CDDAEnd-1||spu.CDDAFeed!=spu.CDDAStart);)
74 if(spu.CDDAPlay==spu.CDDAEnd) spu.CDDAPlay=spu.CDDAStart;
76 l = ((int)(short)v * spu.iLeftXAVol) >> 15;
77 r = ((int)(short)(v >> 16) * spu.iLeftXAVol) >> 15;
81 spu.spuMem[cursor] = v;
82 spu.spuMem[cursor + 0x400/2] = v >> 16;
83 cursor = (cursor + 1) & 0x1ff;
87 ////////////////////////////////////////////////////////////////////////
88 // small linux time helper... only used for watchdog
89 ////////////////////////////////////////////////////////////////////////
91 static unsigned long timeGetTime_spu()
94 gettimeofday(&tv, 0); // well, maybe there are better ways
95 return tv.tv_sec * 1000 + tv.tv_usec/1000; // to do that, but at least it works
98 ////////////////////////////////////////////////////////////////////////
100 ////////////////////////////////////////////////////////////////////////
102 INLINE void FeedXA(xa_decode_t *xap)
104 int sinc,spos,i,iSize,iPlace,vl,vr;
106 if(!spu.bSPUIsOpen) return;
108 spu.xapGlobal = xap; // store info for save states
109 spu.XARepeat = 100; // set up repeat
112 iSize=((45500*xap->nsamples)/xap->freq); // get size
114 iSize=((44100*xap->nsamples)/xap->freq); // get size
116 if(!iSize) return; // none? bye
118 if(spu.XAFeed<spu.XAPlay) iPlace=spu.XAPlay-spu.XAFeed; // how much space in my buf?
119 else iPlace=(spu.XAEnd-spu.XAFeed) + (spu.XAPlay-spu.XAStart);
121 if(iPlace==0) return; // no place at all
123 //----------------------------------------------------//
124 if(spu_config.iXAPitch) // pitch change option?
127 static DWORD dwFPS=0;
128 static int iFPSCnt=0;
129 static int iLastSize=0;
131 DWORD dw=timeGetTime_spu(),dw1,dw2;
135 dwFPS+=dw-dwLT;iFPSCnt++;
143 if(dw1>=(dwL1-100) && dw1<=(dwL1+100)) dw1=dwL1;
145 dw2=(xap->freq*100/xap->nsamples);
146 if((!dw1)||((dw2+100)>=dw1)) iLastSize=0;
149 iLastSize=iSize*dw2/dw1;
150 if(iLastSize>iPlace) iLastSize=iPlace;
157 if(iLastSize) iSize=iLastSize;
160 //----------------------------------------------------//
163 sinc = (xap->nsamples << 16) / iSize; // calc freq by num / size
167 uint32_t * pS=(uint32_t *)xap->pcm;
170 if(spu_config.iXAPitch)
172 int32_t l1,l2;short s;
175 if(spu_config.iUseInterpolation==2)
177 while(spos>=0x10000L)
180 gauss_window[gauss_ptr] = (short)LOWORD(l);
181 gauss_window[4+gauss_ptr] = (short)HIWORD(l);
182 gauss_ptr = (gauss_ptr+1) & 3;
185 vl = (spos >> 6) & ~3;
186 vr=(gauss[vl]*gvall0)&~2047;
187 vr+=(gauss[vl+1]*gvall(1))&~2047;
188 vr+=(gauss[vl+2]*gvall(2))&~2047;
189 vr+=(gauss[vl+3]*gvall(3))&~2047;
190 l= (vr >> 11) & 0xffff;
191 vr=(gauss[vl]*gvalr0)&~2047;
192 vr+=(gauss[vl+1]*gvalr(1))&~2047;
193 vr+=(gauss[vl+2]*gvalr(2))&~2047;
194 vr+=(gauss[vl+3]*gvalr(3))&~2047;
199 while(spos>=0x10000L)
208 l1=(l1*iPlace)/iSize;
212 l2=(l2*iPlace)/iSize;
214 l=(l1&0xffff)|(l2<<16);
218 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
219 if(spu.XAFeed==spu.XAPlay)
221 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
232 if(spu_config.iUseInterpolation==2)
234 while(spos>=0x10000L)
237 gauss_window[gauss_ptr] = (short)LOWORD(l);
238 gauss_window[4+gauss_ptr] = (short)HIWORD(l);
239 gauss_ptr = (gauss_ptr+1) & 3;
242 vl = (spos >> 6) & ~3;
243 vr=(gauss[vl]*gvall0)&~2047;
244 vr+=(gauss[vl+1]*gvall(1))&~2047;
245 vr+=(gauss[vl+2]*gvall(2))&~2047;
246 vr+=(gauss[vl+3]*gvall(3))&~2047;
247 l= (vr >> 11) & 0xffff;
248 vr=(gauss[vl]*gvalr0)&~2047;
249 vr+=(gauss[vl+1]*gvalr(1))&~2047;
250 vr+=(gauss[vl+2]*gvalr(2))&~2047;
251 vr+=(gauss[vl+3]*gvalr(3))&~2047;
256 while(spos>=0x10000L)
265 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
266 if(spu.XAFeed==spu.XAPlay)
268 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
278 unsigned short * pS=(unsigned short *)xap->pcm;
279 uint32_t l;short s=0;
281 if(spu_config.iXAPitch)
286 if(spu_config.iUseInterpolation==2)
288 while(spos>=0x10000L)
290 gauss_window[gauss_ptr] = (short)*pS++;
291 gauss_ptr = (gauss_ptr+1) & 3;
294 vl = (spos >> 6) & ~3;
295 vr=(gauss[vl]*gvall0)&~2047;
296 vr+=(gauss[vl+1]*gvall(1))&~2047;
297 vr+=(gauss[vl+2]*gvall(2))&~2047;
298 vr+=(gauss[vl+3]*gvall(3))&~2047;
304 while(spos>=0x10000L)
312 l1=(l1*iPlace)/iSize;
314 l=(l1&0xffff)|(l1<<16);
317 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
318 if(spu.XAFeed==spu.XAPlay)
320 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
331 if(spu_config.iUseInterpolation==2)
333 while(spos>=0x10000L)
335 gauss_window[gauss_ptr] = (short)*pS++;
336 gauss_ptr = (gauss_ptr+1) & 3;
339 vl = (spos >> 6) & ~3;
340 vr=(gauss[vl]*gvall0)&~2047;
341 vr+=(gauss[vl+1]*gvall(1))&~2047;
342 vr+=(gauss[vl+2]*gvall(2))&~2047;
343 vr+=(gauss[vl+3]*gvall(3))&~2047;
348 while(spos>=0x10000L)
357 *spu.XAFeed++=(l|(l<<16));
359 if(spu.XAFeed==spu.XAEnd) spu.XAFeed=spu.XAStart;
360 if(spu.XAFeed==spu.XAPlay)
362 if(spu.XAPlay!=spu.XAStart) spu.XAFeed=spu.XAPlay-1;
372 ////////////////////////////////////////////////////////////////////////
374 ////////////////////////////////////////////////////////////////////////
376 INLINE int FeedCDDA(unsigned char *pcm, int nBytes)
379 space=(spu.CDDAPlay-spu.CDDAFeed-1)*4 & (CDDA_BUFFER_SIZE - 1);
381 return 0x7761; // rearmed_wait
385 if(spu.CDDAFeed==spu.CDDAEnd) spu.CDDAFeed=spu.CDDAStart;
386 space=(spu.CDDAPlay-spu.CDDAFeed-1)*4 & (CDDA_BUFFER_SIZE - 1);
387 if(spu.CDDAFeed+space/4>spu.CDDAEnd)
388 space=(spu.CDDAEnd-spu.CDDAFeed)*4;
392 memcpy(spu.CDDAFeed,pcm,space);
393 spu.CDDAFeed+=space/4;
398 return 0x676f; // rearmed_go