Mercurial > audlegacy
changeset 334:0daaddb10914 trunk
[svn] Implement GYM playback.
author | chainsaw |
---|---|
date | Sun, 25 Dec 2005 13:31:46 -0800 |
parents | 42cdc99e395a |
children | e089ce1ba088 |
files | Plugins/Input/console/Audacious_Driver.cpp |
diffstat | 1 files changed, 92 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Input/console/Audacious_Driver.cpp Sun Dec 25 13:11:21 2005 -0800 +++ b/Plugins/Input/console/Audacious_Driver.cpp Sun Dec 25 13:31:46 2005 -0800 @@ -36,12 +36,14 @@ static Spc_Emu *spc = NULL; static Nsf_Emu *nsf = NULL; static Gbs_Emu *gbs = NULL; +static Gym_Emu *gym = NULL; static GThread *decode_thread; GStaticMutex playback_mutex = G_STATIC_MUTEX_INIT; static void *play_loop_spc(gpointer arg); static void *play_loop_nsf(gpointer arg); static void *play_loop_gbs(gpointer arg); +static void *play_loop_gym(gpointer arg); static void console_init(void); extern "C" void console_aboutbox(void); static void console_stop(void); @@ -65,6 +67,8 @@ return PLAY_TYPE_NSF; if (!strcasecmp(ext, ".gbs")) return PLAY_TYPE_GBS; + if (!strcasecmp(ext, ".gym")) + return PLAY_TYPE_GYM; } return 0; @@ -117,6 +121,13 @@ return title; } +static gchar *get_title_gym(gchar *filename) +{ + gchar *title; + title = g_path_get_basename(filename); + return title; +} + static gchar *get_title(gchar *filename) { switch (is_our_file(filename)) @@ -130,6 +141,9 @@ case PLAY_TYPE_GBS: return get_title_gbs(filename); break; + case PLAY_TYPE_GYM: + return get_title_gym(filename); + break; } return NULL; @@ -255,7 +269,7 @@ console_ip.set_info(name, audcfg.loop_length * 1000, gbs->voice_count() * 1000, samplerate, 2); else - console_ip.set_info(name, -1, nsf->voice_count() * 1000, + console_ip.set_info(name, -1, gbs->voice_count() * 1000, samplerate, 2); g_free(name); @@ -268,6 +282,47 @@ decode_thread = g_thread_create(play_loop_gbs, gbs, TRUE, NULL); } +static void play_file_gym(char *filename) +{ + gchar *name; + Emu_Std_Reader reader; + Gym_Emu::header_t header; + gint samplerate; + + if (audcfg.resample == TRUE) + samplerate = audcfg.resample_rate; + else + samplerate = 44100; + + reader.open(filename); + reader.read(&header, sizeof(header)); + + gym = new Gym_Emu; + gym->init(samplerate); + gym->load(header, reader); + gym->start_track(0); + + console_ip_is_going = TRUE; + + name = get_title(filename); + + if (audcfg.loop_length) + console_ip.set_info(name, audcfg.loop_length * 1000, + gym->voice_count() * 1000, samplerate, 2); + else + console_ip.set_info(name, -1, gym->voice_count() * 1000, + samplerate, 2); + + g_free(name); + + if (!console_ip.output->open_audio(MY_FMT, samplerate, 2)) + return; + + playing_type = PLAY_TYPE_GYM; + + decode_thread = g_thread_create(play_loop_gym, gym, TRUE, NULL); +} + static void play_file(char *filename) { switch (is_our_file(filename)) @@ -281,6 +336,9 @@ case PLAY_TYPE_GBS: play_file_gbs(filename); break; + case PLAY_TYPE_GYM: + play_file_gym(filename); + break; } } @@ -433,6 +491,39 @@ return NULL; } +static void *play_loop_gym(gpointer arg) +{ + g_static_mutex_lock(&playback_mutex); + Gym_Emu *my_gym = (Gym_Emu *) arg; + Music_Emu::sample_t buf[1024]; + + for (;;) + { + if (!console_ip_is_going) + break; + + my_gym->play(1024, buf); + + if ((console_ip.output->output_time() / 1000) > + audcfg.loop_length && audcfg.loop_length != 0) + break; + console_ip.add_vis_pcm(console_ip.output->written_time(), + MY_FMT, 1, 2048, buf); + while(console_ip.output->buffer_free() < 2048) + xmms_usleep(10000); + console_ip.output->write_audio(buf, 2048); + } + + delete gym; + console_ip.output->close_audio(); + console_ip_is_going = FALSE; + playing_type = PLAY_TYPE_NONE; + g_static_mutex_unlock(&playback_mutex); + g_thread_exit(NULL); + + return NULL; +} + static int get_time(void) { if (console_ip_is_going == TRUE)