Mercurial > audlegacy
annotate Plugins/Input/console/Audacious_Driver.cpp @ 416:cb00a4b01302 trunk
[svn] Convert to produce_audio usage.
| author | chainsaw |
|---|---|
| date | Tue, 10 Jan 2006 16:50:39 -0800 |
| parents | e296500f595a |
| children | 8ddd961ef0ff |
| 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> |
|
319
1e642d74d68c
[svn] Do not abort if libmpc is not found, just disable musepack plugin.
chainsaw
parents:
288
diff
changeset
|
16 #include "libaudacious/configdb.h" |
| 94 | 17 #include "libaudacious/util.h" |
| 18 #include "libaudacious/titlestring.h" | |
|
366
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
19 #include "libaudacious/vfs.h" |
| 145 | 20 #include "audacious/input.h" |
| 95 | 21 #include "audacious/output.h" |
| 288 | 22 #include "libaudcore/playback.h" |
| 94 | 23 |
|
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
24 }; |
|
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
25 |
| 145 | 26 struct AudaciousConsoleConfig audcfg = { 180, FALSE, 32000 }; |
| 27 | |
| 94 | 28 #include <cstring> |
| 213 | 29 #include <stdio.h> |
| 94 | 30 |
|
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
31 #ifdef WORDS_BIGENDIAN |
|
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_BE |
|
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
33 #else |
|
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
34 # 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
|
35 #endif |
|
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
36 |
| 94 | 37 static Spc_Emu *spc = NULL; |
| 213 | 38 static Nsf_Emu *nsf = NULL; |
| 214 | 39 static Gbs_Emu *gbs = NULL; |
| 334 | 40 static Gym_Emu *gym = NULL; |
| 364 | 41 static Vgm_Emu *vgm = NULL; |
| 95 | 42 static GThread *decode_thread; |
| 213 | 43 GStaticMutex playback_mutex = G_STATIC_MUTEX_INIT; |
| 95 | 44 |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
45 static void *play_loop_spc(gpointer arg); |
| 213 | 46 static void *play_loop_nsf(gpointer arg); |
| 214 | 47 static void *play_loop_gbs(gpointer arg); |
| 334 | 48 static void *play_loop_gym(gpointer arg); |
| 364 | 49 static void *play_loop_vgm(gpointer arg); |
| 100 | 50 static void console_init(void); |
| 109 | 51 extern "C" void console_aboutbox(void); |
| 96 | 52 static void console_stop(void); |
| 53 static void console_pause(gshort p); | |
| 54 static int get_time(void); | |
| 103 | 55 static gboolean console_ip_is_going; |
| 100 | 56 extern InputPlugin console_ip; |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
57 static int playing_type; |
| 100 | 58 |
| 94 | 59 static int is_our_file(gchar *filename) |
| 60 { | |
|
366
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
61 VFSFile *file; |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
62 gchar magic[4]; |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
63 if (file = vfs_fopen(filename, "rb")) { |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
64 vfs_fread(magic, 1, 4, file); |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
65 if (!strncmp(magic, "SNES", 4)) { |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
66 vfs_fclose(file); |
| 213 | 67 return PLAY_TYPE_SPC; |
|
366
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
68 } |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
69 if (!strncmp(magic, "NESM", 4)) { |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
70 vfs_fclose(file); |
| 213 | 71 return PLAY_TYPE_NSF; |
|
366
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
72 } |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
73 if (!strncmp(magic, "GYMX", 4)) { |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
74 vfs_fclose(file); |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
75 return PLAY_TYPE_GYM; |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
76 } |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
77 vfs_fclose(file); |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
78 } |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
79 if (file = vfs_fopen(filename, "rb")) { |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
80 vfs_fread(magic, 1, 3, file); |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
81 if (!strncmp(magic, "GBS", 3)) { |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
82 vfs_fclose(file); |
| 214 | 83 return PLAY_TYPE_GBS; |
|
366
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
84 } |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
85 if (!strncmp(magic, "Vgm", 3)) { |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
86 vfs_fclose(file); |
| 364 | 87 return PLAY_TYPE_VGM; |
|
366
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
88 } |
|
4a9139a7b53e
[svn] Use file magic instead of extensions (Phase 2).
chainsaw
parents:
365
diff
changeset
|
89 vfs_fclose(file); |
| 94 | 90 } |
| 91 return 0; | |
| 92 } | |
| 93 | |
| 148 | 94 static gchar *get_title_spc(gchar *filename) |
| 94 | 95 { |
| 96 gchar *title; | |
| 97 Emu_Std_Reader reader; | |
| 98 Spc_Emu::header_t header; | |
| 99 | |
| 100 reader.open(filename); | |
| 101 reader.read(&header, sizeof(header)); | |
| 102 | |
|
363
eaaee9e0519c
[svn] Properly fall back to file name if the tag information is invalid (SPC).
chainsaw
parents:
362
diff
changeset
|
103 if (header.version > 10) |
| 104 | 104 { |
| 105 TitleInput *tinput; | |
| 106 | |
| 107 tinput = bmp_title_input_new(); | |
| 108 | |
|
105
18fe59468510
[svn] Use header.game, over header.author, as most SPC files do not contain the composer information.
nenolod
parents:
104
diff
changeset
|
109 tinput->performer = g_strdup(header.game); |
| 104 | 110 tinput->album_name = g_strdup(header.game); |
| 111 tinput->track_name = g_strdup(header.song); | |
| 94 | 112 |
| 104 | 113 tinput->file_name = g_path_get_basename(filename); |
| 114 tinput->file_path = g_path_get_dirname(filename); | |
| 115 | |
| 116 title = xmms_get_titlestring(xmms_get_gentitle_format(), | |
| 117 tinput); | |
| 118 | |
| 119 g_free(tinput); | |
| 120 } | |
| 121 else | |
| 213 | 122 title = g_path_get_basename(filename); |
| 123 | |
| 124 return title; | |
| 125 } | |
| 99 | 126 |
| 213 | 127 static gchar *get_title_nsf(gchar *filename) |
| 128 { | |
| 129 gchar *title; | |
| 130 title = g_path_get_basename(filename); | |
| 94 | 131 return title; |
| 132 } | |
| 95 | 133 |
| 214 | 134 static gchar *get_title_gbs(gchar *filename) |
| 135 { | |
| 136 gchar *title; | |
| 137 title = g_path_get_basename(filename); | |
| 138 return title; | |
| 139 } | |
| 140 | |
| 334 | 141 static gchar *get_title_gym(gchar *filename) |
| 142 { | |
| 143 gchar *title; | |
| 365 | 144 Emu_Std_Reader reader; |
| 145 Gym_Emu::header_t header; | |
| 146 | |
| 147 reader.open(filename); | |
| 148 reader.read(&header, sizeof(header)); | |
| 149 | |
| 150 if (header.song) | |
| 151 { | |
| 152 TitleInput *tinput; | |
| 153 | |
| 154 tinput = bmp_title_input_new(); | |
| 155 | |
| 156 tinput->performer = g_strdup(header.game); | |
| 157 tinput->album_name = g_strdup(header.game); | |
| 158 tinput->track_name = g_strdup(header.song); | |
| 159 | |
| 160 tinput->file_name = g_path_get_basename(filename); | |
| 161 tinput->file_path = g_path_get_dirname(filename); | |
| 162 | |
| 163 title = xmms_get_titlestring(xmms_get_gentitle_format(), | |
| 164 tinput); | |
| 165 | |
| 166 g_free(tinput); | |
| 167 } | |
| 168 else | |
| 169 title = g_path_get_basename(filename); | |
| 170 | |
| 334 | 171 return title; |
| 172 } | |
| 173 | |
| 364 | 174 static gchar *get_title_vgm(gchar *filename) |
| 175 { | |
| 176 gchar *title; | |
| 177 title = g_path_get_basename(filename); | |
| 178 return title; | |
| 179 } | |
| 180 | |
| 148 | 181 static gchar *get_title(gchar *filename) |
| 182 { | |
| 213 | 183 switch (is_our_file(filename)) |
| 148 | 184 { |
| 213 | 185 case PLAY_TYPE_SPC: |
| 148 | 186 return get_title_spc(filename); |
| 213 | 187 break; |
| 188 case PLAY_TYPE_NSF: | |
| 189 return get_title_nsf(filename); | |
| 190 break; | |
| 214 | 191 case PLAY_TYPE_GBS: |
| 192 return get_title_gbs(filename); | |
| 193 break; | |
| 334 | 194 case PLAY_TYPE_GYM: |
| 195 return get_title_gym(filename); | |
| 196 break; | |
| 364 | 197 case PLAY_TYPE_VGM: |
| 198 return get_title_vgm(filename); | |
| 199 break; | |
| 148 | 200 } |
| 201 | |
| 202 return NULL; | |
| 203 } | |
| 204 | |
| 95 | 205 static void get_song_info(char *filename, char **title, int *length) |
| 206 { | |
| 207 (*title) = get_title(filename); | |
| 145 | 208 |
| 209 if (audcfg.loop_length) | |
| 210 (*length) = audcfg.loop_length; | |
| 211 else | |
| 212 (*length) = -1; | |
| 95 | 213 } |
| 214 | |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
215 static void play_file_spc(char *filename) |
| 95 | 216 { |
|
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
217 gchar *name; |
| 95 | 218 Emu_Std_Reader reader; |
| 219 Spc_Emu::header_t header; | |
| 149 | 220 gint samplerate; |
| 221 | |
| 222 if (audcfg.resample == TRUE) | |
| 223 samplerate = audcfg.resample_rate; | |
| 224 else | |
| 225 samplerate = Spc_Emu::native_sample_rate; | |
| 95 | 226 |
| 227 reader.open(filename); | |
| 228 reader.read(&header, sizeof(header)); | |
| 229 | |
| 230 spc = new Spc_Emu; | |
| 149 | 231 spc->init(samplerate); |
| 95 | 232 spc->load(header, reader); |
| 233 spc->start_track(0); | |
| 234 | |
| 103 | 235 console_ip_is_going = TRUE; |
| 236 | |
|
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
237 name = get_title(filename); |
|
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
238 |
| 145 | 239 if (audcfg.loop_length) |
| 240 console_ip.set_info(name, audcfg.loop_length * 1000, | |
| 149 | 241 spc->voice_count() * 1000, samplerate, 2); |
| 145 | 242 else |
| 149 | 243 console_ip.set_info(name, -1, spc->voice_count() * 1000, |
| 244 samplerate, 2); | |
|
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
245 |
|
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
246 g_free(name); |
|
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
247 |
| 149 | 248 if (!console_ip.output->open_audio(MY_FMT, samplerate, 2)) |
| 100 | 249 return; |
|
133
3fb426494de8
[svn] Open the output channel before firing up the thread.
nenolod
parents:
109
diff
changeset
|
250 |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
251 playing_type = PLAY_TYPE_SPC; |
|
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
252 |
|
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
253 decode_thread = g_thread_create(play_loop_spc, spc, TRUE, NULL); |
|
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
254 } |
|
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
255 |
| 213 | 256 static void play_file_nsf(char *filename) |
| 257 { | |
| 258 gchar *name; | |
| 259 Emu_Std_Reader reader; | |
| 260 Nsf_Emu::header_t header; | |
| 261 gint samplerate; | |
| 262 | |
| 263 if (audcfg.resample == TRUE) | |
| 264 samplerate = audcfg.resample_rate; | |
| 265 else | |
| 266 samplerate = 44100; | |
| 267 | |
| 268 reader.open(filename); | |
| 269 reader.read(&header, sizeof(header)); | |
| 270 | |
| 271 nsf = new Nsf_Emu; | |
| 272 nsf->init(samplerate); | |
| 273 nsf->load(header, reader); | |
| 274 nsf->start_track(0); | |
| 275 | |
| 276 console_ip_is_going = TRUE; | |
| 277 | |
| 278 name = get_title(filename); | |
| 279 | |
| 280 if (audcfg.loop_length) | |
| 281 console_ip.set_info(name, audcfg.loop_length * 1000, | |
| 282 nsf->voice_count() * 1000, samplerate, 2); | |
| 283 else | |
| 284 console_ip.set_info(name, -1, nsf->voice_count() * 1000, | |
| 285 samplerate, 2); | |
| 286 | |
| 287 g_free(name); | |
| 288 | |
| 289 if (!console_ip.output->open_audio(MY_FMT, samplerate, 2)) | |
| 290 return; | |
| 291 | |
| 292 playing_type = PLAY_TYPE_NSF; | |
| 293 | |
| 294 decode_thread = g_thread_create(play_loop_nsf, nsf, TRUE, NULL); | |
| 295 } | |
| 296 | |
| 214 | 297 static void play_file_gbs(char *filename) |
| 298 { | |
| 299 gchar *name; | |
| 300 Emu_Std_Reader reader; | |
| 301 Gbs_Emu::header_t header; | |
| 302 gint samplerate; | |
| 303 | |
| 304 if (audcfg.resample == TRUE) | |
| 305 samplerate = audcfg.resample_rate; | |
| 306 else | |
| 307 samplerate = 44100; | |
| 308 | |
| 309 reader.open(filename); | |
| 310 reader.read(&header, sizeof(header)); | |
| 311 | |
| 312 gbs = new Gbs_Emu; | |
| 313 gbs->init(samplerate); | |
| 314 gbs->load(header, reader); | |
| 315 gbs->start_track(0); | |
| 316 | |
| 317 console_ip_is_going = TRUE; | |
| 318 | |
| 319 name = get_title(filename); | |
| 320 | |
| 321 if (audcfg.loop_length) | |
| 322 console_ip.set_info(name, audcfg.loop_length * 1000, | |
| 323 gbs->voice_count() * 1000, samplerate, 2); | |
| 324 else | |
| 334 | 325 console_ip.set_info(name, -1, gbs->voice_count() * 1000, |
| 214 | 326 samplerate, 2); |
| 327 | |
| 328 g_free(name); | |
| 329 | |
| 330 if (!console_ip.output->open_audio(MY_FMT, samplerate, 2)) | |
| 331 return; | |
| 332 | |
| 333 playing_type = PLAY_TYPE_GBS; | |
| 334 | |
| 335 decode_thread = g_thread_create(play_loop_gbs, gbs, TRUE, NULL); | |
| 336 } | |
| 337 | |
| 334 | 338 static void play_file_gym(char *filename) |
| 339 { | |
| 340 gchar *name; | |
| 341 Emu_Std_Reader reader; | |
| 342 Gym_Emu::header_t header; | |
| 343 gint samplerate; | |
| 344 | |
| 345 if (audcfg.resample == TRUE) | |
| 346 samplerate = audcfg.resample_rate; | |
| 347 else | |
| 348 samplerate = 44100; | |
| 349 | |
| 350 reader.open(filename); | |
| 351 reader.read(&header, sizeof(header)); | |
| 352 | |
| 353 gym = new Gym_Emu; | |
| 354 gym->init(samplerate); | |
| 355 gym->load(header, reader); | |
| 356 gym->start_track(0); | |
| 357 | |
| 358 console_ip_is_going = TRUE; | |
| 359 | |
| 360 name = get_title(filename); | |
| 361 | |
| 362 | 362 if (gym->track_length() > 0) |
| 363 console_ip.set_info(name, gym->track_length() * 1000, | |
| 364 gym->voice_count() * 1000, samplerate, 2); | |
| 365 else if (audcfg.loop_length) | |
| 334 | 366 console_ip.set_info(name, audcfg.loop_length * 1000, |
| 367 gym->voice_count() * 1000, samplerate, 2); | |
| 368 else | |
| 369 console_ip.set_info(name, -1, gym->voice_count() * 1000, | |
| 370 samplerate, 2); | |
| 371 | |
| 372 g_free(name); | |
| 373 | |
| 374 if (!console_ip.output->open_audio(MY_FMT, samplerate, 2)) | |
| 375 return; | |
| 376 | |
| 377 playing_type = PLAY_TYPE_GYM; | |
| 378 | |
| 379 decode_thread = g_thread_create(play_loop_gym, gym, TRUE, NULL); | |
| 380 } | |
| 381 | |
| 364 | 382 static void play_file_vgm(char *filename) |
| 383 { | |
| 384 gchar *name; | |
| 385 Emu_Std_Reader reader; | |
| 386 Vgm_Emu::header_t header; | |
| 387 gint samplerate; | |
| 388 | |
| 389 if (audcfg.resample == TRUE) | |
| 390 samplerate = audcfg.resample_rate; | |
| 391 else | |
| 392 samplerate = 44100; | |
| 393 | |
| 394 reader.open(filename); | |
| 395 reader.read(&header, sizeof(header)); | |
| 396 | |
| 397 vgm = new Vgm_Emu; | |
| 398 vgm->init(samplerate); | |
| 399 vgm->load(header, reader); | |
| 400 vgm->start_track(0); | |
| 401 | |
| 402 console_ip_is_going = TRUE; | |
| 403 | |
| 404 name = get_title(filename); | |
| 405 | |
| 406 if (audcfg.loop_length) | |
| 407 console_ip.set_info(name, audcfg.loop_length * 1000, | |
| 408 vgm->voice_count() * 1000, samplerate, 2); | |
| 409 else | |
| 410 console_ip.set_info(name, -1, vgm->voice_count() * 1000, | |
| 411 samplerate, 2); | |
| 412 | |
| 413 g_free(name); | |
| 414 | |
| 415 if (!console_ip.output->open_audio(MY_FMT, samplerate, 2)) | |
| 416 return; | |
| 417 | |
| 418 playing_type = PLAY_TYPE_VGM; | |
| 419 | |
| 420 decode_thread = g_thread_create(play_loop_vgm, vgm, TRUE, NULL); | |
| 421 } | |
| 422 | |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
423 static void play_file(char *filename) |
|
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
424 { |
| 213 | 425 switch (is_our_file(filename)) |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
426 { |
| 213 | 427 case PLAY_TYPE_SPC: |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
428 play_file_spc(filename); |
| 213 | 429 break; |
| 430 case PLAY_TYPE_NSF: | |
| 431 play_file_nsf(filename); | |
| 432 break; | |
| 214 | 433 case PLAY_TYPE_GBS: |
| 434 play_file_gbs(filename); | |
| 435 break; | |
| 334 | 436 case PLAY_TYPE_GYM: |
| 437 play_file_gym(filename); | |
| 438 break; | |
| 364 | 439 case PLAY_TYPE_VGM: |
| 440 play_file_vgm(filename); | |
| 441 break; | |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
442 } |
| 95 | 443 } |
| 444 | |
| 96 | 445 static void seek(gint time) |
| 446 { | |
| 447 // XXX: Not yet implemented | |
| 448 } | |
| 449 | |
| 450 InputPlugin console_ip = { | |
| 451 NULL, | |
| 452 NULL, | |
| 453 NULL, | |
| 454 console_init, | |
| 109 | 455 console_aboutbox, |
| 96 | 456 NULL, |
| 457 is_our_file, | |
| 458 NULL, | |
| 459 play_file, | |
| 460 console_stop, | |
| 461 console_pause, | |
| 462 seek, | |
| 463 NULL, | |
| 464 get_time, | |
| 465 NULL, | |
| 466 NULL, | |
| 467 NULL, | |
| 468 NULL, | |
| 469 NULL, | |
| 470 NULL, | |
| 471 NULL, | |
| 104 | 472 get_song_info, |
| 96 | 473 NULL, |
| 474 NULL | |
| 475 }; | |
| 476 | |
| 477 static void console_stop(void) | |
| 478 { | |
| 103 | 479 console_ip_is_going = FALSE; |
| 96 | 480 g_thread_join(decode_thread); |
| 481 console_ip.output->close_audio(); | |
| 482 } | |
| 483 | |
|
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
484 extern "C" InputPlugin *get_iplugin_info(void) |
| 96 | 485 { |
| 109 | 486 console_ip.description = g_strdup_printf(_("SPC, GYM, NSF, VGM and GBS module decoder")); |
| 96 | 487 return &console_ip; |
| 488 } | |
| 489 | |
| 490 static void console_pause(gshort p) | |
| 491 { | |
| 492 console_ip.output->pause(p); | |
| 493 } | |
| 494 | |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
495 static void *play_loop_spc(gpointer arg) |
| 95 | 496 { |
| 213 | 497 g_static_mutex_lock(&playback_mutex); |
| 99 | 498 Spc_Emu *my_spc = (Spc_Emu *) arg; |
| 213 | 499 Music_Emu::sample_t buf[1024]; |
| 95 | 500 |
| 145 | 501 for (;;) |
| 502 { | |
| 503 if (!console_ip_is_going) | |
| 504 break; | |
| 505 | |
| 506 my_spc->play(1024, buf); | |
| 507 | |
| 508 if ((console_ip.output->output_time() / 1000) > | |
| 509 audcfg.loop_length && audcfg.loop_length != 0) | |
| 510 break; | |
| 349 | 511 produce_audio(console_ip.output->written_time(), |
| 352 | 512 MY_FMT, 1, 2048, buf, NULL); |
| 108 | 513 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
|
514 xmms_usleep(10000); |
| 100 | 515 } |
| 95 | 516 |
| 96 | 517 delete spc; |
| 145 | 518 console_ip.output->close_audio(); |
| 519 console_ip_is_going = FALSE; | |
|
147
6fe2bfbe6fc2
[svn] Move SPC-specific code into SPC-specific routines.
nenolod
parents:
146
diff
changeset
|
520 playing_type = PLAY_TYPE_NONE; |
| 213 | 521 g_static_mutex_unlock(&playback_mutex); |
| 522 g_thread_exit(NULL); | |
| 523 | |
| 524 return NULL; | |
| 525 } | |
| 526 | |
| 527 static void *play_loop_nsf(gpointer arg) | |
| 528 { | |
| 529 g_static_mutex_lock(&playback_mutex); | |
| 530 Nsf_Emu *my_nsf = (Nsf_Emu *) arg; | |
| 531 Music_Emu::sample_t buf[1024]; | |
| 532 | |
| 533 for (;;) | |
| 534 { | |
| 535 if (!console_ip_is_going) | |
| 536 break; | |
| 537 | |
| 538 my_nsf->play(1024, buf); | |
| 539 | |
| 540 if ((console_ip.output->output_time() / 1000) > | |
| 541 audcfg.loop_length && audcfg.loop_length != 0) | |
| 542 break; | |
| 349 | 543 produce_audio(console_ip.output->written_time(), |
| 352 | 544 MY_FMT, 1, 2048, buf, NULL); |
| 213 | 545 while(console_ip.output->buffer_free() < 2048) |
| 546 xmms_usleep(10000); | |
| 547 } | |
| 548 | |
| 549 delete nsf; | |
| 550 console_ip.output->close_audio(); | |
| 551 console_ip_is_going = FALSE; | |
| 552 playing_type = PLAY_TYPE_NONE; | |
| 553 g_static_mutex_unlock(&playback_mutex); | |
| 96 | 554 g_thread_exit(NULL); |
| 95 | 555 |
| 96 | 556 return NULL; |
| 95 | 557 } |
| 558 | |
| 214 | 559 static void *play_loop_gbs(gpointer arg) |
| 560 { | |
| 561 g_static_mutex_lock(&playback_mutex); | |
| 562 Gbs_Emu *my_gbs = (Gbs_Emu *) arg; | |
| 563 Music_Emu::sample_t buf[1024]; | |
| 564 | |
| 565 for (;;) | |
| 566 { | |
| 567 if (!console_ip_is_going) | |
| 568 break; | |
| 569 | |
| 570 my_gbs->play(1024, buf); | |
| 571 | |
| 572 if ((console_ip.output->output_time() / 1000) > | |
| 573 audcfg.loop_length && audcfg.loop_length != 0) | |
| 574 break; | |
| 349 | 575 produce_audio(console_ip.output->written_time(), |
| 352 | 576 MY_FMT, 1, 2048, buf, NULL); |
| 214 | 577 while(console_ip.output->buffer_free() < 2048) |
| 578 xmms_usleep(10000); | |
| 579 } | |
| 580 | |
| 581 delete gbs; | |
| 582 console_ip.output->close_audio(); | |
| 583 console_ip_is_going = FALSE; | |
| 584 playing_type = PLAY_TYPE_NONE; | |
| 585 g_static_mutex_unlock(&playback_mutex); | |
| 586 g_thread_exit(NULL); | |
| 587 | |
| 588 return NULL; | |
| 589 } | |
| 590 | |
| 334 | 591 static void *play_loop_gym(gpointer arg) |
| 592 { | |
| 593 g_static_mutex_lock(&playback_mutex); | |
| 594 Gym_Emu *my_gym = (Gym_Emu *) arg; | |
| 595 Music_Emu::sample_t buf[1024]; | |
| 596 | |
| 597 for (;;) | |
| 598 { | |
| 599 if (!console_ip_is_going) | |
| 600 break; | |
| 601 | |
| 602 my_gym->play(1024, buf); | |
| 603 | |
| 604 if ((console_ip.output->output_time() / 1000) > | |
|
371
e296500f595a
[svn] Stop GYM playback at the right time, if the length is known.
chainsaw
parents:
366
diff
changeset
|
605 gym->track_length() && gym->track_length() != 0) |
|
e296500f595a
[svn] Stop GYM playback at the right time, if the length is known.
chainsaw
parents:
366
diff
changeset
|
606 break; |
|
e296500f595a
[svn] Stop GYM playback at the right time, if the length is known.
chainsaw
parents:
366
diff
changeset
|
607 if ((console_ip.output->output_time() / 1000) > |
| 334 | 608 audcfg.loop_length && audcfg.loop_length != 0) |
| 609 break; | |
| 349 | 610 produce_audio(console_ip.output->written_time(), |
| 352 | 611 MY_FMT, 1, 2048, buf, NULL); |
| 334 | 612 while(console_ip.output->buffer_free() < 2048) |
| 613 xmms_usleep(10000); | |
| 614 } | |
| 615 | |
| 616 delete gym; | |
| 617 console_ip.output->close_audio(); | |
| 618 console_ip_is_going = FALSE; | |
| 619 playing_type = PLAY_TYPE_NONE; | |
| 620 g_static_mutex_unlock(&playback_mutex); | |
| 621 g_thread_exit(NULL); | |
| 622 | |
| 623 return NULL; | |
| 624 } | |
| 625 | |
| 364 | 626 static void *play_loop_vgm(gpointer arg) |
| 627 { | |
| 628 g_static_mutex_lock(&playback_mutex); | |
| 629 Vgm_Emu *my_vgm = (Vgm_Emu *) arg; | |
| 630 Music_Emu::sample_t buf[1024]; | |
| 631 | |
| 632 for (;;) | |
| 633 { | |
| 634 if (!console_ip_is_going) | |
| 635 break; | |
| 636 | |
| 637 my_vgm->play(1024, buf); | |
| 638 | |
| 639 if ((console_ip.output->output_time() / 1000) > | |
| 640 audcfg.loop_length && audcfg.loop_length != 0) | |
| 641 break; | |
| 642 produce_audio(console_ip.output->written_time(), | |
| 643 MY_FMT, 1, 2048, buf, NULL); | |
| 644 while(console_ip.output->buffer_free() < 2048) | |
| 645 xmms_usleep(10000); | |
| 646 } | |
| 647 | |
| 648 delete vgm; | |
| 649 console_ip.output->close_audio(); | |
| 650 console_ip_is_going = FALSE; | |
| 651 playing_type = PLAY_TYPE_NONE; | |
| 652 g_static_mutex_unlock(&playback_mutex); | |
| 653 g_thread_exit(NULL); | |
| 654 | |
| 655 return NULL; | |
| 656 } | |
| 657 | |
| 96 | 658 static int get_time(void) |
| 659 { | |
| 145 | 660 if (console_ip_is_going == TRUE) |
| 661 return console_ip.output->output_time(); | |
| 662 else | |
| 663 return -1; | |
| 96 | 664 } |
| 95 | 665 |
| 100 | 666 static void console_init(void) |
| 667 { | |
|
319
1e642d74d68c
[svn] Do not abort if libmpc is not found, just disable musepack plugin.
chainsaw
parents:
288
diff
changeset
|
668 ConfigDb *db; |
| 100 | 669 |
|
319
1e642d74d68c
[svn] Do not abort if libmpc is not found, just disable musepack plugin.
chainsaw
parents:
288
diff
changeset
|
670 db = bmp_cfg_db_open(); |
|
150
1997ecd9dcb1
[svn] Add ability to override defaults via .audacious/config until we can get a GUI.
nenolod
parents:
149
diff
changeset
|
671 |
|
319
1e642d74d68c
[svn] Do not abort if libmpc is not found, just disable musepack plugin.
chainsaw
parents:
288
diff
changeset
|
672 bmp_cfg_db_get_int(db, "console", "loop_length", &audcfg.loop_length); |
|
1e642d74d68c
[svn] Do not abort if libmpc is not found, just disable musepack plugin.
chainsaw
parents:
288
diff
changeset
|
673 bmp_cfg_db_get_bool(db, "console", "resample", &audcfg.resample); |
|
1e642d74d68c
[svn] Do not abort if libmpc is not found, just disable musepack plugin.
chainsaw
parents:
288
diff
changeset
|
674 bmp_cfg_db_get_int(db, "console", "resample_rate", &audcfg.resample_rate); |
|
150
1997ecd9dcb1
[svn] Add ability to override defaults via .audacious/config until we can get a GUI.
nenolod
parents:
149
diff
changeset
|
675 |
|
319
1e642d74d68c
[svn] Do not abort if libmpc is not found, just disable musepack plugin.
chainsaw
parents:
288
diff
changeset
|
676 bmp_cfg_db_close(db); |
| 100 | 677 } |
| 678 | |
| 109 | 679 extern "C" void console_aboutbox(void) |
| 680 { | |
| 681 xmms_show_message(_("About the Console Music Decoder"), | |
| 682 _("Console music decoder engine based on Game_Music_Emu 0.2.4.\n" | |
| 683 "Audacious implementation by: William Pitcock <nenolod@nenolod.net>"), | |
| 684 _("Ok"), | |
| 685 FALSE, NULL, NULL); | |
| 686 } |
