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