changeset 214:03d9180e3c87 trunk

[svn] Implement GBS playback.
author chainsaw
date Sun, 20 Nov 2005 11:18:16 -0800
parents ab8ce2fb05d0
children 84162f8f2164
files Plugins/Input/console/Audacious_Driver.cpp Plugins/Input/console/Audacious_Driver.h
diffstat 2 files changed, 92 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/Input/console/Audacious_Driver.cpp	Sun Nov 20 10:57:10 2005 -0800
+++ b/Plugins/Input/console/Audacious_Driver.cpp	Sun Nov 20 11:18:16 2005 -0800
@@ -35,11 +35,13 @@
 
 static Spc_Emu *spc = NULL;
 static Nsf_Emu *nsf = NULL;
+static Gbs_Emu *gbs = NULL;
 static GThread *decode_thread;
 GStaticMutex playback_mutex = G_STATIC_MUTEX_INIT;
 
 static void *play_loop_spc(gpointer arg);
 static void *play_loop_nsf(gpointer arg);
+static void *play_loop_gbs(gpointer arg);
 static void console_init(void);
 extern "C" void console_aboutbox(void);
 static void console_stop(void);
@@ -61,6 +63,8 @@
 			return PLAY_TYPE_SPC;
 		if (!strcasecmp(ext, ".nsf"))
 			return PLAY_TYPE_NSF;
+		if (!strcasecmp(ext, ".gbs"))
+			return PLAY_TYPE_GBS;
 	}
 
 	return 0;
@@ -106,6 +110,13 @@
 	return title;
 }
 
+static gchar *get_title_gbs(gchar *filename)
+{
+	gchar *title;
+	title = g_path_get_basename(filename);
+	return title;
+}
+
 static gchar *get_title(gchar *filename)
 {
 	switch (is_our_file(filename))
@@ -116,6 +127,9 @@
 		case PLAY_TYPE_NSF:
 			return get_title_nsf(filename);
 			break;
+		case PLAY_TYPE_GBS:
+			return get_title_gbs(filename);
+			break;
 	}
 
 	return NULL;
@@ -213,6 +227,47 @@
 	decode_thread = g_thread_create(play_loop_nsf, nsf, TRUE, NULL);
 }
 
+static void play_file_gbs(char *filename)
+{
+	gchar *name;
+	Emu_Std_Reader reader;
+	Gbs_Emu::header_t header;
+	gint samplerate;
+
+	if (audcfg.resample == TRUE)
+		samplerate = audcfg.resample_rate;
+	else
+		samplerate = 44100;
+
+	reader.open(filename);
+	reader.read(&header, sizeof(header));
+
+	gbs = new Gbs_Emu;
+	gbs->init(samplerate);
+	gbs->load(header, reader);
+	gbs->start_track(0);
+
+	console_ip_is_going = TRUE;
+
+	name = get_title(filename);
+
+	if (audcfg.loop_length)
+		console_ip.set_info(name, audcfg.loop_length * 1000, 
+			gbs->voice_count() * 1000, samplerate, 2);
+	else
+		console_ip.set_info(name, -1, nsf->voice_count() * 1000,
+			samplerate, 2);
+
+	g_free(name);
+
+        if (!console_ip.output->open_audio(MY_FMT, samplerate, 2))
+                 return;
+
+	playing_type = PLAY_TYPE_GBS;
+
+	decode_thread = g_thread_create(play_loop_gbs, gbs, TRUE, NULL);
+}
+
 static void play_file(char *filename)
 {
 	switch (is_our_file(filename))
@@ -223,6 +278,9 @@
 		case PLAY_TYPE_NSF:
 			play_file_nsf(filename);
 			break;
+		case PLAY_TYPE_GBS:
+			play_file_gbs(filename);
+			break;
 	}
 }
 
@@ -342,6 +400,39 @@
         return NULL;
 }
 
+static void *play_loop_gbs(gpointer arg)
+{
+	g_static_mutex_lock(&playback_mutex);
+	Gbs_Emu *my_gbs = (Gbs_Emu *) arg;
+        Music_Emu::sample_t buf[1024];
+
+	for (;;)
+	{
+		if (!console_ip_is_going)
+			break;
+
+		my_gbs->play(1024, buf);
+
+		if ((console_ip.output->output_time() / 1000) > 
+			audcfg.loop_length && audcfg.loop_length != 0)
+			break;
+		console_ip.add_vis_pcm(console_ip.output->written_time(),
+			MY_FMT, 1, 2048, buf);
+	        while(console_ip.output->buffer_free() < 2048)
+			xmms_usleep(10000);
+		console_ip.output->write_audio(buf, 2048);
+	}
+
+        delete gbs;
+        console_ip.output->close_audio();
+	console_ip_is_going = FALSE;
+	playing_type = PLAY_TYPE_NONE;
+	g_static_mutex_unlock(&playback_mutex);
+        g_thread_exit(NULL);
+
+        return NULL;
+}
+
 static int get_time(void)
 {
 	if (console_ip_is_going == TRUE)
--- a/Plugins/Input/console/Audacious_Driver.h	Sun Nov 20 10:57:10 2005 -0800
+++ b/Plugins/Input/console/Audacious_Driver.h	Sun Nov 20 11:18:16 2005 -0800
@@ -53,7 +53,7 @@
 #define PLAY_TYPE_SPC		1
 #define PLAY_TYPE_NSF		2
 #define PLAY_TYPE_VGM		3
-#define PLAY_TIME_GBS		4
+#define PLAY_TYPE_GBS		4
 #define PLAY_TYPE_GYM		5
 
 #endif