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 #include "externals.h"
24 #include "dsoundoss.h"
30 #define _(x) gettext(x)
38 #if defined (USEMACOSX)
39 static char * libraryName = N_("Mac OS X Sound");
40 #elif defined (USEALSA)
41 static char * libraryName = N_("ALSA Sound");
42 #elif defined (USEOSS)
43 static char * libraryName = N_("OSS Sound");
44 #elif defined (USESDL)
45 static char * libraryName = N_("SDL Sound");
46 #elif defined (USEPULSEAUDIO)
47 static char * libraryName = N_("PulseAudio Sound");
49 static char * libraryName = N_("NULL Sound");
52 static char * libraryInfo = N_("P.E.Op.S. Sound Driver V1.7\nCoded by Pete Bernert and the P.E.Op.S. team\n");
57 // psx buffer / addresses
59 unsigned short regArea[10000];
60 unsigned short spuMem[256*1024];
61 unsigned char * spuMemC;
62 unsigned char * pSpuIrq=0;
63 unsigned char * pSpuBuffer;
64 unsigned char * pMixIrq=0;
75 int iUseInterpolation=2;
77 // MAIN infos struct for each channel
79 SPUCHAN s_chan[MAXCHAN+1]; // channel + 1 infos (1 is security for fmod handling)
82 unsigned long dwNoiseVal=1; // global noise generator
85 unsigned short spuCtrl=0; // some vars to store psx reg infos
86 unsigned short spuStat=0;
87 unsigned short spuIrq=0;
88 unsigned long spuAddr=0xffffffff; // address into spu mem
89 int bEndThread=0; // thread handlers
94 static pthread_t thread = (pthread_t)-1; // thread id (linux)
96 unsigned long dwNewChannel=0; // flags for faster testing, if new channel starts
97 unsigned long dwChannelOn=0;
99 void (CALLBACK *irqCallback)(void)=0; // func of main emu, called on spu irq
100 void (CALLBACK *cddavCallback)(unsigned short,unsigned short)=0;
102 // certain globals (were local before, but with the new timeproc I need em global)
104 static const int f[8][2] = { { 0, 0 },
109 int SSumLR[NSSIZE*2];
114 int lastch=-1; // last channel processed on spu irq in timer mode
115 static int lastns=0; // last ns pos
116 static int iSecureStart=0; // secure start counter
118 ////////////////////////////////////////////////////////////////////////
120 ////////////////////////////////////////////////////////////////////////
122 // dirty inline func includes
127 ////////////////////////////////////////////////////////////////////////
128 // helpers for simple interpolation
131 // easy interpolation on upsampling, no special filter, just "Pete's common sense" tm
133 // instead of having n equal sample values in a row like:
137 // we compare the current delta change with the next delta change.
139 // if curr_delta is positive,
141 // - and next delta is smaller (or changing direction):
145 // - and next delta significant (at least twice) bigger:
149 // - and next delta is nearly same:
154 // if curr_delta is negative,
156 // - and next delta is smaller (or changing direction):
160 // - and next delta significant (at least twice) bigger:
164 // - and next delta is nearly same:
170 INLINE void InterpolateUp(int ch)
172 if(s_chan[ch].SB[32]==1) // flag == 1? calc step and set flag... and don't change the value in this pass
174 const int id1=s_chan[ch].SB[30]-s_chan[ch].SB[29]; // curr delta to next val
175 const int id2=s_chan[ch].SB[31]-s_chan[ch].SB[30]; // and next delta to next-next val :)
179 if(id1>0) // curr delta positive
182 {s_chan[ch].SB[28]=id1;s_chan[ch].SB[32]=2;}
185 s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x10000L;
187 s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x20000L;
189 else // curr delta negative
192 {s_chan[ch].SB[28]=id1;s_chan[ch].SB[32]=2;}
195 s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x10000L;
197 s_chan[ch].SB[28]=(id1*s_chan[ch].sinc)/0x20000L;
201 if(s_chan[ch].SB[32]==2) // flag 1: calc step and set flag... and don't change the value in this pass
205 s_chan[ch].SB[28]=(s_chan[ch].SB[28]*s_chan[ch].sinc)/0x20000L;
206 if(s_chan[ch].sinc<=0x8000)
207 s_chan[ch].SB[29]=s_chan[ch].SB[30]-(s_chan[ch].SB[28]*((0x10000/s_chan[ch].sinc)-1));
208 else s_chan[ch].SB[29]+=s_chan[ch].SB[28];
210 else // no flags? add bigger val (if possible), calc smaller step, set flag1
211 s_chan[ch].SB[29]+=s_chan[ch].SB[28];
215 // even easier interpolation on downsampling, also no special filter, again just "Pete's common sense" tm
218 INLINE void InterpolateDown(int ch)
220 if(s_chan[ch].sinc>=0x20000L) // we would skip at least one val?
222 s_chan[ch].SB[29]+=(s_chan[ch].SB[30]-s_chan[ch].SB[29])/2; // add easy weight
223 if(s_chan[ch].sinc>=0x30000L) // we would skip even more vals?
224 s_chan[ch].SB[29]+=(s_chan[ch].SB[31]-s_chan[ch].SB[30])/2;// add additional next weight
228 ////////////////////////////////////////////////////////////////////////
229 // helpers for gauss interpolation
231 #define gval0 (((short*)(&s_chan[ch].SB[29]))[gpos])
232 #define gval(x) (((short*)(&s_chan[ch].SB[29]))[(gpos+x)&3])
236 ////////////////////////////////////////////////////////////////////////
240 ////////////////////////////////////////////////////////////////////////
241 // START SOUND... called by main thread to setup a new sound on a channel
242 ////////////////////////////////////////////////////////////////////////
244 INLINE void StartSound(int ch)
249 // fussy timing issues - do in VoiceOn
250 //s_chan[ch].pCurr=s_chan[ch].pStart; // set sample start
251 //s_chan[ch].bStop=0;
254 s_chan[ch].s_1=0; // init mixing vars
256 s_chan[ch].iSBPos=28;
258 s_chan[ch].SB[29]=0; // init our interpolation helpers
261 if(iUseInterpolation>=2) // gauss interpolation?
262 {s_chan[ch].spos=0x30000L;s_chan[ch].SB[28]=0;} // -> start with more decoding
263 else {s_chan[ch].spos=0x10000L;s_chan[ch].SB[31]=0;} // -> no/simple interpolation starts with one 44100 decoding
265 dwNewChannel&=~(1<<ch); // clear new channel bit
268 ////////////////////////////////////////////////////////////////////////
269 // ALL KIND OF HELPERS
270 ////////////////////////////////////////////////////////////////////////
272 INLINE void VoiceChangeFrequency(int ch)
274 s_chan[ch].iUsedFreq=s_chan[ch].iActFreq; // -> take it and calc steps
275 s_chan[ch].sinc=s_chan[ch].iRawPitch<<4;
276 if(!s_chan[ch].sinc) s_chan[ch].sinc=1;
277 if(iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simle imterpolation mode: set flag
280 ////////////////////////////////////////////////////////////////////////
282 INLINE void FModChangeFrequency(int ch,int ns)
284 int NP=s_chan[ch].iRawPitch;
286 NP=((32768L+iFMod[ns])*NP)/32768L;
288 if(NP>0x3fff) NP=0x3fff;
291 NP=(44100L*NP)/(4096L); // calc frequency
293 s_chan[ch].iActFreq=NP;
294 s_chan[ch].iUsedFreq=NP;
295 s_chan[ch].sinc=(((NP/10)<<16)/4410);
296 if(!s_chan[ch].sinc) s_chan[ch].sinc=1;
297 if(iUseInterpolation==1) // freq change in simple interpolation mode
302 ////////////////////////////////////////////////////////////////////////
304 // noise handler... just produces some noise data
305 // surely wrong... and no noise frequency (spuCtrl&0x3f00) will be used...
306 // and sometimes the noise will be used as fmod modulation... pfff
308 INLINE int iGetNoiseVal(int ch)
312 if((dwNoiseVal<<=1)&0x80000000L)
314 dwNoiseVal^=0x0040001L;
315 fa=((dwNoiseVal>>2)&0x7fff);
318 else fa=(dwNoiseVal>>2)&0x7fff;
320 // mmm... depending on the noise freq we allow bigger/smaller changes to the previous val
321 fa=s_chan[ch].iOldNoise+((fa-s_chan[ch].iOldNoise)/((0x001f-((spuCtrl&0x3f00)>>9))+1));
322 if(fa>32767L) fa=32767L;
323 if(fa<-32767L) fa=-32767L;
324 s_chan[ch].iOldNoise=fa;
326 if(iUseInterpolation<2) // no gauss/cubic interpolation?
327 s_chan[ch].SB[29] = fa; // -> store noise val in "current sample" slot
331 ////////////////////////////////////////////////////////////////////////
333 INLINE void StoreInterpolationVal(int ch,int fa)
335 if(s_chan[ch].bFMod==2) // fmod freq channel
336 s_chan[ch].SB[29]=fa;
339 if((spuCtrl&0x4000)==0) fa=0; // muted?
342 if(fa>32767L) fa=32767L;
343 if(fa<-32767L) fa=-32767L;
346 if(iUseInterpolation>=2) // gauss/cubic interpolation
348 int gpos = s_chan[ch].SB[28];
351 s_chan[ch].SB[28] = gpos;
354 if(iUseInterpolation==1) // simple interpolation
356 s_chan[ch].SB[28] = 0;
357 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'
358 s_chan[ch].SB[30] = s_chan[ch].SB[31];
359 s_chan[ch].SB[31] = fa;
360 s_chan[ch].SB[32] = 1; // -> flag: calc new interolation
362 else s_chan[ch].SB[29]=fa; // no interpolation
366 ////////////////////////////////////////////////////////////////////////
368 INLINE int iGetInterpolationVal(int ch)
372 if(s_chan[ch].bFMod==2) return s_chan[ch].SB[29];
374 switch(iUseInterpolation)
376 //--------------------------------------------------//
377 case 3: // cubic interpolation
380 xd = ((s_chan[ch].spos) >> 1)+1;
381 gpos = s_chan[ch].SB[28];
383 fa = gval(3) - 3*gval(2) + 3*gval(1) - gval0;
384 fa *= (xd - (2<<15)) / 6;
386 fa += gval(2) - gval(1) - gval(1) + gval0;
387 fa *= (xd - (1<<15)) >> 1;
389 fa += gval(1) - gval0;
395 //--------------------------------------------------//
396 case 2: // gauss interpolation
399 vl = (s_chan[ch].spos >> 6) & ~3;
400 gpos = s_chan[ch].SB[28];
401 vr=(gauss[vl]*gval0)&~2047;
402 vr+=(gauss[vl+1]*gval(1))&~2047;
403 vr+=(gauss[vl+2]*gval(2))&~2047;
404 vr+=(gauss[vl+3]*gval(3))&~2047;
407 //--------------------------------------------------//
408 case 1: // simple interpolation
410 if(s_chan[ch].sinc<0x10000L) // -> upsampling?
411 InterpolateUp(ch); // --> interpolate up
412 else InterpolateDown(ch); // --> else down
413 fa=s_chan[ch].SB[29];
415 //--------------------------------------------------//
416 default: // no interpolation
418 fa=s_chan[ch].SB[29];
420 //--------------------------------------------------//
426 ////////////////////////////////////////////////////////////////////////
428 // here is the main job handler... thread, timer or direct func call
429 // basically the whole sound processing is done in this fat func!
430 ////////////////////////////////////////////////////////////////////////
432 // 5 ms waiting phase, if buffer is full and no new sound has to get started
433 // .. can be made smaller (smallest val: 1 ms), but bigger waits give
434 // better performance
439 ////////////////////////////////////////////////////////////////////////
441 static void *MAINThread(void *arg)
443 int s_1,s_2,fa,ns,ns_from,ns_to;
444 #if !defined(_MACOSX) && !defined(__arm__)
445 int voldiv = iVolume;
447 const int voldiv = 2;
449 unsigned char * start;unsigned int nSample;
450 int ch,predict_nr,shift_factor,flags,d,s;
453 while(!bEndThread) // until we are shutting down
455 // ok, at the beginning we are looking if there is
456 // enuff free place in the dsound/oss buffer to
457 // fill in new data, or if there is a new channel to start.
458 // if not, we wait (thread) or return (timer/spuasync)
459 // until enuff free place is available/a new channel gets
462 if(dwNewChannel) // new channel should start immedately?
463 { // (at least one bit 0 ... MAXCHANNEL is set?)
464 iSecureStart++; // -> set iSecure
465 if(iSecureStart>5) iSecureStart=0; // (if it is set 5 times - that means on 5 tries a new samples has been started - in a row, we will reset it, to give the sound update a chance)
467 else iSecureStart=0; // 0: no new channel should start
469 while(!iSecureStart && !bEndThread && // no new start? no thread end?
470 (SoundGetBytesBuffered()>TESTSIZE)) // and still enuff data in sound buffer?
472 iSecureStart=0; // reset secure
474 if(iUseTimer) return 0; // linux no-thread mode? bye
475 usleep(PAUSE_L); // else sleep for x ms (linux)
477 if(dwNewChannel) iSecureStart=1; // if a new channel kicks in (or, of course, sound buffer runs low), we will leave the loop
480 //--------------------------------------------------// continue from irq handling in timer mode?
485 if(lastch>=0) // will be -1 if no continue is pending
487 ch=lastch; ns_from=lastns+1; lastch=-1; // -> setup all kind of vars to continue
490 //--------------------------------------------------//
491 //- main channel loop -//
492 //--------------------------------------------------//
494 for(;ch<MAXCHAN;ch++) // loop em all... we will collect 1 ms of sound of each playing channel
496 if(dwNewChannel&(1<<ch)) StartSound(ch); // start new sound
497 if(!(dwChannelOn&(1<<ch))) continue; // channel not playing? next
499 if(s_chan[ch].iActFreq!=s_chan[ch].iUsedFreq) // new psx frequency?
500 VoiceChangeFrequency(ch);
502 for(ns=ns_from;ns<ns_to;ns++) // loop until 1 ms of data is reached
506 if(s_chan[ch].bFMod==1 && iFMod[ns]) // fmod freq channel
507 FModChangeFrequency(ch,ns);
509 while(s_chan[ch].spos>=0x10000L)
511 if(s_chan[ch].iSBPos==28) // 28 reached?
513 start=s_chan[ch].pCurr; // set up the current pos
515 if (start == (unsigned char*)-1) // special "stop" sign
517 dwChannelOn&=~(1<<ch); // -> turn everything off
518 s_chan[ch].ADSRX.EnvelopeVol=0;
519 goto ENDX; // -> and done for this channel
524 //////////////////////////////////////////// spu irq handler here? mmm... do it later
529 predict_nr=(int)*start;start++;
530 shift_factor=predict_nr&0xf;
532 flags=(int)*start;start++;
534 // -------------------------------------- //
536 for (nSample=0;nSample<28;start++)
540 if(s&0x8000) s|=0xffff0000;
542 fa=(s >> shift_factor);
543 fa=fa + ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
547 s_chan[ch].SB[nSample++]=fa;
549 if(s&0x8000) s|=0xffff0000;
550 fa=(s>>shift_factor);
551 fa=fa + ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1])>>6);
554 s_chan[ch].SB[nSample++]=fa;
557 //////////////////////////////////////////// irq check
559 if(irqCallback && (spuCtrl&0x40)) // some callback and irq active?
561 if((pSpuIrq > start-16 && // irq address reached?
563 ((flags&1) && // special: irq on looping addr, when stop/loop flag is set
564 (pSpuIrq > s_chan[ch].pLoop-16 &&
565 pSpuIrq <= s_chan[ch].pLoop)))
567 irqCallback(); // -> call main emu
569 if(iSPUIRQWait) // -> option: wait after irq for main emu
580 //////////////////////////////////////////// flag handler
582 if((flags&4) && (!s_chan[ch].bIgnoreLoop))
583 s_chan[ch].pLoop=start-16; // loop adress
585 if(flags&1) // 1: stop/loop
587 // We play this block out first...
588 //if(!(flags&2)) // 1+2: do loop... otherwise: stop
589 if(flags!=3 || s_chan[ch].pLoop==NULL) // PETE: if we don't check exactly for 3, loop hang ups will happen (DQ4, for example)
590 { // and checking if pLoop is set avoids crashes, yeah
591 start = (unsigned char*)-1;
595 start = s_chan[ch].pLoop;
599 s_chan[ch].pCurr=start; // store values for next cycle
604 fa=s_chan[ch].SB[s_chan[ch].iSBPos++]; // get sample data
606 StoreInterpolationVal(ch,fa); // store val for later interpolation
608 s_chan[ch].spos -= 0x10000L;
611 if(s_chan[ch].bNoise)
612 fa=iGetNoiseVal(ch); // get noise val
613 else fa=iGetInterpolationVal(ch); // get sample val
615 sval = (MixADSR(ch) * fa) / 1023; // mix adsr
617 if(s_chan[ch].bFMod==2) // fmod freq channel
618 iFMod[ns]=sval; // -> store 1T sample data, use that to do fmod on next channel
619 else // no fmod freq channel
621 //////////////////////////////////////////////
622 // ok, left/right sound volume (psx volume goes from 0 ... 0x3fff)
624 SSumLR[ns*2] +=(sval*s_chan[ch].iLeftVolume)/0x4000L;
625 SSumLR[ns*2+1]+=(sval*s_chan[ch].iRightVolume)/0x4000L;
627 //////////////////////////////////////////////
628 // now let us store sound data for reverb
630 if(s_chan[ch].bRVBActive) StoreREVERB(ch,ns,sval);
633 ////////////////////////////////////////////////
634 // ok, go on until 1 ms data of this channel is collected
636 s_chan[ch].spos += s_chan[ch].sinc;
642 if(bIRQReturn) // special return for "spu irq - wait for cpu action"
647 DWORD dwWatchTime=timeGetTime_spu()+2500;
649 while(iSpuAsyncWait && !bEndThread &&
650 timeGetTime_spu()<dwWatchTime)
661 //---------------------------------------------------//
662 //- here we have another 1 ms of sound data
663 //---------------------------------------------------//
664 // mix XA infos (if any)
668 ///////////////////////////////////////////////////////
669 // mix all channels (including reverb) into one buffer
671 for (ns = 0; ns < NSSIZE*2; )
673 SSumLR[ns] += MixREVERBLeft(ns/2);
675 d = SSumLR[ns] / voldiv; SSumLR[ns] = 0;
676 if (d < -32767) d = -32767; if (d > 32767) d = 32767;
680 SSumLR[ns] += MixREVERBRight();
682 d = SSumLR[ns] / voldiv; SSumLR[ns] = 0;
683 if(d < -32767) d = -32767; if(d > 32767) d = 32767;
688 //////////////////////////////////////////////////////
689 // special irq handling in the decode buffers (0x0000-0x1000)
691 // the decode buffers are located in spu memory in the following way:
692 // 0x0000-0x03ff CD audio left
693 // 0x0400-0x07ff CD audio right
694 // 0x0800-0x0bff Voice 1
695 // 0x0c00-0x0fff Voice 3
696 // and decoded data is 16 bit for one sample
698 // even if voices 1/3 are off or no cd audio is playing, the internal
699 // play positions will move on and wrap after 0x400 bytes.
700 // Therefore: we just need a pointer from spumem+0 to spumem+3ff, and
701 // increase this pointer on each sample by 2 bytes. If this pointer
702 // (or 0x400 offsets of this pointer) hits the spuirq address, we generate
703 // an IRQ. Only problem: the "wait for cpu" option is kinda hard to do here
704 // in some of Peops timer modes. So: we ignore this option here (for now).
706 if(pMixIrq && irqCallback)
708 for(ns=0;ns<NSSIZE;ns++)
710 if((spuCtrl&0x40) && pSpuIrq && pSpuIrq<spuMemC+0x1000)
714 if(pSpuIrq>=pMixIrq+(ch*0x400) && pSpuIrq<pMixIrq+(ch*0x400)+2)
718 pMixIrq+=2;if(pMixIrq>spuMemC+0x3ff) pMixIrq=spuMemC;
725 // wanna have around 1/60 sec (16.666 ms) updates
728 SoundFeedStreamData((unsigned char *)pSpuBuffer,
729 ((unsigned char *)pS) - ((unsigned char *)pSpuBuffer));
730 pS = (short *)pSpuBuffer;
735 // end of big main loop...
742 // SPU ASYNC... even newer epsxe func
743 // 1 time every 'cycle' cycles... harhar
745 void CALLBACK SPUasync(unsigned long cycle)
750 if(iSpuAsyncWait<=16) return;
754 if(iUseTimer==2) // special mode, only used in Linux by this spu (or if you enable the experimental Windows mode)
756 if(!bSpuInit) return; // -> no init, no call
758 MAINThread(0); // -> linux high-compat mode
760 // abuse iSpuAsyncWait mechanism to reduce calls to above function
761 // to make it do larger chunks
762 // note: doing it less often than once per frame causes skips
767 // SPU UPDATE... new epsxe func
768 // 1 time every 32 hsync lines
769 // (312/32)x50 in pal
770 // (262/32)x60 in ntsc
772 // since epsxe 1.5.2 (linux) uses SPUupdate, not SPUasync, I will
773 // leave that func in the linux port, until epsxe linux is using
774 // the async function as well
776 void CALLBACK SPUupdate(void)
783 void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap)
786 if(!xap->freq) return; // no xa freq ? bye
788 FeedXA(xap); // call main XA feeder
792 void CALLBACK SPUplayCDDAchannel(short *pcm, int nbytes)
795 if (nbytes<=0) return;
797 FeedCDDA((unsigned char *)pcm, nbytes);
800 // SETUPTIMER: init of certain buffers and threads/timers
801 void SetupTimer(void)
803 memset(SSumLR,0,sizeof(SSumLR)); // init some mixing buffers
804 memset(iFMod,0,NSSIZE*sizeof(int));
805 pS=(short *)pSpuBuffer; // setup soundbuffer pointer
807 bEndThread=0; // init thread vars
809 bSpuInit=1; // flag: we are inited
811 if(!iUseTimer) // linux: use thread
813 pthread_create(&thread, NULL, MAINThread, NULL);
817 // REMOVETIMER: kill threads/timers
818 void RemoveTimer(void)
820 bEndThread=1; // raise flag to end thread
822 if(!iUseTimer) // linux tread?
825 while(!bThreadEnded && i<2000) {usleep(1000L);i++;} // -> wait until thread has ended
826 if(thread!=(pthread_t)-1) {pthread_cancel(thread);thread=(pthread_t)-1;} // -> cancel thread anyway
829 bThreadEnded=0; // no more spu is running
833 // SETUPSTREAMS: init most of the spu buffers
834 void SetupStreams(void)
838 pSpuBuffer=(unsigned char *)malloc(32768); // alloc mixing buffer
840 if(iUseReverb==1) i=88200*2;
843 sRVBStart = (int *)malloc(i*4); // alloc reverb buffer
844 memset(sRVBStart,0,i*4);
845 sRVBEnd = sRVBStart + i;
846 sRVBPlay = sRVBStart;
848 XAStart = // alloc xa buffer
849 (uint32_t *)malloc(44100 * sizeof(uint32_t));
850 XAEnd = XAStart + 44100;
854 CDDAStart = // alloc cdda buffer
855 (uint32_t *)malloc(16384 * sizeof(uint32_t));
856 CDDAEnd = CDDAStart + 16384;
857 CDDAPlay = CDDAStart;
858 CDDAFeed = CDDAStart;
860 for(i=0;i<MAXCHAN;i++) // loop sound channels
862 // we don't use mutex sync... not needed, would only
864 // s_chan[i].hMutex=CreateMutex(NULL,FALSE,NULL);
865 s_chan[i].ADSRX.SustainLevel = 0xf; // -> init sustain
866 s_chan[i].pLoop=spuMemC;
867 s_chan[i].pStart=spuMemC;
868 s_chan[i].pCurr=spuMemC;
871 pMixIrq=spuMemC; // enable decoded buffer irqs by setting the address
874 // REMOVESTREAMS: free most buffer
875 void RemoveStreams(void)
877 free(pSpuBuffer); // free mixing buffer
879 free(sRVBStart); // free reverb buffer
881 free(XAStart); // free XA buffer
883 free(CDDAStart); // free CDDA buffer
889 // SPUINIT: this func will be called first by the main emu
890 long CALLBACK SPUinit(void)
892 spuMemC = (unsigned char *)spuMem; // just small setup
893 memset((void *)&rvb, 0, sizeof(REVERBInfo));
899 spuAddr = 0xffffffff;
902 spuMemC = (unsigned char *)spuMem;
904 memset((void *)s_chan, 0, (MAXCHAN + 1) * sizeof(SPUCHAN));
909 //ReadConfigSPU(); // read user stuff
910 SetupStreams(); // prepare streaming
915 // SPUOPEN: called by main emu after init
916 long CALLBACK SPUopen(void)
918 if (bSPUIsOpen) return 0; // security for some stupid main emus
920 SetupSound(); // setup sound (before init!)
921 SetupTimer(); // timer for feeding data
925 return PSE_SPU_ERR_SUCCESS;
928 // SPUCLOSE: called before shutdown
929 long CALLBACK SPUclose(void)
931 if (!bSPUIsOpen) return 0; // some security
933 bSPUIsOpen = 0; // no more open
935 RemoveTimer(); // no more feeding
936 RemoveSound(); // no more sound handling
941 // SPUSHUTDOWN: called by main emu on final exit
942 long CALLBACK SPUshutdown(void)
945 RemoveStreams(); // no more streaming
950 // SPUTEST: we don't test, we are always fine ;)
951 long CALLBACK SPUtest(void)
956 // SPUCONFIGURE: call config dialog
957 long CALLBACK SPUconfigure(void)
962 // StartCfgTool("CFG");
967 // SPUABOUT: show about window
968 void CALLBACK SPUabout(void)
973 // StartCfgTool("ABOUT");
978 // this functions will be called once,
979 // passes a callback that should be called on SPU-IRQ/cdda volume change
980 void CALLBACK SPUregisterCallback(void (CALLBACK *callback)(void))
982 irqCallback = callback;
985 void CALLBACK SPUregisterCDDAVolume(void (CALLBACK *CDDAVcallback)(unsigned short,unsigned short))
987 cddavCallback = CDDAVcallback;
990 // COMMON PLUGIN INFO FUNCS
992 char * CALLBACK PSEgetLibName(void)
994 return _(libraryName);
997 unsigned long CALLBACK PSEgetLibType(void)
1002 unsigned long CALLBACK PSEgetLibVersion(void)
1004 return (1 << 16) | (6 << 8);
1007 char * SPUgetLibInfos(void)
1009 return _(libraryInfo);
1013 // vim:shiftwidth=1:expandtab