summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-09-07 14:48:00 +0000
committerSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-09-07 14:48:00 +0000
commit1f60537347e86ff502d12b0a15efa78ac4624a90 (patch)
treef28cd5bab565c5bd33b82bc9102c92b33e142f40 /plugins
parent1b9c28ab153d51c5591a8c82105e141c0de55352 (diff)
downloadpcsxr-1f60537347e86ff502d12b0a15efa78ac4624a90.tar.gz
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@29192 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins')
-rw-r--r--plugins/dfsound/alsa.c130
-rw-r--r--plugins/dfsound/cfg.c4
-rw-r--r--plugins/dfsound/externals.h14
-rw-r--r--plugins/dfsound/spu.c46
-rw-r--r--plugins/dfsound/spu.h1
-rw-r--r--plugins/dfsound/stdafx.h2
-rw-r--r--plugins/dfsound/xa.c38
-rw-r--r--plugins/dfsound/xa.h1
8 files changed, 71 insertions, 165 deletions
diff --git a/plugins/dfsound/alsa.c b/plugins/dfsound/alsa.c
index 90ce26b8..67b10396 100644
--- a/plugins/dfsound/alsa.c
+++ b/plugins/dfsound/alsa.c
@@ -30,86 +30,6 @@
static snd_pcm_t *handle = NULL;
static snd_pcm_uframes_t buffer_size;
-static snd_pcm_t *handle_cdda = NULL;
-
-// SETUP CDDA SOUND
-void SetupCDDASound(void)
-{
- snd_pcm_hw_params_t *hwparams;
- unsigned int pspeed;
- int pchannels = 2;
- int format;
- unsigned int buffer_time = 500000;
- unsigned int period_time = buffer_time / 4;
- int err;
-
- pspeed = 44100;
- format = SND_PCM_FORMAT_S16_LE;
-
- if ((err = snd_pcm_open(&handle_cdda, "default",
- SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0)
- {
- printf("Audio open error: %s\n", snd_strerror(err));
- return;
- }
-
- if((err = snd_pcm_nonblock(handle_cdda, 0))<0)
- {
- printf("Can't set blocking moded: %s\n", snd_strerror(err));
- return;
- }
-
- snd_pcm_hw_params_alloca(&hwparams);
-
- if((err=snd_pcm_hw_params_any(handle_cdda, hwparams))<0)
- {
- printf("Broken configuration for this PCM: %s\n", snd_strerror(err));
- return;
- }
-
- if((err=snd_pcm_hw_params_set_access(handle_cdda, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED))<0)
- {
- printf("Access type not available: %s\n", snd_strerror(err));
- return;
- }
-
- if((err=snd_pcm_hw_params_set_format(handle_cdda, hwparams, format))<0)
- {
- printf("Sample format not available: %s\n", snd_strerror(err));
- return;
- }
-
- if((err=snd_pcm_hw_params_set_channels(handle_cdda, hwparams, pchannels))<0)
- {
- printf("Channels count not available: %s\n", snd_strerror(err));
- return;
- }
-
- if((err=snd_pcm_hw_params_set_rate_near(handle_cdda, hwparams, &pspeed, 0))<0)
- {
- printf("Rate not available: %s\n", snd_strerror(err));
- return;
- }
-
- if((err=snd_pcm_hw_params_set_buffer_time_near(handle_cdda, hwparams, &buffer_time, 0))<0)
- {
- printf("Buffer time error: %s\n", snd_strerror(err));
- return;
- }
-
- if((err=snd_pcm_hw_params_set_period_time_near(handle_cdda, hwparams, &period_time, 0))<0)
- {
- printf("Period time error: %s\n", snd_strerror(err));
- return;
- }
-
- if((err=snd_pcm_hw_params(handle_cdda, hwparams))<0)
- {
- printf("Unable to install hw params: %s\n", snd_strerror(err));
- return;
- }
-}
-
// SETUP SOUND
void SetupSound(void)
{
@@ -118,7 +38,7 @@ void SetupSound(void)
unsigned int pspeed;
int pchannels;
int format;
- unsigned int buffer_time = 50000;
+ unsigned int buffer_time = 100000;
unsigned int period_time = buffer_time / 4;
int err;
@@ -199,8 +119,6 @@ void SetupSound(void)
}
buffer_size = snd_pcm_status_get_avail(status);
-
- SetupCDDASound();
}
// REMOVE SOUND
@@ -212,13 +130,6 @@ void RemoveSound(void)
snd_pcm_close(handle);
handle = NULL;
}
-
- if(handle_cdda != NULL)
- {
- snd_pcm_drop(handle_cdda);
- snd_pcm_close(handle_cdda);
- handle_cdda = NULL;
- }
}
// GET BYTES BUFFERED
@@ -248,43 +159,4 @@ void SoundFeedStreamData(unsigned char* pSound,long lBytes)
iDisStereo ? lBytes / 2 : lBytes / 4);
}
-static unsigned char cdda_buf[23520];
-
-// PLAY CDDA CHANNEL
-void CALLBACK SPUplayCDDAchannel(short* pcm, int nbytes)
-{
- int i, size, s;
- unsigned char *p = (unsigned char *)pcm;
-
- if (handle_cdda == NULL) return;
-
- while (nbytes > 0)
- {
- size = nbytes;
- if (size > sizeof(cdda_buf)) size = sizeof(cdda_buf);
-
- for (i = 0; i < size / 4; i++)
- {
- s = (short)(p[i*4] | (p[i*4+1] << 8));
- s *= iLeftXAVol;
- s /= 32767;
- cdda_buf[i*4] = (s & 0xFF);
- cdda_buf[i*4+1] = ((s & 0xFF00) >> 8);
-
- s = (short)(p[i*4+2] | (p[i*4+3] << 8));
- s *= iRightXAVol;
- s /= 32767;
- cdda_buf[i*4+2] = (s & 0xFF);
- cdda_buf[i*4+3] = ((s & 0xFF00) >> 8);
- }
-
- if (snd_pcm_state(handle_cdda) == SND_PCM_STATE_XRUN)
- snd_pcm_prepare(handle_cdda);
- snd_pcm_writei(handle_cdda, cdda_buf, size / 4);
-
- nbytes -= size;
- p += size;
- }
-}
-
#endif
diff --git a/plugins/dfsound/cfg.c b/plugins/dfsound/cfg.c
index f51d3568..6c3069e3 100644
--- a/plugins/dfsound/cfg.c
+++ b/plugins/dfsound/cfg.c
@@ -125,10 +125,6 @@ void ReadConfigFile(void)
// in linux. But timer mode 2 (spuupdate) is safe to use.
if(iUseTimer) iUseTimer=2;
-#ifdef NOTHREADLIB
- iUseTimer=2;
-#endif
-
strcpy(t,"\nSPUIRQWait");p=strstr(pB,t);if(p) {p=strstr(p,"=");len=1;}
if(p) iSPUIRQWait=atoi(p+len);
if(iSPUIRQWait<0) iSPUIRQWait=0;
diff --git a/plugins/dfsound/externals.h b/plugins/dfsound/externals.h
index d736373d..16a7b9c1 100644
--- a/plugins/dfsound/externals.h
+++ b/plugins/dfsound/externals.h
@@ -15,7 +15,8 @@
* *
***************************************************************************/
-#include <stdint.h>
+#include <stdint.h>
+
/////////////////////////////////////////////////////////
// generic defines
/////////////////////////////////////////////////////////
@@ -142,7 +143,6 @@ typedef struct
int iOldNoise; // old noise val for this channel
ADSRInfo ADSR; // active ADSR settings
ADSRInfoEx ADSRX; // next ADSR settings (will be moved to active on sample start)
-
} SPUCHAN;
///////////////////////////////////////////////////////////
@@ -159,7 +159,6 @@ typedef struct
int iRVBLeft;
int iRVBRight;
-
int FB_SRC_A; // (offset)
int FB_SRC_B; // (offset)
int IIR_ALPHA; // (coef.)
@@ -257,10 +256,15 @@ extern xa_decode_t * xapGlobal;
extern uint32_t * XAFeed;
extern uint32_t * XAPlay;
extern uint32_t * XAStart;
-extern uint32_t * XAEnd;
+extern uint32_t * XAEnd;
extern uint32_t XARepeat;
-extern uint32_t XALastVal;
+extern uint32_t XALastVal;
+
+extern uint32_t * CDDAFeed;
+extern uint32_t * CDDAPlay;
+extern uint32_t * CDDAStart;
+extern uint32_t * CDDAEnd;
extern int iLeftXAVol;
extern int iRightXAVol;
diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c
index 93cb2c6a..700af07d 100644
--- a/plugins/dfsound/spu.c
+++ b/plugins/dfsound/spu.c
@@ -86,9 +86,7 @@ int bThreadEnded=0;
int bSpuInit=0;
int bSPUIsOpen=0;
-#ifndef NOTHREADLIB
static pthread_t thread = -1; // thread id (linux)
-#endif
unsigned long dwNewChannel=0; // flags for faster testing, if new channel starts
@@ -662,7 +660,7 @@ ENDX: ;
//---------------------------------------------------//
// mix XA infos (if any)
- if(XAPlay!=XAFeed || XARepeat) MixXA();
+ MixXA();
///////////////////////////////////////////////////////
// mix all channels (including reverb) into one buffer
@@ -799,6 +797,15 @@ void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap)
FeedXA(xap); // call main XA feeder
}
+// CDDA AUDIO
+void CALLBACK SPUplayCDDAchannel(short *pcm, int nbytes)
+{
+ if (!pcm) return;
+ if (nbytes<=0) return;
+
+ FeedCDDA((unsigned char *)pcm, nbytes);
+}
+
// INIT/EXIT STUFF
// SPUINIT: this func will be called first by the main emu
@@ -823,12 +830,10 @@ void SetupTimer(void)
bThreadEnded=0;
bSpuInit=1; // flag: we are inited
-#ifndef NOTHREADLIB
if(!iUseTimer) // linux: use thread
{
pthread_create(&thread, NULL, MAINThread, NULL);
}
-#endif
}
// REMOVETIMER: kill threads/timers
@@ -836,14 +841,12 @@ void RemoveTimer(void)
{
bEndThread=1; // raise flag to end thread
-#ifndef NOTHREADLIB
if(!iUseTimer) // linux tread?
{
int i=0;
while(!bThreadEnded && i<2000) {usleep(1000L);i++;} // -> wait until thread has ended
if(thread!=-1) {pthread_cancel(thread);thread=-1;} // -> cancel thread anyway
}
-#endif
bThreadEnded=0; // no more spu is running
bSpuInit=0;
@@ -865,10 +868,16 @@ void SetupStreams(void)
sRVBPlay = sRVBStart;
XAStart = // alloc xa buffer
- (uint32_t *)malloc(44100*4);
+ (uint32_t *)malloc(44100 * sizeof(uint32_t));
+ XAEnd = XAStart + 44100;
XAPlay = XAStart;
XAFeed = XAStart;
- XAEnd = XAStart + 44100;
+
+ CDDAStart = // alloc cdda buffer
+ (uint32_t *)malloc(16384 * sizeof(uint32_t));
+ CDDAEnd = CDDAStart + 16384;
+ CDDAPlay = CDDAStart;
+ CDDAFeed = CDDAStart + 1;
for(i=0;i<MAXCHAN;i++) // loop sound channels
{
@@ -890,22 +899,13 @@ void SetupStreams(void)
void RemoveStreams(void)
{
free(pSpuBuffer); // free mixing buffer
- pSpuBuffer=NULL;
+ pSpuBuffer = NULL;
free(sRVBStart); // free reverb buffer
- sRVBStart=0;
+ sRVBStart = NULL;
free(XAStart); // free XA buffer
- XAStart=0;
-
-/*
- int i;
- for(i=0;i<MAXCHAN;i++)
- {
- WaitForSingleObject(s_chan[i].hMutex,2000);
- ReleaseMutex(s_chan[i].hMutex);
- if(s_chan[i].hMutex)
- {CloseHandle(s_chan[i].hMutex);s_chan[i].hMutex=0;}
- }
-*/
+ XAStart = NULL;
+ free(CDDAStart); // free CDDA buffer
+ CDDAStart = NULL;
}
// SPUOPEN: called by main emu after init
diff --git a/plugins/dfsound/spu.h b/plugins/dfsound/spu.h
index a6e57b30..8912684b 100644
--- a/plugins/dfsound/spu.h
+++ b/plugins/dfsound/spu.h
@@ -18,3 +18,4 @@
void SetupTimer(void);
void RemoveTimer(void);
void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap);
+void CALLBACK SPUplayCDDAchannel(short *pcm, int bytes); \ No newline at end of file
diff --git a/plugins/dfsound/stdafx.h b/plugins/dfsound/stdafx.h
index ceff1d6b..a17fb186 100644
--- a/plugins/dfsound/stdafx.h
+++ b/plugins/dfsound/stdafx.h
@@ -24,9 +24,7 @@
#include <sys/soundcard.h>
#endif
#include <unistd.h>
-#ifndef NOTHREADLIB
#include <pthread.h>
-#endif
#define RRand(range) (random()%range)
#include <string.h>
#include <sys/time.h>
diff --git a/plugins/dfsound/xa.c b/plugins/dfsound/xa.c
index abd8b461..cea1968f 100644
--- a/plugins/dfsound/xa.c
+++ b/plugins/dfsound/xa.c
@@ -36,6 +36,11 @@ uint32_t * XAEnd = NULL;
uint32_t XARepeat = 0;
uint32_t XALastVal = 0;
+uint32_t * CDDAFeed = NULL;
+uint32_t * CDDAPlay = NULL;
+uint32_t * CDDAStart = NULL;
+uint32_t * CDDAEnd = NULL;
+
int iLeftXAVol = 32767;
int iRightXAVol = 32767;
@@ -48,12 +53,13 @@ static int gauss_window[8] = {0, 0, 0, 0, 0, 0, 0, 0};
#define gvalr(x) gauss_window[4+((gauss_ptr+x)&3)]
////////////////////////////////////////////////////////////////////////
-// MIX XA
+// MIX XA & CDDA
////////////////////////////////////////////////////////////////////////
INLINE void MixXA(void)
{
int ns;
+ uint32_t l;
for(ns=0;ns<NSSIZE && XAPlay!=XAFeed;ns++)
{
@@ -72,6 +78,14 @@ INLINE void MixXA(void)
SSumR[ns]+=(((short)((XALastVal>>16)&0xffff)) * iRightXAVol)/32767;
}
}
+
+ for(ns=0;ns<NSSIZE && CDDAPlay!=CDDAFeed && (CDDAPlay!=CDDAEnd-1||CDDAFeed!=CDDAStart);ns++)
+ {
+ l=*CDDAPlay++;
+ if(CDDAPlay==CDDAEnd) CDDAPlay=CDDAStart;
+ SSumL[ns]+=(((short)(l&0xffff)) * iLeftXAVol)/32767;
+ SSumR[ns]+=(((short)((l>>16)&0xffff)) * iRightXAVol)/32767;
+ }
}
////////////////////////////////////////////////////////////////////////
@@ -358,5 +372,25 @@ INLINE void FeedXA(xa_decode_t *xap)
}
}
-#endif
+////////////////////////////////////////////////////////////////////////
+// FEED CDDA
+////////////////////////////////////////////////////////////////////////
+INLINE void FeedCDDA(unsigned char *pcm, int nBytes)
+{
+ while(nBytes>0)
+ {
+ if(CDDAFeed==CDDAEnd) CDDAFeed=CDDAStart;
+ while(CDDAFeed==CDDAPlay-1||
+ (CDDAFeed==CDDAEnd-1&&CDDAPlay==CDDAStart))
+ {
+ if (!iUseTimer) usleep(1000);
+ else return;
+ }
+ *CDDAFeed++=(*pcm | (*(pcm+1)<<8) | (*(pcm+2)<<16) | (*(pcm+3)<<24));
+ nBytes-=4;
+ pcm+=4;
+ }
+}
+
+#endif
diff --git a/plugins/dfsound/xa.h b/plugins/dfsound/xa.h
index 7fd1a8e7..0928eba2 100644
--- a/plugins/dfsound/xa.h
+++ b/plugins/dfsound/xa.h
@@ -17,3 +17,4 @@
INLINE void MixXA(void);
INLINE void FeedXA(xa_decode_t *xap);
+INLINE void FeedCDDA(unsigned char *pcm, int nBytes);