Mercurial > audlegacy
annotate Plugins/Input/console/Audacious_Driver.cpp @ 145:8794a4781a15 trunk
[svn] looping stuff
author | nenolod |
---|---|
date | Thu, 10 Nov 2005 17:51:04 -0800 |
parents | 3fb426494de8 |
children | 4309d2df6586 |
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 |
109 | 13 #include <glib.h> |
96 | 14 #include <glib/gi18n.h> |
109 | 15 #include <gtk/gtk.h> |
94 | 16 #include "libaudacious/configfile.h" |
17 #include "libaudacious/util.h" | |
18 #include "libaudacious/titlestring.h" | |
145 | 19 #include "audacious/input.h" |
95 | 20 #include "audacious/output.h" |
145 | 21 #include "audacious/playback.h" |
94 | 22 |
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
23 }; |
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
24 |
145 | 25 struct AudaciousConsoleConfig audcfg = { 180, FALSE, 32000 }; |
26 | |
94 | 27 #include <cstring> |
28 | |
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
29 #ifdef WORDS_BIGENDIAN |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
30 # define MY_FMT FMT_S16_BE |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
31 #else |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
32 # define MY_FMT FMT_S16_LE |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
33 #endif |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
34 |
94 | 35 static Spc_Emu *spc = NULL; |
95 | 36 static GThread *decode_thread; |
37 | |
38 static void *play_loop(gpointer arg); | |
100 | 39 static void console_init(void); |
109 | 40 extern "C" void console_aboutbox(void); |
96 | 41 static void console_stop(void); |
42 static void console_pause(gshort p); | |
43 static int get_time(void); | |
103 | 44 static gboolean console_ip_is_going; |
100 | 45 extern InputPlugin console_ip; |
46 | |
94 | 47 static int is_our_file(gchar *filename) |
48 { | |
49 gchar *ext; | |
50 | |
51 ext = strrchr(filename, '.'); | |
52 | |
53 if (ext) | |
54 { | |
55 if (!strcasecmp(ext, ".spc")) | |
56 return 1; | |
57 } | |
58 | |
59 return 0; | |
60 } | |
61 | |
62 static gchar *get_title(gchar *filename) | |
63 { | |
64 gchar *title; | |
65 Emu_Std_Reader reader; | |
66 Spc_Emu::header_t header; | |
67 | |
68 reader.open(filename); | |
69 reader.read(&header, sizeof(header)); | |
70 | |
104 | 71 if (header.song) |
72 { | |
73 TitleInput *tinput; | |
74 | |
75 tinput = bmp_title_input_new(); | |
76 | |
105
18fe59468510
[svn] Use header.game, over header.author, as most SPC files do not contain the composer information.
nenolod
parents:
104
diff
changeset
|
77 tinput->performer = g_strdup(header.game); |
104 | 78 tinput->album_name = g_strdup(header.game); |
79 tinput->track_name = g_strdup(header.song); | |
94 | 80 |
104 | 81 tinput->file_name = g_path_get_basename(filename); |
82 tinput->file_path = g_path_get_dirname(filename); | |
83 | |
84 title = xmms_get_titlestring(xmms_get_gentitle_format(), | |
85 tinput); | |
86 | |
87 g_free(tinput); | |
88 } | |
89 else | |
90 title = g_strdup(filename); | |
99 | 91 |
94 | 92 return title; |
93 } | |
95 | 94 |
95 static void get_song_info(char *filename, char **title, int *length) | |
96 { | |
97 (*title) = get_title(filename); | |
145 | 98 |
99 if (audcfg.loop_length) | |
100 (*length) = audcfg.loop_length; | |
101 else | |
102 (*length) = -1; | |
95 | 103 } |
104 | |
105 static void play_file(char *filename) | |
106 { | |
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
107 gchar *name; |
95 | 108 Emu_Std_Reader reader; |
109 Spc_Emu::header_t header; | |
110 | |
111 reader.open(filename); | |
112 reader.read(&header, sizeof(header)); | |
113 | |
114 spc = new Spc_Emu; | |
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
115 spc->init(32000); |
95 | 116 spc->load(header, reader); |
117 spc->start_track(0); | |
118 | |
103 | 119 console_ip_is_going = TRUE; |
120 | |
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
121 name = get_title(filename); |
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
122 |
145 | 123 if (audcfg.loop_length) |
124 console_ip.set_info(name, audcfg.loop_length * 1000, | |
125 spc->voice_count(), 32000, 2); | |
126 else | |
127 console_ip.set_info(name, -1, spc->voice_count(), 32000, 2); | |
128 | |
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
129 |
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
130 g_free(name); |
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
131 |
102
de414e40f772
[svn] Normal sound decoding, now to just figure out how to stop the decode_thread when we need to.
nenolod
parents:
101
diff
changeset
|
132 if (!console_ip.output->open_audio(MY_FMT, 32000, 2)) |
100 | 133 return; |
133
3fb426494de8
[svn] Open the output channel before firing up the thread.
nenolod
parents:
109
diff
changeset
|
134 |
3fb426494de8
[svn] Open the output channel before firing up the thread.
nenolod
parents:
109
diff
changeset
|
135 decode_thread = g_thread_create(play_loop, spc, TRUE, NULL); |
95 | 136 } |
137 | |
96 | 138 static void seek(gint time) |
139 { | |
140 // XXX: Not yet implemented | |
141 } | |
142 | |
143 InputPlugin console_ip = { | |
144 NULL, | |
145 NULL, | |
146 NULL, | |
147 console_init, | |
109 | 148 console_aboutbox, |
96 | 149 NULL, |
150 is_our_file, | |
151 NULL, | |
152 play_file, | |
153 console_stop, | |
154 console_pause, | |
155 seek, | |
156 NULL, | |
157 get_time, | |
158 NULL, | |
159 NULL, | |
160 NULL, | |
161 NULL, | |
162 NULL, | |
163 NULL, | |
164 NULL, | |
104 | 165 get_song_info, |
96 | 166 NULL, |
167 NULL | |
168 }; | |
169 | |
170 static void console_stop(void) | |
171 { | |
103 | 172 console_ip_is_going = FALSE; |
96 | 173 g_thread_join(decode_thread); |
174 console_ip.output->close_audio(); | |
175 } | |
176 | |
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
177 extern "C" InputPlugin *get_iplugin_info(void) |
96 | 178 { |
109 | 179 console_ip.description = g_strdup_printf(_("SPC, GYM, NSF, VGM and GBS module decoder")); |
96 | 180 return &console_ip; |
181 } | |
182 | |
183 static void console_pause(gshort p) | |
184 { | |
185 console_ip.output->pause(p); | |
186 } | |
187 | |
95 | 188 static void *play_loop(gpointer arg) |
189 { | |
99 | 190 Spc_Emu *my_spc = (Spc_Emu *) arg; |
108 | 191 Music_Emu::sample_t buf[1024]; |
95 | 192 |
145 | 193 for (;;) |
194 { | |
195 if (!console_ip_is_going) | |
196 break; | |
197 | |
198 my_spc->play(1024, buf); | |
199 | |
200 if ((console_ip.output->output_time() / 1000) > | |
201 audcfg.loop_length && audcfg.loop_length != 0) | |
202 break; | |
100 | 203 console_ip.add_vis_pcm(console_ip.output->written_time(), |
108 | 204 MY_FMT, 1, 2048, buf); |
205 while(console_ip.output->buffer_free() < 2048) | |
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
206 xmms_usleep(10000); |
108 | 207 console_ip.output->write_audio(buf, 2048); |
100 | 208 } |
95 | 209 |
96 | 210 delete spc; |
145 | 211 console_ip.output->close_audio(); |
212 console_ip_is_going = FALSE; | |
96 | 213 g_thread_exit(NULL); |
95 | 214 |
96 | 215 return NULL; |
95 | 216 } |
217 | |
96 | 218 static int get_time(void) |
219 { | |
145 | 220 if (console_ip_is_going == TRUE) |
221 return console_ip.output->output_time(); | |
222 else | |
223 return -1; | |
96 | 224 } |
95 | 225 |
100 | 226 static void console_init(void) |
227 { | |
228 | |
229 } | |
230 | |
109 | 231 extern "C" void console_aboutbox(void) |
232 { | |
233 xmms_show_message(_("About the Console Music Decoder"), | |
234 _("Console music decoder engine based on Game_Music_Emu 0.2.4.\n" | |
235 "Audacious implementation by: William Pitcock <nenolod@nenolod.net>"), | |
236 _("Ok"), | |
237 FALSE, NULL, NULL); | |
238 } |