changeset 2742:fd5373830ac1

Initial plugin. Don't use this unless you like aud to use 100% cpu.
author William Pitcock <nenolod@atheme.org>
date Mon, 30 Jun 2008 22:12:23 -0500
parents f16fdcabe069
children f0547285577e
files src/psf2/Makefile src/psf2/eng_protos.h src/psf2/eng_psf2.c src/psf2/oss.c src/psf2/peops2/spu.c src/psf2/peops2/spu.h src/psf2/plugin.c
diffstat 7 files changed, 131 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/src/psf2/Makefile	Mon Jun 30 21:15:45 2008 -0500
+++ b/src/psf2/Makefile	Mon Jun 30 22:12:23 2008 -0500
@@ -1,9 +1,7 @@
-PROG = psf2
-#PLUGIN = psf2${PLUGIN_SUFFIX}
+PLUGIN = psf2${PLUGIN_SUFFIX}
 
 SRCS = corlett.c \
        plugin.c \
-       oss.c \
        psx.c \
        psx_hw.c \
        eng_psf.c \
--- a/src/psf2/eng_protos.h	Mon Jun 30 21:15:45 2008 -0500
+++ b/src/psf2/eng_protos.h	Mon Jun 30 22:12:23 2008 -0500
@@ -5,49 +5,15 @@
 // (C) 2000-2007 Richard F. Bannister
 //
 
+#include <audacious/plugin.h>
+
 //
 // eng_protos.h
 //
 
-int32 psf_start(uint8 *, uint32 length);
-int32 psf_gen(int16 *, uint32);
-int32 psf_stop(void);
-int32 psf_command(int32, int32);
-int32 psf_fill_info(ao_display_info *);
-
 int32 psf2_start(uint8 *, uint32 length);
-int32 psf2_gen(int16 *, uint32);
+int32 psf2_execute(InputPlayback *playback);
 int32 psf2_stop(void);
 int32 psf2_command(int32, int32);
 int32 psf2_fill_info(ao_display_info *);
 
-int32 qsf_start(uint8 *, uint32 length);
-int32 qsf_gen(int16 *, uint32);
-int32 qsf_stop(void);
-int32 qsf_command(int32, int32);
-int32 qsf_fill_info(ao_display_info *);
-
-int32 ssf_start(uint8 *, uint32 length);
-int32 ssf_gen(int16 *, uint32);
-int32 ssf_stop(void);
-int32 ssf_command(int32, int32);
-int32 ssf_fill_info(ao_display_info *);
-
-int32 spu_start(uint8 *, uint32 length);
-int32 spu_gen(int16 *, uint32);
-int32 spu_stop(void);
-int32 spu_command(int32, int32);
-int32 spu_fill_info(ao_display_info *);
-
-uint8 qsf_memory_read(uint16 addr);
-uint8 qsf_memory_readop(uint16 addr);
-uint8 qsf_memory_readport(uint16 addr);
-void qsf_memory_write(uint16 addr, uint8 byte);
-void qsf_memory_writeport(uint16 addr, uint8 byte);
-
-int32 dsf_start(uint8 *, uint32 length);
-int32 dsf_gen(int16 *, uint32);
-int32 dsf_stop(void);
-int32 dsf_command(int32, int32);
-int32 dsf_fill_info(ao_display_info *);
-
--- a/src/psf2/eng_psf2.c	Mon Jun 30 21:15:45 2008 -0500
+++ b/src/psf2/eng_psf2.c	Mon Jun 30 22:12:23 2008 -0500
@@ -586,20 +586,13 @@
 	return AO_SUCCESS;
 }
 
-void ps2_update(unsigned char *pSound, long lBytes)
-{
-	memcpy(spu_pOutput, pSound, lBytes);	// (for direct 44.1kHz output)
-}
-
-int32 psf2_gen(int16 *buffer, uint32 samples)
+int32 psf2_execute(InputPlayback *playback)
 {	
 	int i;
 
-	spu_pOutput = (char *)buffer;
-
-	for (i = 0; i < samples; i++)
+	for (i = 0; i < 44100 / 60; i++)
 	{
-		SPU2async(1);
+		SPU2async(1, playback);
 		ps2_hw_slice();
 	}
 
--- a/src/psf2/oss.c	Mon Jun 30 21:15:45 2008 -0500
+++ b/src/psf2/oss.c	Mon Jun 30 22:12:23 2008 -0500
@@ -53,7 +53,7 @@
 static int hw_present;
 
 static INT32 is_broken_driver;
-int nDSoundSegLen = 0;
+int nDSoundSegLen = 44100 / 60;
 int oss_nw = 0;
 
 int audiofd;
--- a/src/psf2/peops2/spu.c	Mon Jun 30 21:15:45 2008 -0500
+++ b/src/psf2/peops2/spu.c	Mon Jun 30 22:12:23 2008 -0500
@@ -168,7 +168,7 @@
 static int lastns=0;       // last ns pos
 static int iSecureStart=0; // secure start counter
 
-extern void ps2_update(unsigned char *samples, long lBytes);
+extern void psf2_update(unsigned char *samples, long lBytes, void *data);
 
 ////////////////////////////////////////////////////////////////////////
 // CODE AREA
@@ -359,7 +359,7 @@
 
 int iSpuAsyncWait=0;
 
-static void *MAINThread(int samp2run)
+static void *MAINThread(int samp2run, void *data)
 {
  int s_1,s_2,fa,voldiv=iVolume;
  unsigned char * start;unsigned int nSample;
@@ -762,7 +762,7 @@
   // wanna have around 1/60 sec (16.666 ms) updates
 	if ((((unsigned char *)pS)-((unsigned char *)pSpuBuffer)) == (735*4))
 	{
-	    	ps2_update((u8*)pSpuBuffer,(u8*)pS-(u8*)pSpuBuffer);
+	    	psf2_update((u8*)pSpuBuffer,(u8*)pS-(u8*)pSpuBuffer, data);
 	        pS=(short *)pSpuBuffer;					  
 	}
  }
@@ -783,7 +783,7 @@
 //  1 time every 'cycle' cycles... harhar
 ////////////////////////////////////////////////////////////////////////
 
-EXPORT_GCC void CALLBACK SPU2async(unsigned long cycle)
+EXPORT_GCC void CALLBACK SPU2async(unsigned long cycle, void *data)
 {
  if(iSpuAsyncWait)
   {
@@ -792,7 +792,7 @@
    iSpuAsyncWait=0;
   }
 
-   MAINThread(0);                                      // -> linux high-compat mode
+ MAINThread(0, data);                                      // -> linux high-compat mode
 }
 
 ////////////////////////////////////////////////////////////////////////
--- a/src/psf2/peops2/spu.h	Mon Jun 30 21:15:45 2008 -0500
+++ b/src/psf2/peops2/spu.h	Mon Jun 30 22:12:23 2008 -0500
@@ -34,6 +34,6 @@
 
 EXPORT_GCC long CALLBACK SPU2init(void);
 EXPORT_GCC long CALLBACK SPU2open(void *pDsp);
-EXPORT_GCC void CALLBACK SPU2async(unsigned long cycle);
-EXPORT_GCC void CALLBACK SPU2close(void);
-
+EXPORT_GCC void CALLBACK SPU2async(unsigned long cycle, void *);
+EXPORT_GCC void CALLBACK SPU2close(void);
+
--- a/src/psf2/plugin.c	Mon Jun 30 21:15:45 2008 -0500
+++ b/src/psf2/plugin.c	Mon Jun 30 22:12:23 2008 -0500
@@ -28,6 +28,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <audacious/plugin.h>
+
 #include "ao.h"
 #include "eng_protos.h"
 
@@ -39,14 +41,13 @@
 	uint32 sig; 
 	char *name; 
 	int32 (*start)(uint8 *, uint32); 
-	int32 (*gen)(int16 *, uint32); 
 	int32 (*stop)(void); 
 	int32 (*command)(int32, int32); 
 	uint32 rate; 
 	int32 (*fillinfo)(ao_display_info *); 
 } types[] = {
-	{ 0x50534602, "Sony PlayStation 2 (.psf2)", psf2_start, psf2_gen, psf2_stop, psf2_command, 60, psf2_fill_info },
-	{ 0xffffffff, "", NULL, NULL, NULL, NULL, 0, NULL }
+	{ 0x50534602, "Sony PlayStation 2 (.psf2)", psf2_start, psf2_stop, psf2_command, 60, psf2_fill_info },
+	{ 0xffffffff, "", NULL, NULL, NULL, 0, NULL }
 };
 
 static char *path;
@@ -56,14 +57,14 @@
 {
 	uint8 *filebuf;
 	uint32 size;
-	FILE *auxfile;
+	VFSFile *auxfile;
 
-	auxfile = fopen(filename, "rb");
+	auxfile = aud_vfs_fopen(filename, "rb");
 	if (!auxfile)
 	{
 		char buf[PATH_MAX];
 		snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename);
-		auxfile = fopen(buf, "rb");
+		auxfile = aud_vfs_fopen(buf, "rb");
 
 		if (!auxfile)
 		{
@@ -72,21 +73,21 @@
 		}
 	}
 
-	fseek(auxfile, 0, SEEK_END);
-	size = ftell(auxfile);
-	fseek(auxfile, 0, SEEK_SET);
+	aud_vfs_fseek(auxfile, 0, SEEK_END);
+	size = aud_vfs_ftell(auxfile);
+	aud_vfs_fseek(auxfile, 0, SEEK_SET);
 
 	filebuf = malloc(size);
 
 	if (!filebuf)
 	{
-		fclose(auxfile);
+		aud_vfs_fclose(auxfile);
 		printf("ERROR: could not allocate %d bytes of memory\n", size);
 		return AO_FAIL;
 	}
 
-	fread(filebuf, size, 1, auxfile);
-	fclose(auxfile);
+	aud_vfs_fread(filebuf, size, 1, auxfile);
+	aud_vfs_fclose(auxfile);
 
 	*buffer = filebuf;
 	*length = (uint64)size;
@@ -94,39 +95,37 @@
 	return AO_SUCCESS;
 }
 
-int main(int argv, char *argc[])
+void psf2_play(InputPlayback *data)
 {
-	FILE *file;
+	VFSFile *file;
 	uint8 *buffer;
 	uint32 size, filesig;
 
-	path = strdup(argc[1]);
-	file = fopen(argc[1], "rb");
+	path = strdup(data->filename);
+	file = aud_vfs_fopen(data->filename, "rb");
 
 	if (!file)
 	{
-		printf("ERROR: could not open file %s\n", argc[1]);
-		return -1;
+		printf("ERROR: could not open file %s\n", data->filename);
+		return;
 	}
 
-	// get the length of the file by seeking to the end then reading the current position
-	fseek(file, 0, SEEK_END);
-	size = ftell(file);
-	// reset the pointer
-	fseek(file, 0, SEEK_SET);
+	aud_vfs_fseek(file, 0, SEEK_END);
+	size = aud_vfs_ftell(file);
+	aud_vfs_fseek(file, 0, SEEK_SET);
 
 	buffer = malloc(size);
 
 	if (!buffer)
 	{
-		fclose(file);
+		aud_vfs_fclose(file);
 		printf("ERROR: could not allocate %d bytes of memory\n", size);
-		return -1;
+		return;
 	}
 
 	// read the file
-	fread(buffer, size, 1, file);
-	fclose(file);
+	aud_vfs_fread(buffer, size, 1, file);
+	aud_vfs_fclose(file);
 
 	// now try to identify the file
 	type = 0;
@@ -148,26 +147,107 @@
 	{
 		printf("ERROR: File is unknown, signature bytes are %02x %02x %02x %02x\n", buffer[0], buffer[1], buffer[2], buffer[3]);
 		free(buffer);
-		return -1;
+		return;
 	}
 
 	if (psf2_start(buffer, size) != AO_SUCCESS)
 	{
 		free(buffer);
 		printf("ERROR: Engine rejected file!\n");
-		return -1;
+		return;
 	}
 	
-	m1sdr_Init(44100);
-	m1sdr_SetCallback(psf2_gen);
+	data->output->open_audio(FMT_S16_NE, 44100, 2);
 
-	while (1)
+	data->playing = TRUE;
+	data->set_pb_ready(data);
+	while (data->playing)
 	{
-		m1sdr_TimeCheck();
-	}		
+		psf2_execute(data);
+	}	
 
 	free(buffer);
+}
 
-	return 1;
+void psf2_update(unsigned char *buffer, long count, InputPlayback *playback)
+{
+	const int mask = ~((((16 / 8) * 2)) - 1);
+
+	while (count > 0)
+	{
+		int t = playback->output->buffer_free() & mask;
+		if (t > count)
+			playback->pass_audio(playback, FMT_S16_NE, 2, count, buffer, NULL);
+		else
+		{
+			if (t)
+				playback->pass_audio(playback, FMT_S16_NE, 2, t, buffer, NULL);
+
+			g_usleep((count-t)*1000*5/441/2);
+		}
+		count -= t;
+		buffer += t;
+	}
+
+#if 0
+    if (seek)
+    {
+        if(sexypsf_seek(seek))
+        {
+            playback->output->flush(seek);
+            seek = 0;
+        }
+        else  // negative time - must make a C time machine
+        {
+            sexypsf_stop();
+            return;
+        }
+    }
+    if (stop)
+        sexypsf_stop();
+#endif
 }
 
+void psf2_Stop(InputPlayback *playback)
+{
+	playback->playing = FALSE;
+}
+
+void psf2_pause(InputPlayback *playback, short p)
+{
+	playback->output->pause(p);
+}
+
+static int
+is_our_fd(gchar *filename, VFSFile *file)
+{
+	gchar magic[4];
+	aud_vfs_fread(magic, 1, 4, file);
+
+	if (!memcmp(magic, "PSF\x02", 4))
+		return 1;
+
+	return 0;
+}
+
+gchar *psf2_fmts[] = { "psf2", "minipsf2", NULL };
+
+InputPlugin psf2_ip =
+{
+    .description = "PSF2 Audio Plugin",
+    .play_file = psf2_play,
+    .stop = psf2_Stop,
+    .pause = psf2_pause,
+#if 0
+    .seek = sexypsf_xmms_seek,
+    .get_song_info = sexypsf_xmms_getsonginfo,
+    .get_song_tuple = get_aud_tuple_psf,
+#endif
+    .is_our_file_from_vfs = is_our_fd,
+    .vfs_extensions = psf2_fmts,
+};
+
+InputPlugin *psf2_iplist[] = { &psf2_ip, NULL };
+
+DECLARE_PLUGIN(psf2, NULL, NULL, psf2_iplist, NULL, NULL, NULL, NULL, NULL);
+