summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-08-31 11:20:03 +0000
committerSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2009-08-31 11:20:03 +0000
commit507ff7fa3cb06c2c6a1d3665b325ab6c572a2825 (patch)
tree18b489a209c2c46875b78ff15528c89f901a2e6e
parentd772714e45f5cb7db70c284a667eb69867a57e86 (diff)
downloadpcsxr-507ff7fa3cb06c2c6a1d3665b325ab6c572a2825.tar.gz
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@28436 e17a0e51-4ae3-4d35-97c3-1a29b211df97
-rw-r--r--ChangeLog11
-rw-r--r--doc/tweaks.txt7
-rw-r--r--libpcsxcore/cdriso.c130
-rw-r--r--libpcsxcore/cdriso.h1
-rw-r--r--plugins/dfsound/alsa.c6
-rw-r--r--win32/pcsx.dsp4
6 files changed, 127 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index cfc1acad..6be1dc1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+August 30, 2009 Wei Mingzhi <weimingzhi@gmail.com>
+
+ * libpcsxcore/cdriso.c: Implemented CDDA playing via SPUplayCDDAchannel().
+ Now CD tracks can be played directly via a SPU plugin which implements the
+ SPUplayCDDAchannel() function, e.g., spuEternal.
+ * libpcsxcore/cdriso.h: Removed unused prototypes.
+ * doc/tweaks.txt: Removed obsolete information.
+ * win32/pcsx.dsp: Use Multithreaded instead of Singlethreaded.
+ * plugins/dfsound/alsa.c: Set the buffer_time and period_time manually,
+ hopefully the "lagging" issue can be fixed.
+
August 29, 2009 Wei Mingzhi <weimingzhi@gmail.com>
* plugins/dfcdrom/cdr.c: Don't restart the track if play was called with
diff --git a/doc/tweaks.txt b/doc/tweaks.txt
index 4c29ab58..0788302f 100644
--- a/doc/tweaks.txt
+++ b/doc/tweaks.txt
@@ -23,10 +23,3 @@ function. These can all be found at Configuration -> CPU.
* Enable Interpreter CPU:
Enables interpretive emulation.
This is often more compatible, but at the price of emulation speed.
-
-Currently, PCSX-Reloaded does not support CD-DA tracks when loading
-image files. In this case, to experience music in games such as Tekken
-and Wipeout 2097, a CD emulation software should be used in conjunction
-with the emulator. DAEMON Tools (http://www.daemon-tools.cc) and CDEmu
-(http://cdemu.sourceforge.net) were tested to work under Windows and
-GNU/Linux respectively.
diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c
index 94977022..b79359c4 100644
--- a/libpcsxcore/cdriso.c
+++ b/libpcsxcore/cdriso.c
@@ -18,11 +18,17 @@
* 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307 USA. *
***************************************************************************/
-// TODO: implement CDDA support.
-
#include "psxcommon.h"
#include "plugins.h"
+#ifdef _WIN32
+#include <process.h>
+#include <windows.h>
+#else
+#include <pthread.h>
+#include <sys/time.h>
+#endif
+
#define MSF2SECT(m, s, f) (((m) * 60 + (s) - 2) * 75 + (f))
#define btoi(b) ((b) / 16 * 10 + (b) % 16) /* BCD to u_char */
@@ -32,11 +38,22 @@
#define SUB_FRAMESIZE 96
FILE *cdHandle = NULL;
+FILE *cddaHandle = NULL;
FILE *subHandle = NULL;
static unsigned char cdbuffer[DATA_SIZE];
static unsigned char subbuffer[SUB_FRAMESIZE];
+static unsigned char sndbuffer[CD_FRAMESIZE_RAW * 10];
+
+#ifdef _WIN32
+static HANDLE threadid;
+#else
+static pthread_t threadid;
+#endif
+static int initial_offset = 0;
+static int playing = 0;
+
char* CALLBACK CDR__getDriveLetter(void);
long CALLBACK CDR__configure(void);
long CALLBACK CDR__test(void);
@@ -71,17 +88,6 @@ static void sec2msf(unsigned int s, char *msf) {
msf[2] = s;
}
-// get size of a track given the sector
-unsigned int ISOgetTrackLength(unsigned int s) {
- int i = 1;
-
- while ((msf2sec(ti[i].start) < s) && i <= numtracks) {
- i++;
- }
-
- return msf2sec(ti[--i].length);
-}
-
// divide a string of xx:yy:zz into m, s, f
static void tok2msf(char *time, char *msf) {
char *token;
@@ -111,12 +117,103 @@ static void tok2msf(char *time, char *msf) {
}
}
-// start the CDDA playback
-static void startCDDA(unsigned int offset) {
+#ifndef _WIN32
+static long GetTickCount(void) {
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return now.tv_sec * 1000L + now.tv_usec / 1000L;
+}
+#endif
+
+// this thread plays audio data
+#ifdef _WIN32
+static void playthread(void *param)
+#else
+static void *playthread(void *param)
+#endif
+{
+ time_t t;
+ long d;
+
+ t = 0;
+
+ while (playing) {
+ d = (long)t - GetTickCount();
+ if (d > 0) {
+#ifdef _WIN32
+ Sleep(d);
+#else
+ usleep(d);
+#endif
+ }
+
+ t = GetTickCount() + 1000 * (sizeof(sndbuffer) / CD_FRAMESIZE_RAW) / 75;
+
+ if ((d = fread(sndbuffer, 1, sizeof(sndbuffer), cddaHandle)) == 0) {
+ playing = 0;
+ fclose(cddaHandle);
+ cddaHandle = NULL;
+ initial_offset = 0;
+ break;
+ }
+
+ SPU_playCDDAchannel((short *)sndbuffer, d);
+ }
+
+#ifdef _WIN32
+ _endthread();
+#else
+ pthread_exit(0);
+ return NULL;
+#endif
}
// stop the CDDA playback
static void stopCDDA() {
+ if (!playing) {
+ return;
+ }
+
+ playing = 0;
+#ifdef _WIN32
+ WaitForSingleObject(threadid, INFINITE);
+#else
+ pthread_join(threadid, NULL);
+#endif
+
+ if (cddaHandle != NULL) {
+ fclose(cddaHandle);
+ cddaHandle = NULL;
+ }
+
+ initial_offset = 0;
+}
+
+// start the CDDA playback
+static void startCDDA(unsigned int offset) {
+ if (playing) {
+ if (initial_offset == offset) {
+ return;
+ }
+ stopCDDA();
+ }
+
+ cddaHandle = fopen(cdrfilename, "rb");
+ if (cddaHandle == NULL) {
+ return;
+ }
+
+ initial_offset = offset;
+ fseek(cddaHandle, initial_offset, SEEK_SET);
+
+ offset /= CD_FRAMESIZE_RAW;
+
+ playing = 1;
+#ifdef _WIN32
+ threadid = (HANDLE)_beginthread(playthread, 0, NULL);
+#else
+ pthread_create(&threadid, NULL, playthread, NULL);
+#endif
}
// this function tries to get the .toc file of the given .bin
@@ -325,7 +422,7 @@ static int parseccd(const char *isofile) {
}
if (msf2sec(ti[numtracks].gap) != 0) {
- sec2msf(t - msf2sec(ti[numtracks].gap), ti[numtracks].gap);
+ sec2msf(t - msf2sec(ti[numtracks].gap), ti[numtracks].gap);
}
t += msf2sec(ti[numtracks].gap);
@@ -505,7 +602,6 @@ static unsigned char * CALLBACK ISOgetBuffer(void) {
// does NOT uses bcd format
static long CALLBACK ISOplay(unsigned char *time) {
if (SPU_playCDDAchannel != NULL) {
- SysPrintf("Starting cdda-audio (%i:%i:%i)...\n", time[0], time[1], time[2]);
startCDDA(MSF2SECT(time[0], time[1], time[2]) * CD_FRAMESIZE_RAW);
}
return 0;
diff --git a/libpcsxcore/cdriso.h b/libpcsxcore/cdriso.h
index ca5d2bfd..473ff99e 100644
--- a/libpcsxcore/cdriso.h
+++ b/libpcsxcore/cdriso.h
@@ -22,6 +22,5 @@
#define CDRISO_H
int imageReaderInit(void);
-unsigned int ISOgetTrackLength(unsigned int s);
#endif
diff --git a/plugins/dfsound/alsa.c b/plugins/dfsound/alsa.c
index e9ea0a3b..2050c6ad 100644
--- a/plugins/dfsound/alsa.c
+++ b/plugins/dfsound/alsa.c
@@ -39,10 +39,8 @@ void SetupSound(void)
int pspeed;
int pchannels;
int format;
-#if 0
- int buffer_time = 500000;
+ int buffer_time = 50000;
int period_time = buffer_time / 4;
-#endif
int err;
if (iDisStereo) pchannels = 1;
@@ -96,7 +94,6 @@ void SetupSound(void)
return;
}
-#if 0
if((err=snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0))<0)
{
printf("Buffer time error: %s\n", snd_strerror(err));
@@ -108,7 +105,6 @@ void SetupSound(void)
printf("Period time error: %s\n", snd_strerror(err));
return;
}
-#endif
if((err=snd_pcm_hw_params(handle, hwparams))<0)
{
diff --git a/win32/pcsx.dsp b/win32/pcsx.dsp
index dc5b883d..99b5045c 100644
--- a/win32/pcsx.dsp
+++ b/win32/pcsx.dsp
@@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /G6 /Zp16 /W3 /GX /O2 /Op /Ob2 /I "../" /I "./zlib" /I "../libpcsxcore" /I "./glue" /I "./" /I "./gui" /I "./intl" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "__WIN32__" /D "_MSC_VER_" /D PCSX_VERSION=\"1.5\" /D "__i386__" /D "ENABLE_NLS" /D PACKAGE=\"pcsx\" /D inline=__forceinline /FR /FD /Zm200 /c
+# ADD CPP /nologo /G6 /Zp16 /MT /W3 /GX /O2 /Op /Ob2 /I "../" /I "./zlib" /I "../libpcsxcore" /I "./glue" /I "./" /I "./gui" /I "./intl" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "__WIN32__" /D "_MSC_VER_" /D PCSX_VERSION=\"1.5\" /D "__i386__" /D "ENABLE_NLS" /D PACKAGE=\"pcsx\" /D inline=__forceinline /FR /FD /Zm200 /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x408 /d "NDEBUG"
@@ -69,7 +69,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D PCSX_VERSION=\"1.3\" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /GX /ZI /Od /I "../" /I "./zlib" /I "../libpcsxcore" /I "./glue" /I "./" /I "./gui" /I "./intl" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "__WIN32__" /D "__i386__" /D PCSX_VERSION=\"1.5\" /D "ENABLE_NLS" /D PACKAGE=\"pcsx\" /D inline= /FR /FD /GZ /Zm200 /c
+# ADD CPP /nologo /MTd /W3 /GX /ZI /Od /I "../" /I "./zlib" /I "../libpcsxcore" /I "./glue" /I "./" /I "./gui" /I "./intl" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "__WIN32__" /D "__i386__" /D PCSX_VERSION=\"1.5\" /D "ENABLE_NLS" /D PACKAGE=\"pcsx\" /D inline= /FR /FD /GZ /Zm200 /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x408 /d "_DEBUG"