Commit | Line | Data |
---|---|---|
ef79bbde P |
1 | /*************************************************************************** |
2 | spu.c - description | |
3 | ------------------- | |
4 | begin : Wed May 15 2002 | |
5 | copyright : (C) 2002 by Pete Bernert | |
6 | email : BlackDove@addcom.de | |
07a6dd2c | 7 | |
8 | Portions (C) GraÅžvydas "notaz" Ignotas, 2010-2011 | |
9 | ||
ef79bbde P |
10 | ***************************************************************************/ |
11 | /*************************************************************************** | |
12 | * * | |
13 | * This program is free software; you can redistribute it and/or modify * | |
14 | * it under the terms of the GNU General Public License as published by * | |
15 | * the Free Software Foundation; either version 2 of the License, or * | |
16 | * (at your option) any later version. See also the license.txt file for * | |
17 | * additional informations. * | |
18 | * * | |
19 | ***************************************************************************/ | |
20 | ||
21 | #include "stdafx.h" | |
22 | ||
23 | #define _IN_SPU | |
24 | ||
25 | #include "externals.h" | |
3fc2a4c2 | 26 | #include "registers.h" |
ef79bbde | 27 | #include "dsoundoss.h" |
ef79bbde P |
28 | |
29 | #ifdef ENABLE_NLS | |
30 | #include <libintl.h> | |
31 | #include <locale.h> | |
32 | #define _(x) gettext(x) | |
33 | #define N_(x) (x) | |
34 | #else | |
35 | #define _(x) (x) | |
36 | #define N_(x) (x) | |
37 | #endif | |
38 | ||
a80ae4a0 | 39 | #ifdef __ARM_ARCH_7A__ |
1775933a | 40 | #define ssat32_to_16(v) \ |
41 | asm("ssat %0,#16,%1" : "=r" (v) : "r" (v)) | |
42 | #else | |
43 | #define ssat32_to_16(v) do { \ | |
44 | if (v < -32768) v = -32768; \ | |
45 | else if (v > 32767) v = 32767; \ | |
46 | } while (0) | |
47 | #endif | |
48 | ||
6d866bb7 | 49 | /* |
ef79bbde P |
50 | #if defined (USEMACOSX) |
51 | static char * libraryName = N_("Mac OS X Sound"); | |
52 | #elif defined (USEALSA) | |
53 | static char * libraryName = N_("ALSA Sound"); | |
54 | #elif defined (USEOSS) | |
55 | static char * libraryName = N_("OSS Sound"); | |
56 | #elif defined (USESDL) | |
57 | static char * libraryName = N_("SDL Sound"); | |
58 | #elif defined (USEPULSEAUDIO) | |
59 | static char * libraryName = N_("PulseAudio Sound"); | |
60 | #else | |
61 | static char * libraryName = N_("NULL Sound"); | |
62 | #endif | |
63 | ||
64 | static char * libraryInfo = N_("P.E.Op.S. Sound Driver V1.7\nCoded by Pete Bernert and the P.E.Op.S. team\n"); | |
6d866bb7 | 65 | */ |
ef79bbde P |
66 | |
67 | // globals | |
68 | ||
69 | // psx buffer / addresses | |
70 | ||
71 | unsigned short regArea[10000]; | |
72 | unsigned short spuMem[256*1024]; | |
73 | unsigned char * spuMemC; | |
74 | unsigned char * pSpuIrq=0; | |
75 | unsigned char * pSpuBuffer; | |
76 | unsigned char * pMixIrq=0; | |
77 | ||
78 | // user settings | |
79 | ||
9e7a7352 | 80 | int iVolume=768; // 1024 is 1.0 |
ef79bbde | 81 | int iXAPitch=1; |
ef79bbde P |
82 | int iSPUIRQWait=1; |
83 | int iDebugMode=0; | |
84 | int iRecordMode=0; | |
85 | int iUseReverb=2; | |
86 | int iUseInterpolation=2; | |
ef79bbde P |
87 | |
88 | // MAIN infos struct for each channel | |
89 | ||
90 | SPUCHAN s_chan[MAXCHAN+1]; // channel + 1 infos (1 is security for fmod handling) | |
91 | REVERBInfo rvb; | |
92 | ||
b1094d0e | 93 | unsigned int dwNoiseVal; // global noise generator |
94 | unsigned int dwNoiseCount; | |
ef79bbde P |
95 | int iSpuAsyncWait=0; |
96 | ||
97 | unsigned short spuCtrl=0; // some vars to store psx reg infos | |
98 | unsigned short spuStat=0; | |
99 | unsigned short spuIrq=0; | |
100 | unsigned long spuAddr=0xffffffff; // address into spu mem | |
ef79bbde P |
101 | int bSpuInit=0; |
102 | int bSPUIsOpen=0; | |
103 | ||
174c454a | 104 | unsigned int dwNewChannel=0; // flags for faster testing, if new channel starts |
105 | unsigned int dwChannelOn=0; // not silent channels | |
106 | unsigned int dwPendingChanOff=0; | |
107 | unsigned int dwChannelDead=0; // silent+not useful channels | |
ef79bbde P |
108 | |
109 | void (CALLBACK *irqCallback)(void)=0; // func of main emu, called on spu irq | |
110 | void (CALLBACK *cddavCallback)(unsigned short,unsigned short)=0; | |
111 | ||
112 | // certain globals (were local before, but with the new timeproc I need em global) | |
113 | ||
6d866bb7 | 114 | static const int f[8][2] = { { 0, 0 }, |
ef79bbde P |
115 | { 60, 0 }, |
116 | { 115, -52 }, | |
117 | { 98, -55 }, | |
118 | { 122, -60 } }; | |
b17618c0 | 119 | int ChanBuf[NSSIZE+3]; |
120 | int SSumLR[(NSSIZE+3)*2]; | |
ef79bbde P |
121 | int iFMod[NSSIZE]; |
122 | int iCycle = 0; | |
123 | short * pS; | |
124 | ||
125 | int lastch=-1; // last channel processed on spu irq in timer mode | |
126 | static int lastns=0; // last ns pos | |
ef79bbde | 127 | |
983a7cfd | 128 | #define CDDA_BUFFER_SIZE (16384 * sizeof(uint32_t)) // must be power of 2 |
129 | ||
ef79bbde P |
130 | //////////////////////////////////////////////////////////////////////// |
131 | // CODE AREA | |
132 | //////////////////////////////////////////////////////////////////////// | |
133 | ||
134 | // dirty inline func includes | |
135 | ||
136 | #include "reverb.c" | |
137 | #include "adsr.c" | |
138 | ||
139 | //////////////////////////////////////////////////////////////////////// | |
140 | // helpers for simple interpolation | |
141 | ||
142 | // | |
143 | // easy interpolation on upsampling, no special filter, just "Pete's common sense" tm | |
144 | // | |
145 | // instead of having n equal sample values in a row like: | |
146 | // ____ | |
147 | // |____ | |
148 | // | |
149 | // we compare the current delta change with the next delta change. | |
150 | // | |
151 | // if curr_delta is positive, | |
152 | // | |
153 | // - and next delta is smaller (or changing direction): | |
154 | // \. | |
155 | // -__ | |
156 | // | |
157 | // - and next delta significant (at least twice) bigger: | |
158 | // --_ | |
159 | // \. | |
160 | // | |
161 | // - and next delta is nearly same: | |
162 | // \. | |
163 | // \. | |
164 | // | |
165 | // | |
166 | // if curr_delta is negative, | |
167 | // | |
168 | // - and next delta is smaller (or changing direction): | |
169 | // _-- | |
170 | // / | |
171 | // | |
172 | // - and next delta significant (at least twice) bigger: | |
173 | // / | |
174 | // __- | |
175 | // | |
176 | // - and next delta is nearly same: | |
177 | // / | |
178 | // / | |
179 | // | |
180 | ||
181 | ||
182 | INLINE void InterpolateUp(int ch) | |
183 | { | |
184 | if(s_chan[ch].SB[32]==1) // flag == 1? calc step and set flag... and don't change the value in this pass | |
185 | { | |
186 | const int id1=s_chan[ch].SB[30]-s_chan[ch].SB[29]; // curr delta to next val | |
187 | const int id2=s_chan[ch].SB[31]-s_chan[ch].SB[30]; // and next delta to next-next val :) | |
188 | ||
189 | s_chan[ch].SB[32]=0; | |
190 | ||
191 | if(id1>0) // curr delta positive | |
192 | { | |
193 | if(id2<id1) | |
194 | {s_chan[ch].SB[28]=id1;s_chan[ch].SB[32]=2;} | |
195 | else | |
196 | if(id2<(id1<<1)) | |
197 | s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x10000L; | |
198 | else | |
199 | s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x20000L; | |
200 | } | |
201 | else // curr delta negative | |
202 | { | |
203 | if(id2>id1) | |
204 | {s_chan[ch].SB[28]=id1;s_chan[ch].SB[32]=2;} | |
205 | else | |
206 | if(id2>(id1<<1)) | |
207 | s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x10000L; | |
208 | else | |
209 | s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x20000L; | |
210 | } | |
211 | } | |
212 | else | |
213 | if(s_chan[ch].SB[32]==2) // flag 1: calc step and set flag... and don't change the value in this pass | |
214 | { | |
215 | s_chan[ch].SB[32]=0; | |
216 | ||
217 | s_chan[ch].SB[28]=(s_chan[ch].SB[28]*s_chan[ch].sinc)/0x20000L; | |
76d1d09c | 218 | //if(s_chan[ch].sinc<=0x8000) |
219 | // s_chan[ch].SB[29]=s_chan[ch].SB[30]-(s_chan[ch].SB[28]*((0x10000/s_chan[ch].sinc)-1)); | |
220 | //else | |
221 | s_chan[ch].SB[29]+=s_chan[ch].SB[28]; | |
ef79bbde P |
222 | } |
223 | else // no flags? add bigger val (if possible), calc smaller step, set flag1 | |
224 | s_chan[ch].SB[29]+=s_chan[ch].SB[28]; | |
225 | } | |
226 | ||
227 | // | |
228 | // even easier interpolation on downsampling, also no special filter, again just "Pete's common sense" tm | |
229 | // | |
230 | ||
231 | INLINE void InterpolateDown(int ch) | |
232 | { | |
233 | if(s_chan[ch].sinc>=0x20000L) // we would skip at least one val? | |
234 | { | |
235 | s_chan[ch].SB[29]+=(s_chan[ch].SB[30]-s_chan[ch].SB[29])/2; // add easy weight | |
236 | if(s_chan[ch].sinc>=0x30000L) // we would skip even more vals? | |
237 | s_chan[ch].SB[29]+=(s_chan[ch].SB[31]-s_chan[ch].SB[30])/2;// add additional next weight | |
238 | } | |
239 | } | |
240 | ||
241 | //////////////////////////////////////////////////////////////////////// | |
242 | // helpers for gauss interpolation | |
243 | ||
244 | #define gval0 (((short*)(&s_chan[ch].SB[29]))[gpos]) | |
245 | #define gval(x) (((short*)(&s_chan[ch].SB[29]))[(gpos+x)&3]) | |
246 | ||
247 | #include "gauss_i.h" | |
248 | ||
249 | //////////////////////////////////////////////////////////////////////// | |
250 | ||
251 | #include "xa.c" | |
252 | ||
253 | //////////////////////////////////////////////////////////////////////// | |
254 | // START SOUND... called by main thread to setup a new sound on a channel | |
255 | //////////////////////////////////////////////////////////////////////// | |
256 | ||
257 | INLINE void StartSound(int ch) | |
258 | { | |
259 | StartADSR(ch); | |
260 | StartREVERB(ch); | |
261 | ||
b00afb77 | 262 | // fussy timing issues - do in VoiceOn |
263 | //s_chan[ch].pCurr=s_chan[ch].pStart; // set sample start | |
264 | //s_chan[ch].bStop=0; | |
265 | //s_chan[ch].bOn=1; | |
ef79bbde | 266 | |
381ea103 | 267 | s_chan[ch].SB[26]=0; // init mixing vars |
268 | s_chan[ch].SB[27]=0; | |
ef79bbde P |
269 | s_chan[ch].iSBPos=28; |
270 | ||
ef79bbde P |
271 | s_chan[ch].SB[29]=0; // init our interpolation helpers |
272 | s_chan[ch].SB[30]=0; | |
273 | ||
274 | if(iUseInterpolation>=2) // gauss interpolation? | |
275 | {s_chan[ch].spos=0x30000L;s_chan[ch].SB[28]=0;} // -> start with more decoding | |
276 | else {s_chan[ch].spos=0x10000L;s_chan[ch].SB[31]=0;} // -> no/simple interpolation starts with one 44100 decoding | |
277 | ||
278 | dwNewChannel&=~(1<<ch); // clear new channel bit | |
279 | } | |
280 | ||
281 | //////////////////////////////////////////////////////////////////////// | |
282 | // ALL KIND OF HELPERS | |
283 | //////////////////////////////////////////////////////////////////////// | |
284 | ||
07a6dd2c | 285 | INLINE int FModChangeFrequency(int ch,int ns) |
ef79bbde | 286 | { |
7e44d49d | 287 | unsigned int NP=s_chan[ch].iRawPitch; |
07a6dd2c | 288 | int sinc; |
ef79bbde P |
289 | |
290 | NP=((32768L+iFMod[ns])*NP)/32768L; | |
291 | ||
292 | if(NP>0x3fff) NP=0x3fff; | |
293 | if(NP<0x1) NP=0x1; | |
294 | ||
7e44d49d | 295 | sinc=NP<<4; // calc frequency |
ef79bbde | 296 | if(iUseInterpolation==1) // freq change in simple interpolation mode |
07a6dd2c | 297 | s_chan[ch].SB[32]=1; |
ef79bbde | 298 | iFMod[ns]=0; |
07a6dd2c | 299 | |
300 | return sinc; | |
ef79bbde P |
301 | } |
302 | ||
303 | //////////////////////////////////////////////////////////////////////// | |
304 | ||
ef79bbde P |
305 | INLINE void StoreInterpolationVal(int ch,int fa) |
306 | { | |
307 | if(s_chan[ch].bFMod==2) // fmod freq channel | |
308 | s_chan[ch].SB[29]=fa; | |
309 | else | |
310 | { | |
381ea103 | 311 | ssat32_to_16(fa); |
ef79bbde P |
312 | |
313 | if(iUseInterpolation>=2) // gauss/cubic interpolation | |
314 | { | |
315 | int gpos = s_chan[ch].SB[28]; | |
316 | gval0 = fa; | |
317 | gpos = (gpos+1) & 3; | |
318 | s_chan[ch].SB[28] = gpos; | |
319 | } | |
320 | else | |
321 | if(iUseInterpolation==1) // simple interpolation | |
322 | { | |
323 | s_chan[ch].SB[28] = 0; | |
324 | s_chan[ch].SB[29] = s_chan[ch].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' | |
325 | s_chan[ch].SB[30] = s_chan[ch].SB[31]; | |
326 | s_chan[ch].SB[31] = fa; | |
327 | s_chan[ch].SB[32] = 1; // -> flag: calc new interolation | |
328 | } | |
329 | else s_chan[ch].SB[29]=fa; // no interpolation | |
330 | } | |
331 | } | |
332 | ||
333 | //////////////////////////////////////////////////////////////////////// | |
334 | ||
8cd23d6d | 335 | INLINE int iGetInterpolationVal(int ch, int spos) |
ef79bbde P |
336 | { |
337 | int fa; | |
338 | ||
339 | if(s_chan[ch].bFMod==2) return s_chan[ch].SB[29]; | |
340 | ||
341 | switch(iUseInterpolation) | |
342 | { | |
343 | //--------------------------------------------------// | |
344 | case 3: // cubic interpolation | |
345 | { | |
346 | long xd;int gpos; | |
8cd23d6d | 347 | xd = (spos >> 1)+1; |
ef79bbde P |
348 | gpos = s_chan[ch].SB[28]; |
349 | ||
350 | fa = gval(3) - 3*gval(2) + 3*gval(1) - gval0; | |
351 | fa *= (xd - (2<<15)) / 6; | |
352 | fa >>= 15; | |
353 | fa += gval(2) - gval(1) - gval(1) + gval0; | |
354 | fa *= (xd - (1<<15)) >> 1; | |
355 | fa >>= 15; | |
356 | fa += gval(1) - gval0; | |
357 | fa *= xd; | |
358 | fa >>= 15; | |
359 | fa = fa + gval0; | |
360 | ||
361 | } break; | |
362 | //--------------------------------------------------// | |
363 | case 2: // gauss interpolation | |
364 | { | |
365 | int vl, vr;int gpos; | |
8cd23d6d | 366 | vl = (spos >> 6) & ~3; |
ef79bbde P |
367 | gpos = s_chan[ch].SB[28]; |
368 | vr=(gauss[vl]*gval0)&~2047; | |
369 | vr+=(gauss[vl+1]*gval(1))&~2047; | |
370 | vr+=(gauss[vl+2]*gval(2))&~2047; | |
371 | vr+=(gauss[vl+3]*gval(3))&~2047; | |
372 | fa = vr>>11; | |
373 | } break; | |
374 | //--------------------------------------------------// | |
375 | case 1: // simple interpolation | |
376 | { | |
377 | if(s_chan[ch].sinc<0x10000L) // -> upsampling? | |
378 | InterpolateUp(ch); // --> interpolate up | |
379 | else InterpolateDown(ch); // --> else down | |
380 | fa=s_chan[ch].SB[29]; | |
381 | } break; | |
382 | //--------------------------------------------------// | |
383 | default: // no interpolation | |
384 | { | |
385 | fa=s_chan[ch].SB[29]; | |
386 | } break; | |
387 | //--------------------------------------------------// | |
388 | } | |
389 | ||
390 | return fa; | |
391 | } | |
392 | ||
3fc2a4c2 | 393 | static void do_irq(void) |
394 | { | |
8048a6d7 | 395 | //if(!(spuStat & STAT_IRQ)) |
3fc2a4c2 | 396 | { |
8048a6d7 | 397 | spuStat |= STAT_IRQ; // asserted status? |
3fc2a4c2 | 398 | if(irqCallback) irqCallback(); |
399 | } | |
400 | } | |
401 | ||
381ea103 | 402 | static void decode_block_data(int *dest, const unsigned char *src, int predict_nr, int shift_factor) |
403 | { | |
404 | int nSample; | |
405 | int fa, s_1, s_2, d, s; | |
406 | ||
407 | s_1 = dest[27]; | |
408 | s_2 = dest[26]; | |
409 | ||
410 | for (nSample = 0; nSample < 28; src++) | |
411 | { | |
412 | d = (int)*src; | |
413 | s = (int)(signed short)((d & 0x0f) << 12); | |
414 | ||
415 | fa = s >> shift_factor; | |
416 | fa += ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6); | |
417 | s_2=s_1;s_1=fa; | |
418 | ||
419 | dest[nSample++] = fa; | |
420 | ||
421 | s = (int)(signed short)((d & 0xf0) << 8); | |
422 | fa = s >> shift_factor; | |
423 | fa += ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6); | |
424 | s_2=s_1;s_1=fa; | |
425 | ||
426 | dest[nSample++] = fa; | |
427 | } | |
428 | } | |
429 | ||
e11ae5c5 | 430 | static int decode_block(int ch) |
431 | { | |
432 | unsigned char *start; | |
381ea103 | 433 | int predict_nr,shift_factor,flags; |
e11ae5c5 | 434 | int ret = 0; |
435 | ||
e11ae5c5 | 436 | start=s_chan[ch].pCurr; // set up the current pos |
174c454a | 437 | if(dwPendingChanOff&(1<<ch)) |
e11ae5c5 | 438 | { |
439 | dwChannelOn&=~(1<<ch); // -> turn everything off | |
3fc2a4c2 | 440 | dwPendingChanOff&=~(1<<ch); |
e11ae5c5 | 441 | s_chan[ch].bStop=1; |
442 | s_chan[ch].ADSRX.EnvelopeVol=0; | |
e11ae5c5 | 443 | } |
444 | ||
3fc2a4c2 | 445 | //////////////////////////////////////////// irq check |
446 | ||
447 | if(spuCtrl&CTRL_IRQ) | |
448 | { | |
449 | if(pSpuIrq == start) // irq address reached? | |
450 | { | |
451 | do_irq(); // -> call main emu | |
452 | ret = 1; | |
453 | } | |
454 | } | |
e11ae5c5 | 455 | |
381ea103 | 456 | predict_nr=(int)start[0]; |
e11ae5c5 | 457 | shift_factor=predict_nr&0xf; |
458 | predict_nr >>= 4; | |
e11ae5c5 | 459 | |
381ea103 | 460 | decode_block_data(s_chan[ch].SB, start + 2, predict_nr, shift_factor); |
e11ae5c5 | 461 | |
e11ae5c5 | 462 | //////////////////////////////////////////// flag handler |
463 | ||
381ea103 | 464 | flags=(int)start[1]; |
465 | if(flags&4) | |
466 | s_chan[ch].pLoop=start; // loop adress | |
e11ae5c5 | 467 | |
381ea103 | 468 | start+=16; |
e11ae5c5 | 469 | if(flags&1) // 1: stop/loop |
470 | { | |
3fc2a4c2 | 471 | if(!(flags&2)) |
472 | dwPendingChanOff|=1<<ch; | |
473 | ||
474 | start = s_chan[ch].pLoop; | |
e11ae5c5 | 475 | } |
476 | ||
174c454a | 477 | if (start - spuMemC >= 0x80000) { |
478 | // most likely wrong | |
479 | start = spuMemC; | |
480 | printf("ch%d oflow\n", ch); | |
481 | } | |
e11ae5c5 | 482 | |
381ea103 | 483 | s_chan[ch].pCurr = start; // store values for next cycle |
be1cb678 | 484 | s_chan[ch].bJump = flags & 1; |
e11ae5c5 | 485 | |
486 | return ret; | |
487 | } | |
488 | ||
07a6dd2c | 489 | // do block, but ignore sample data |
490 | static int skip_block(int ch) | |
491 | { | |
492 | unsigned char *start = s_chan[ch].pCurr; | |
493 | int flags = start[1]; | |
494 | int ret = 0; | |
495 | ||
07a6dd2c | 496 | if(start == pSpuIrq) |
497 | { | |
498 | do_irq(); | |
499 | ret = 1; | |
500 | } | |
501 | ||
381ea103 | 502 | if(flags & 4) |
be1cb678 | 503 | s_chan[ch].pLoop = start; |
07a6dd2c | 504 | |
505 | s_chan[ch].pCurr += 16; | |
506 | ||
507 | if(flags & 1) | |
508 | s_chan[ch].pCurr = s_chan[ch].pLoop; | |
509 | ||
be1cb678 | 510 | s_chan[ch].bJump = flags & 1; |
07a6dd2c | 511 | return ret; |
512 | } | |
513 | ||
514 | #define make_do_samples(name, fmod_code, interp_start, interp1_code, interp2_code, interp_end) \ | |
515 | static int do_samples_##name(int ch, int ns, int ns_to) \ | |
516 | { \ | |
517 | int sinc = s_chan[ch].sinc; \ | |
518 | int spos = s_chan[ch].spos; \ | |
381ea103 | 519 | int sbpos = s_chan[ch].iSBPos; \ |
520 | int *SB = s_chan[ch].SB; \ | |
07a6dd2c | 521 | int ret = -1; \ |
522 | int d, fa; \ | |
523 | interp_start; \ | |
524 | \ | |
525 | for (; ns < ns_to; ns++) \ | |
526 | { \ | |
527 | fmod_code; \ | |
528 | \ | |
529 | while (spos >= 0x10000) \ | |
530 | { \ | |
381ea103 | 531 | if(sbpos == 28) \ |
07a6dd2c | 532 | { \ |
381ea103 | 533 | sbpos = 0; \ |
07a6dd2c | 534 | d = decode_block(ch); \ |
535 | if(d && iSPUIRQWait) \ | |
536 | { \ | |
537 | ret = ns; \ | |
538 | goto out; \ | |
539 | } \ | |
540 | } \ | |
541 | \ | |
381ea103 | 542 | fa = SB[sbpos++]; \ |
07a6dd2c | 543 | interp1_code; \ |
544 | spos -= 0x10000; \ | |
545 | } \ | |
546 | \ | |
547 | interp2_code; \ | |
548 | spos += sinc; \ | |
549 | } \ | |
550 | \ | |
551 | out: \ | |
552 | s_chan[ch].sinc = sinc; \ | |
553 | s_chan[ch].spos = spos; \ | |
381ea103 | 554 | s_chan[ch].iSBPos = sbpos; \ |
07a6dd2c | 555 | interp_end; \ |
556 | \ | |
557 | return ret; \ | |
558 | } | |
559 | ||
560 | #define fmod_recv_check \ | |
561 | if(s_chan[ch].bFMod==1 && iFMod[ns]) \ | |
562 | sinc = FModChangeFrequency(ch,ns) | |
563 | ||
564 | make_do_samples(default, fmod_recv_check, , | |
565 | StoreInterpolationVal(ch, fa), | |
8cd23d6d | 566 | ChanBuf[ns] = iGetInterpolationVal(ch, spos), ) |
07a6dd2c | 567 | make_do_samples(noint, , fa = s_chan[ch].SB[29], , ChanBuf[ns] = fa, s_chan[ch].SB[29] = fa) |
568 | ||
569 | #define simple_interp_store \ | |
570 | s_chan[ch].SB[28] = 0; \ | |
571 | s_chan[ch].SB[29] = s_chan[ch].SB[30]; \ | |
572 | s_chan[ch].SB[30] = s_chan[ch].SB[31]; \ | |
573 | s_chan[ch].SB[31] = fa; \ | |
574 | s_chan[ch].SB[32] = 1 | |
575 | ||
576 | #define simple_interp_get \ | |
577 | if(sinc<0x10000) /* -> upsampling? */ \ | |
578 | InterpolateUp(ch); /* --> interpolate up */ \ | |
579 | else InterpolateDown(ch); /* --> else down */ \ | |
580 | ChanBuf[ns] = s_chan[ch].SB[29] | |
581 | ||
582 | make_do_samples(simple, , , | |
583 | simple_interp_store, simple_interp_get, ) | |
584 | ||
585 | static int do_samples_noise(int ch, int ns, int ns_to) | |
586 | { | |
b1094d0e | 587 | int level, shift, bit; |
588 | ||
07a6dd2c | 589 | s_chan[ch].spos += s_chan[ch].sinc * (ns_to - ns); |
590 | while (s_chan[ch].spos >= 28*0x10000) | |
591 | { | |
592 | skip_block(ch); | |
593 | s_chan[ch].spos -= 28*0x10000; | |
594 | } | |
595 | ||
b1094d0e | 596 | // modified from DrHell/shalma, no fraction |
597 | level = (spuCtrl >> 10) & 0x0f; | |
598 | level = 0x8000 >> level; | |
599 | ||
07a6dd2c | 600 | for (; ns < ns_to; ns++) |
b1094d0e | 601 | { |
602 | dwNoiseCount += 2; | |
603 | if (dwNoiseCount >= level) | |
604 | { | |
605 | dwNoiseCount -= level; | |
606 | shift = (dwNoiseVal >> 10) & 0x1f; | |
607 | bit = (0x69696969 >> shift) & 1; | |
608 | if (dwNoiseVal & 0x8000) | |
609 | bit ^= 1; | |
610 | dwNoiseVal = (dwNoiseVal << 1) | bit; | |
611 | } | |
612 | ||
613 | ChanBuf[ns] = (signed short)dwNoiseVal; | |
614 | } | |
07a6dd2c | 615 | |
616 | return -1; | |
617 | } | |
618 | ||
3a721c1f | 619 | #ifdef __arm__ |
620 | // asm code; lv and rv must be 0-3fff | |
b17618c0 | 621 | extern void mix_chan(int start, int count, int lv, int rv); |
622 | extern void mix_chan_rvb(int start, int count, int lv, int rv); | |
623 | #else | |
624 | static void mix_chan(int start, int count, int lv, int rv) | |
625 | { | |
626 | int *dst = SSumLR + start * 2; | |
627 | const int *src = ChanBuf + start; | |
628 | int l, r; | |
629 | ||
630 | while (count--) | |
631 | { | |
632 | int sval = *src++; | |
633 | ||
634 | l = (sval * lv) >> 14; | |
635 | r = (sval * rv) >> 14; | |
636 | *dst++ += l; | |
637 | *dst++ += r; | |
638 | } | |
639 | } | |
640 | ||
641 | static void mix_chan_rvb(int start, int count, int lv, int rv) | |
642 | { | |
643 | int *dst = SSumLR + start * 2; | |
644 | int *drvb = sRVBStart + start * 2; | |
645 | const int *src = ChanBuf + start; | |
646 | int l, r; | |
647 | ||
648 | while (count--) | |
649 | { | |
650 | int sval = *src++; | |
651 | ||
652 | l = (sval * lv) >> 14; | |
653 | r = (sval * rv) >> 14; | |
654 | *dst++ += l; | |
655 | *dst++ += r; | |
656 | *drvb++ += l; | |
657 | *drvb++ += r; | |
658 | } | |
659 | } | |
660 | #endif | |
661 | ||
ef79bbde P |
662 | //////////////////////////////////////////////////////////////////////// |
663 | // MAIN SPU FUNCTION | |
6d75977b | 664 | // here is the main job handler... |
ef79bbde P |
665 | // basically the whole sound processing is done in this fat func! |
666 | //////////////////////////////////////////////////////////////////////// | |
667 | ||
6d75977b | 668 | static int do_samples(void) |
ef79bbde | 669 | { |
9e7a7352 | 670 | int volmult = iVolume; |
07a6dd2c | 671 | int ns,ns_from,ns_to; |
174c454a | 672 | int ch,d,silentch; |
ef79bbde P |
673 | int bIRQReturn=0; |
674 | ||
6d75977b | 675 | while(1) |
ef79bbde P |
676 | { |
677 | // ok, at the beginning we are looking if there is | |
678 | // enuff free place in the dsound/oss buffer to | |
679 | // fill in new data, or if there is a new channel to start. | |
680 | // if not, we wait (thread) or return (timer/spuasync) | |
681 | // until enuff free place is available/a new channel gets | |
682 | // started | |
683 | ||
f8edb5bc | 684 | if(!dwNewChannel && SoundGetBytesBuffered()) // still enuff data in sound buffer? |
ef79bbde | 685 | { |
6d75977b | 686 | return 0; |
ef79bbde P |
687 | } |
688 | ||
689 | //--------------------------------------------------// continue from irq handling in timer mode? | |
690 | ||
8680e822 | 691 | ns_from=0; |
692 | ns_to=NSSIZE; | |
693 | ch=0; | |
ef79bbde P |
694 | if(lastch>=0) // will be -1 if no continue is pending |
695 | { | |
e11ae5c5 | 696 | ch=lastch; ns_from=lastns; lastch=-1; // -> setup all kind of vars to continue |
ef79bbde P |
697 | } |
698 | ||
174c454a | 699 | silentch=~(dwChannelOn|dwNewChannel); |
700 | ||
ef79bbde P |
701 | //--------------------------------------------------// |
702 | //- main channel loop -// | |
703 | //--------------------------------------------------// | |
704 | { | |
8680e822 | 705 | for(;ch<MAXCHAN;ch++) // loop em all... we will collect 1 ms of sound of each playing channel |
ef79bbde | 706 | { |
6d866bb7 | 707 | if(dwNewChannel&(1<<ch)) StartSound(ch); // start new sound |
708 | if(!(dwChannelOn&(1<<ch))) continue; // channel not playing? next | |
ef79bbde | 709 | |
07a6dd2c | 710 | if(s_chan[ch].bNoise) |
711 | d=do_samples_noise(ch, ns_from, ns_to); | |
712 | else if(s_chan[ch].bFMod==2 || (s_chan[ch].bFMod==0 && iUseInterpolation==0)) | |
713 | d=do_samples_noint(ch, ns_from, ns_to); | |
714 | else if(s_chan[ch].bFMod==0 && iUseInterpolation==1) | |
715 | d=do_samples_simple(ch, ns_from, ns_to); | |
716 | else | |
717 | d=do_samples_default(ch, ns_from, ns_to); | |
718 | if(d>=0) | |
ef79bbde | 719 | { |
07a6dd2c | 720 | bIRQReturn=1; |
721 | lastch=ch; | |
722 | lastns=ns_to=d; | |
587fa7de | 723 | if(d==0) |
724 | break; | |
1ab7621a | 725 | } |
ef79bbde | 726 | |
1ab7621a | 727 | MixADSR(ch, ns_from, ns_to); |
728 | ||
729 | if(s_chan[ch].bFMod==2) // fmod freq channel | |
730 | memcpy(iFMod, ChanBuf, sizeof(iFMod)); | |
b17618c0 | 731 | else if(s_chan[ch].bRVBActive) |
732 | mix_chan_rvb(ns_from,ns_to-ns_from,s_chan[ch].iLeftVolume,s_chan[ch].iRightVolume); | |
1775933a | 733 | else |
b17618c0 | 734 | mix_chan(ns_from,ns_to-ns_from,s_chan[ch].iLeftVolume,s_chan[ch].iRightVolume); |
ef79bbde P |
735 | } |
736 | } | |
737 | ||
78c60846 | 738 | // advance "stopped" channels that can cause irqs |
739 | // (all chans are always playing on the real thing..) | |
740 | if(!bIRQReturn && (spuCtrl&CTRL_IRQ)) | |
741 | for(ch=0;ch<MAXCHAN;ch++) | |
742 | { | |
174c454a | 743 | if(!(silentch&(1<<ch))) continue; // already handled |
744 | if(dwChannelDead&(1<<ch)) continue; | |
78c60846 | 745 | if(s_chan[ch].pCurr > pSpuIrq && s_chan[ch].pLoop > pSpuIrq) |
746 | continue; | |
747 | ||
78c60846 | 748 | s_chan[ch].spos += s_chan[ch].sinc * NSSIZE; |
749 | while(s_chan[ch].spos >= 28 * 0x10000) | |
750 | { | |
7e44d49d | 751 | unsigned char *start = s_chan[ch].pCurr; |
78c60846 | 752 | |
a3ed1915 | 753 | // no need for bIRQReturn since the channel is silent |
754 | iSpuAsyncWait |= skip_block(ch); | |
07a6dd2c | 755 | if(start == s_chan[ch].pCurr) |
78c60846 | 756 | { |
757 | // looping on self | |
7e44d49d | 758 | dwChannelDead |= 1<<ch; |
759 | s_chan[ch].spos = 0; | |
78c60846 | 760 | break; |
761 | } | |
762 | ||
78c60846 | 763 | s_chan[ch].spos -= 28 * 0x10000; |
764 | } | |
765 | } | |
766 | ||
e11ae5c5 | 767 | if(bIRQReturn && iSPUIRQWait) // special return for "spu irq - wait for cpu action" |
8680e822 | 768 | { |
e11ae5c5 | 769 | iSpuAsyncWait=1; |
8680e822 | 770 | bIRQReturn=0; |
6d75977b | 771 | return 0; |
8680e822 | 772 | } |
773 | ||
774 | ||
ef79bbde P |
775 | //---------------------------------------------------// |
776 | //- here we have another 1 ms of sound data | |
777 | //---------------------------------------------------// | |
778 | // mix XA infos (if any) | |
779 | ||
780 | MixXA(); | |
781 | ||
782 | /////////////////////////////////////////////////////// | |
783 | // mix all channels (including reverb) into one buffer | |
784 | ||
1775933a | 785 | if(iUseReverb) |
786 | REVERBDo(); | |
787 | ||
788 | if((spuCtrl&0x4000)==0) // muted? (rare, don't optimize for this) | |
789 | { | |
790 | memset(pS, 0, NSSIZE * 2 * sizeof(pS[0])); | |
791 | pS += NSSIZE*2; | |
792 | } | |
793 | else | |
97ea4077 | 794 | for (ns = 0; ns < NSSIZE*2; ) |
ef79bbde | 795 | { |
9e7a7352 | 796 | d = SSumLR[ns]; SSumLR[ns] = 0; |
797 | d = d * volmult >> 10; | |
1775933a | 798 | ssat32_to_16(d); |
ef79bbde | 799 | *pS++ = d; |
97ea4077 | 800 | ns++; |
ef79bbde | 801 | |
9e7a7352 | 802 | d = SSumLR[ns]; SSumLR[ns] = 0; |
803 | d = d * volmult >> 10; | |
1775933a | 804 | ssat32_to_16(d); |
ef79bbde | 805 | *pS++ = d; |
97ea4077 | 806 | ns++; |
ef79bbde P |
807 | } |
808 | ||
809 | ////////////////////////////////////////////////////// | |
810 | // special irq handling in the decode buffers (0x0000-0x1000) | |
811 | // we know: | |
812 | // the decode buffers are located in spu memory in the following way: | |
813 | // 0x0000-0x03ff CD audio left | |
814 | // 0x0400-0x07ff CD audio right | |
815 | // 0x0800-0x0bff Voice 1 | |
816 | // 0x0c00-0x0fff Voice 3 | |
817 | // and decoded data is 16 bit for one sample | |
818 | // we assume: | |
819 | // even if voices 1/3 are off or no cd audio is playing, the internal | |
820 | // play positions will move on and wrap after 0x400 bytes. | |
821 | // Therefore: we just need a pointer from spumem+0 to spumem+3ff, and | |
822 | // increase this pointer on each sample by 2 bytes. If this pointer | |
823 | // (or 0x400 offsets of this pointer) hits the spuirq address, we generate | |
824 | // an IRQ. Only problem: the "wait for cpu" option is kinda hard to do here | |
825 | // in some of Peops timer modes. So: we ignore this option here (for now). | |
826 | ||
3fc2a4c2 | 827 | if(pMixIrq) |
ef79bbde P |
828 | { |
829 | for(ns=0;ns<NSSIZE;ns++) | |
830 | { | |
831 | if((spuCtrl&0x40) && pSpuIrq && pSpuIrq<spuMemC+0x1000) | |
832 | { | |
833 | for(ch=0;ch<4;ch++) | |
834 | { | |
835 | if(pSpuIrq>=pMixIrq+(ch*0x400) && pSpuIrq<pMixIrq+(ch*0x400)+2) | |
3fc2a4c2 | 836 | do_irq(); |
ef79bbde P |
837 | } |
838 | } | |
839 | pMixIrq+=2;if(pMixIrq>spuMemC+0x3ff) pMixIrq=spuMemC; | |
840 | } | |
841 | } | |
842 | ||
843 | InitREVERB(); | |
844 | ||
845 | // feed the sound | |
846 | // wanna have around 1/60 sec (16.666 ms) updates | |
381ea103 | 847 | if (iCycle++ > 16/FRAG_MSECS) |
ef79bbde P |
848 | { |
849 | SoundFeedStreamData((unsigned char *)pSpuBuffer, | |
850 | ((unsigned char *)pS) - ((unsigned char *)pSpuBuffer)); | |
851 | pS = (short *)pSpuBuffer; | |
852 | iCycle = 0; | |
853 | } | |
854 | } | |
855 | ||
ef79bbde P |
856 | return 0; |
857 | } | |
858 | ||
859 | // SPU ASYNC... even newer epsxe func | |
860 | // 1 time every 'cycle' cycles... harhar | |
861 | ||
554a2220 | 862 | // rearmed: called every 2ms now |
863 | ||
ef79bbde P |
864 | void CALLBACK SPUasync(unsigned long cycle) |
865 | { | |
f8edb5bc | 866 | if(!bSpuInit) return; // -> no init, no call |
867 | ||
ef79bbde P |
868 | if(iSpuAsyncWait) |
869 | { | |
870 | iSpuAsyncWait++; | |
6d75977b | 871 | if(iSpuAsyncWait<=16/FRAG_MSECS) return; |
ef79bbde P |
872 | iSpuAsyncWait=0; |
873 | } | |
874 | ||
6d75977b | 875 | do_samples(); |
ef79bbde P |
876 | } |
877 | ||
878 | // SPU UPDATE... new epsxe func | |
879 | // 1 time every 32 hsync lines | |
880 | // (312/32)x50 in pal | |
881 | // (262/32)x60 in ntsc | |
882 | ||
883 | // since epsxe 1.5.2 (linux) uses SPUupdate, not SPUasync, I will | |
884 | // leave that func in the linux port, until epsxe linux is using | |
885 | // the async function as well | |
886 | ||
887 | void CALLBACK SPUupdate(void) | |
888 | { | |
889 | SPUasync(0); | |
890 | } | |
891 | ||
892 | // XA AUDIO | |
893 | ||
894 | void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap) | |
895 | { | |
896 | if(!xap) return; | |
897 | if(!xap->freq) return; // no xa freq ? bye | |
898 | ||
899 | FeedXA(xap); // call main XA feeder | |
900 | } | |
901 | ||
902 | // CDDA AUDIO | |
983a7cfd | 903 | int CALLBACK SPUplayCDDAchannel(short *pcm, int nbytes) |
ef79bbde | 904 | { |
983a7cfd | 905 | if (!pcm) return -1; |
906 | if (nbytes<=0) return -1; | |
ef79bbde | 907 | |
983a7cfd | 908 | return FeedCDDA((unsigned char *)pcm, nbytes); |
ef79bbde P |
909 | } |
910 | ||
6d75977b | 911 | // to be called after state load |
912 | void ClearWorkingState(void) | |
ef79bbde | 913 | { |
97ea4077 | 914 | memset(SSumLR,0,sizeof(SSumLR)); // init some mixing buffers |
6d75977b | 915 | memset(iFMod,0,sizeof(iFMod)); |
ef79bbde | 916 | pS=(short *)pSpuBuffer; // setup soundbuffer pointer |
ef79bbde P |
917 | } |
918 | ||
919 | // SETUPSTREAMS: init most of the spu buffers | |
920 | void SetupStreams(void) | |
921 | { | |
922 | int i; | |
923 | ||
924 | pSpuBuffer=(unsigned char *)malloc(32768); // alloc mixing buffer | |
925 | ||
926 | if(iUseReverb==1) i=88200*2; | |
927 | else i=NSSIZE*2; | |
928 | ||
929 | sRVBStart = (int *)malloc(i*4); // alloc reverb buffer | |
930 | memset(sRVBStart,0,i*4); | |
931 | sRVBEnd = sRVBStart + i; | |
932 | sRVBPlay = sRVBStart; | |
933 | ||
934 | XAStart = // alloc xa buffer | |
935 | (uint32_t *)malloc(44100 * sizeof(uint32_t)); | |
936 | XAEnd = XAStart + 44100; | |
937 | XAPlay = XAStart; | |
938 | XAFeed = XAStart; | |
939 | ||
940 | CDDAStart = // alloc cdda buffer | |
983a7cfd | 941 | (uint32_t *)malloc(CDDA_BUFFER_SIZE); |
ef79bbde P |
942 | CDDAEnd = CDDAStart + 16384; |
943 | CDDAPlay = CDDAStart; | |
b8e744ce | 944 | CDDAFeed = CDDAStart; |
ef79bbde P |
945 | |
946 | for(i=0;i<MAXCHAN;i++) // loop sound channels | |
947 | { | |
948 | // we don't use mutex sync... not needed, would only | |
949 | // slow us down: | |
950 | // s_chan[i].hMutex=CreateMutex(NULL,FALSE,NULL); | |
6d866bb7 | 951 | s_chan[i].ADSRX.SustainLevel = 0xf; // -> init sustain |
ef79bbde | 952 | s_chan[i].pLoop=spuMemC; |
ef79bbde P |
953 | s_chan[i].pCurr=spuMemC; |
954 | } | |
955 | ||
6d75977b | 956 | pMixIrq=spuMemC; // enable decoded buffer irqs by setting the address |
957 | ||
958 | ClearWorkingState(); | |
959 | ||
960 | bSpuInit=1; // flag: we are inited | |
ef79bbde P |
961 | } |
962 | ||
963 | // REMOVESTREAMS: free most buffer | |
964 | void RemoveStreams(void) | |
965 | { | |
966 | free(pSpuBuffer); // free mixing buffer | |
967 | pSpuBuffer = NULL; | |
968 | free(sRVBStart); // free reverb buffer | |
969 | sRVBStart = NULL; | |
970 | free(XAStart); // free XA buffer | |
971 | XAStart = NULL; | |
972 | free(CDDAStart); // free CDDA buffer | |
973 | CDDAStart = NULL; | |
974 | } | |
975 | ||
976 | // INIT/EXIT STUFF | |
977 | ||
978 | // SPUINIT: this func will be called first by the main emu | |
979 | long CALLBACK SPUinit(void) | |
980 | { | |
981 | spuMemC = (unsigned char *)spuMem; // just small setup | |
982 | memset((void *)&rvb, 0, sizeof(REVERBInfo)); | |
983 | InitADSR(); | |
984 | ||
ef79bbde P |
985 | spuIrq = 0; |
986 | spuAddr = 0xffffffff; | |
ef79bbde P |
987 | spuMemC = (unsigned char *)spuMem; |
988 | pMixIrq = 0; | |
989 | memset((void *)s_chan, 0, (MAXCHAN + 1) * sizeof(SPUCHAN)); | |
990 | pSpuIrq = 0; | |
cdb31c95 | 991 | //iSPUIRQWait = 0; |
ef79bbde P |
992 | lastch = -1; |
993 | ||
ef79bbde P |
994 | SetupStreams(); // prepare streaming |
995 | ||
996 | return 0; | |
997 | } | |
998 | ||
999 | // SPUOPEN: called by main emu after init | |
1000 | long CALLBACK SPUopen(void) | |
1001 | { | |
1002 | if (bSPUIsOpen) return 0; // security for some stupid main emus | |
1003 | ||
1004 | SetupSound(); // setup sound (before init!) | |
ef79bbde P |
1005 | |
1006 | bSPUIsOpen = 1; | |
1007 | ||
1008 | return PSE_SPU_ERR_SUCCESS; | |
1009 | } | |
1010 | ||
1011 | // SPUCLOSE: called before shutdown | |
1012 | long CALLBACK SPUclose(void) | |
1013 | { | |
1014 | if (!bSPUIsOpen) return 0; // some security | |
1015 | ||
1016 | bSPUIsOpen = 0; // no more open | |
1017 | ||
ef79bbde P |
1018 | RemoveSound(); // no more sound handling |
1019 | ||
1020 | return 0; | |
1021 | } | |
1022 | ||
1023 | // SPUSHUTDOWN: called by main emu on final exit | |
1024 | long CALLBACK SPUshutdown(void) | |
1025 | { | |
1026 | SPUclose(); | |
1027 | RemoveStreams(); // no more streaming | |
6d75977b | 1028 | bSpuInit=0; |
ef79bbde P |
1029 | |
1030 | return 0; | |
1031 | } | |
1032 | ||
1033 | // SPUTEST: we don't test, we are always fine ;) | |
1034 | long CALLBACK SPUtest(void) | |
1035 | { | |
1036 | return 0; | |
1037 | } | |
1038 | ||
1039 | // SPUCONFIGURE: call config dialog | |
1040 | long CALLBACK SPUconfigure(void) | |
1041 | { | |
1042 | #ifdef _MACOSX | |
1043 | DoConfiguration(); | |
1044 | #else | |
ee849648 | 1045 | // StartCfgTool("CFG"); |
ef79bbde P |
1046 | #endif |
1047 | return 0; | |
1048 | } | |
1049 | ||
1050 | // SPUABOUT: show about window | |
1051 | void CALLBACK SPUabout(void) | |
1052 | { | |
1053 | #ifdef _MACOSX | |
1054 | DoAbout(); | |
1055 | #else | |
ee849648 | 1056 | // StartCfgTool("ABOUT"); |
ef79bbde P |
1057 | #endif |
1058 | } | |
1059 | ||
1060 | // SETUP CALLBACKS | |
1061 | // this functions will be called once, | |
1062 | // passes a callback that should be called on SPU-IRQ/cdda volume change | |
1063 | void CALLBACK SPUregisterCallback(void (CALLBACK *callback)(void)) | |
1064 | { | |
1065 | irqCallback = callback; | |
1066 | } | |
1067 | ||
1068 | void CALLBACK SPUregisterCDDAVolume(void (CALLBACK *CDDAVcallback)(unsigned short,unsigned short)) | |
1069 | { | |
1070 | cddavCallback = CDDAVcallback; | |
1071 | } | |
1072 | ||
1073 | // COMMON PLUGIN INFO FUNCS | |
e906c010 | 1074 | /* |
ef79bbde P |
1075 | char * CALLBACK PSEgetLibName(void) |
1076 | { | |
1077 | return _(libraryName); | |
1078 | } | |
1079 | ||
1080 | unsigned long CALLBACK PSEgetLibType(void) | |
1081 | { | |
1082 | return PSE_LT_SPU; | |
1083 | } | |
1084 | ||
1085 | unsigned long CALLBACK PSEgetLibVersion(void) | |
1086 | { | |
1087 | return (1 << 16) | (6 << 8); | |
1088 | } | |
1089 | ||
1090 | char * SPUgetLibInfos(void) | |
1091 | { | |
1092 | return _(libraryInfo); | |
1093 | } | |
e906c010 | 1094 | */ |
6d866bb7 | 1095 | |
90f1d26c | 1096 | // debug |
174c454a | 1097 | void spu_get_debug_info(int *chans_out, int *run_chans, int *fmod_chans_out, int *noise_chans_out) |
90f1d26c | 1098 | { |
174c454a | 1099 | int ch = 0, fmod_chans = 0, noise_chans = 0, irq_chans = 0; |
90f1d26c | 1100 | |
1101 | for(;ch<MAXCHAN;ch++) | |
1102 | { | |
1103 | if (!(dwChannelOn & (1<<ch))) | |
1104 | continue; | |
1105 | if (s_chan[ch].bFMod == 2) | |
1106 | fmod_chans |= 1 << ch; | |
1107 | if (s_chan[ch].bNoise) | |
1108 | noise_chans |= 1 << ch; | |
174c454a | 1109 | if((spuCtrl&CTRL_IRQ) && s_chan[ch].pCurr <= pSpuIrq && s_chan[ch].pLoop <= pSpuIrq) |
1110 | irq_chans |= 1 << ch; | |
90f1d26c | 1111 | } |
1112 | ||
1113 | *chans_out = dwChannelOn; | |
174c454a | 1114 | *run_chans = ~dwChannelOn & ~dwChannelDead & irq_chans; |
90f1d26c | 1115 | *fmod_chans_out = fmod_chans; |
1116 | *noise_chans_out = noise_chans; | |
1117 | } | |
1118 | ||
6d866bb7 | 1119 | // vim:shiftwidth=1:expandtab |