Mercurial > audlegacy
annotate Plugins/Input/console/Audacious_Driver.cpp @ 96:8dbd2d31c1f7 trunk
[svn] More work
| author | nenolod |
|---|---|
| date | Tue, 01 Nov 2005 21:23:24 -0800 |
| parents | 8247bbf454a8 |
| children | e42694a28331 |
| rev | line source |
|---|---|
|
90
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
1 /* |
|
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
2 * Audacious: Cross platform multimedia player |
|
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
3 * Copyright (c) 2005 Audacious Team |
|
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
4 * |
|
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
5 * Driver for Game_Music_Emu library. See details at: |
|
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
6 * http://www.slack.net/~ant/libs/ |
|
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
7 */ |
|
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
8 |
| 94 | 9 #include "Audacious_Driver.h" |
|
90
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
10 |
| 96 | 11 #include <glib/gi18n.h> |
| 94 | 12 #include "libaudacious/configfile.h" |
| 13 #include "libaudacious/util.h" | |
| 14 #include "libaudacious/titlestring.h" | |
| 95 | 15 #include "audacious/output.h" |
| 94 | 16 #include <gtk/gtk.h> |
| 17 | |
| 18 #include <cstring> | |
| 19 | |
| 20 static Spc_Emu *spc = NULL; | |
| 95 | 21 static GThread *decode_thread; |
| 22 | |
| 23 static void *play_loop(gpointer arg); | |
| 96 | 24 static void console_stop(void); |
| 25 static void console_pause(gshort p); | |
| 26 static int get_time(void); | |
| 94 | 27 |
| 28 static int is_our_file(gchar *filename) | |
| 29 { | |
| 30 gchar *ext; | |
| 31 | |
| 32 ext = strrchr(filename, '.'); | |
| 33 | |
| 34 if (ext) | |
| 35 { | |
| 36 if (!strcasecmp(ext, ".spc")) | |
| 37 return 1; | |
| 38 } | |
| 39 | |
| 40 return 0; | |
| 41 } | |
| 42 | |
| 43 static gchar *get_title(gchar *filename) | |
| 44 { | |
| 45 gchar *title; | |
| 46 Emu_Std_Reader reader; | |
| 47 Spc_Emu::header_t header; | |
| 48 | |
| 49 reader.open(filename); | |
| 50 reader.read(&header, sizeof(header)); | |
| 51 | |
| 52 title = g_strdup(header.song); | |
| 53 | |
| 54 return title; | |
| 55 } | |
| 95 | 56 |
| 57 static void get_song_info(char *filename, char **title, int *length) | |
| 58 { | |
| 59 (*title) = get_title(filename); | |
| 60 (*length) = -1; | |
| 61 } | |
| 62 | |
| 63 static void play_file(char *filename) | |
| 64 { | |
| 65 Emu_Std_Reader reader; | |
| 66 Spc_Emu::header_t header; | |
| 67 | |
| 68 reader.open(filename); | |
| 69 reader.read(&header, sizeof(header)); | |
| 70 | |
| 71 spc = new Spc_Emu; | |
| 72 spc->init(44100); | |
| 73 spc->load(header, reader); | |
| 74 spc->start_track(0); | |
| 75 | |
| 76 decode_thread = g_thread_create(play_loop, NULL, FALSE, NULL); | |
| 77 } | |
| 78 | |
| 96 | 79 static void seek(gint time) |
| 80 { | |
| 81 // XXX: Not yet implemented | |
| 82 } | |
| 83 | |
| 84 static void console_init(void) | |
| 85 { | |
| 86 // nothing to do here | |
| 87 } | |
| 88 | |
| 89 InputPlugin console_ip = { | |
| 90 NULL, | |
| 91 NULL, | |
| 92 NULL, | |
| 93 console_init, | |
| 94 NULL, | |
| 95 NULL, | |
| 96 is_our_file, | |
| 97 NULL, | |
| 98 play_file, | |
| 99 console_stop, | |
| 100 console_pause, | |
| 101 seek, | |
| 102 NULL, | |
| 103 get_time, | |
| 104 NULL, | |
| 105 NULL, | |
| 106 NULL, | |
| 107 NULL, | |
| 108 NULL, | |
| 109 NULL, | |
| 110 NULL, | |
| 111 NULL, | |
| 112 NULL, | |
| 113 NULL | |
| 114 }; | |
| 115 | |
| 116 static void console_stop(void) | |
| 117 { | |
| 118 g_thread_join(decode_thread); | |
| 119 console_ip.output->close_audio(); | |
| 120 } | |
| 121 | |
| 122 InputPlugin *get_iplugin_info(void) | |
| 123 { | |
| 124 console_ip.description = g_strdup_printf(_("Console music plugin")); | |
| 125 return &console_ip; | |
| 126 } | |
| 127 | |
| 128 static void console_pause(gshort p) | |
| 129 { | |
| 130 console_ip.output->pause(p); | |
| 131 } | |
| 132 | |
| 95 | 133 static void *play_loop(gpointer arg) |
| 134 { | |
| 96 | 135 Music_Emu::sample_t buf[1024]; |
| 95 | 136 |
| 96 | 137 while (spc->play(1024, buf)) |
| 138 { | |
| 139 produce_audio(console_ip.output->written_time(), | |
| 140 FMT_S16_LE, 2, 1024, (char *) buf, | |
| 141 NULL); | |
| 142 xmms_usleep(100000); | |
| 143 } | |
| 95 | 144 |
| 96 | 145 delete spc; |
| 146 g_thread_exit(NULL); | |
| 95 | 147 |
| 96 | 148 return NULL; |
| 95 | 149 } |
| 150 | |
| 96 | 151 static int get_time(void) |
| 152 { | |
| 153 return console_ip.output->output_time(); | |
| 154 } | |
| 95 | 155 |
