comparison Plugins/Input/console/Audacious_Driver.cpp @ 477:8fc500c08b61 trunk

[svn] SPC length detection c/o Kiyoshi Aman <kiyoshi.aman -at- gmail.com>
author nenolod
date Thu, 19 Jan 2006 19:31:32 -0800
parents c7191cd6ee8e
children 0b9507985f0d
comparison
equal deleted inserted replaced
476:0389b92ed03f 477:8fc500c08b61
25 25
26 struct AudaciousConsoleConfig audcfg = { 180, FALSE, 32000 }; 26 struct AudaciousConsoleConfig audcfg = { 180, FALSE, 32000 };
27 27
28 #include <cstring> 28 #include <cstring>
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <cstdlib>
31 #include <cctype>
30 32
31 static Spc_Emu *spc = NULL; 33 static Spc_Emu *spc = NULL;
32 static Nsf_Emu *nsf = NULL; 34 static Nsf_Emu *nsf = NULL;
33 static Gbs_Emu *gbs = NULL; 35 static Gbs_Emu *gbs = NULL;
34 static Gym_Emu *gym = NULL; 36 static Gym_Emu *gym = NULL;
79 vfs_fclose(file); 81 vfs_fclose(file);
80 } 82 }
81 return 0; 83 return 0;
82 } 84 }
83 85
86 static gint strtoi(gchar *buf,size_t len) {
87 guint num = 0;
88 while (len && isdigit(*buf)) {
89 num *= 10;
90 num += *buf - '0';
91 buf++;
92 len--;
93 }
94 return num;
95 }
96
84 static gchar *get_title_spc(gchar *filename) 97 static gchar *get_title_spc(gchar *filename)
85 { 98 {
86 gchar *title; 99 gchar *title;
87 Emu_Std_Reader reader; 100 Spc_Reader reader;
88 Spc_Emu::header_t header; 101 Spc_Emu::header_t header;
89 102
90 reader.open(filename); 103 reader.open(filename);
91 reader.read(&header, sizeof(header)); 104 reader.read(&header, sizeof(header));
92 105
255 } 268 }
256 269
257 static void play_file_spc(char *filename) 270 static void play_file_spc(char *filename)
258 { 271 {
259 gchar *name; 272 gchar *name;
260 Emu_Std_Reader reader; 273 Spc_Reader reader;
261 Spc_Emu::header_t header; 274 Spc_Emu::header_t header;
262 gint samplerate; 275 gint samplerate;
263 276
264 if (audcfg.resample == TRUE) 277 if (audcfg.resample == TRUE)
265 samplerate = audcfg.resample_rate; 278 samplerate = audcfg.resample_rate;
276 289
277 console_ip_is_going = TRUE; 290 console_ip_is_going = TRUE;
278 291
279 name = get_title(filename); 292 name = get_title(filename);
280 293
281 if (audcfg.loop_length) 294 spc->length = strtoi(header.len_secs,3);
295
296 if (spc->length > 0)
297 console_ip.set_info(name, spc->length * 1000,
298 spc->voice_count() * 1000, samplerate, 2);
299 else if (audcfg.loop_length)
282 console_ip.set_info(name, audcfg.loop_length * 1000, 300 console_ip.set_info(name, audcfg.loop_length * 1000,
283 spc->voice_count() * 1000, samplerate, 2); 301 spc->voice_count() * 1000, samplerate, 2);
284 else 302 else
285 console_ip.set_info(name, -1, spc->voice_count() * 1000, 303 console_ip.set_info(name, -1, spc->voice_count() * 1000,
286 samplerate, 2); 304 samplerate, 2);
548 if (!console_ip_is_going) 566 if (!console_ip_is_going)
549 break; 567 break;
550 568
551 my_spc->play(1024, buf); 569 my_spc->play(1024, buf);
552 570
571 if ((console_ip.output->output_time() / 1000) >
572 spc->length && spc->length != 0)
573 break;
553 if ((console_ip.output->output_time() / 1000) > 574 if ((console_ip.output->output_time() / 1000) >
554 audcfg.loop_length && audcfg.loop_length != 0) 575 audcfg.loop_length && audcfg.loop_length != 0)
555 break; 576 break;
556 produce_audio(console_ip.output->written_time(), 577 produce_audio(console_ip.output->written_time(),
557 FMT_S16_NE, 1, 2048, buf, NULL); 578 FMT_S16_NE, 1, 2048, buf, NULL);