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