Mercurial > audlegacy
annotate Plugins/Input/console/Audacious_Driver.cpp @ 103:948027ac55be trunk
[svn] Stop playback when requested to by user.
| author | nenolod |
|---|---|
| date | Wed, 02 Nov 2005 19:11:24 -0800 |
| parents | de414e40f772 |
| children | 04d4827ea8a4 |
| 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 | |
|
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
24 #ifdef WORDS_BIGENDIAN |
|
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
25 # 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
|
26 #else |
|
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
27 # 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
|
28 #endif |
|
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
29 |
| 94 | 30 static Spc_Emu *spc = NULL; |
| 95 | 31 static GThread *decode_thread; |
| 32 | |
| 33 static void *play_loop(gpointer arg); | |
| 100 | 34 static void console_init(void); |
| 96 | 35 static void console_stop(void); |
| 36 static void console_pause(gshort p); | |
| 37 static int get_time(void); | |
| 103 | 38 static gboolean console_ip_is_going; |
| 94 | 39 |
| 100 | 40 extern InputPlugin console_ip; |
| 41 | |
| 94 | 42 static int is_our_file(gchar *filename) |
| 43 { | |
| 44 gchar *ext; | |
| 45 | |
| 46 ext = strrchr(filename, '.'); | |
| 47 | |
| 48 if (ext) | |
| 49 { | |
| 50 if (!strcasecmp(ext, ".spc")) | |
| 51 return 1; | |
| 52 } | |
| 53 | |
| 54 return 0; | |
| 55 } | |
| 56 | |
| 57 static gchar *get_title(gchar *filename) | |
| 58 { | |
| 59 gchar *title; | |
| 60 Emu_Std_Reader reader; | |
| 61 Spc_Emu::header_t header; | |
| 62 | |
| 63 reader.open(filename); | |
| 64 reader.read(&header, sizeof(header)); | |
| 65 | |
| 66 title = g_strdup(header.song); | |
| 67 | |
| 99 | 68 printf("song title is: %s\n", title); |
| 69 | |
| 94 | 70 return title; |
| 71 } | |
| 95 | 72 |
| 73 static void get_song_info(char *filename, char **title, int *length) | |
| 74 { | |
| 75 (*title) = get_title(filename); | |
| 76 (*length) = -1; | |
| 99 | 77 |
| 78 printf("get_song_info() finished\n"); | |
| 95 | 79 } |
| 80 | |
| 81 static void play_file(char *filename) | |
| 82 { | |
| 83 Emu_Std_Reader reader; | |
| 84 Spc_Emu::header_t header; | |
| 85 | |
| 86 reader.open(filename); | |
| 87 reader.read(&header, sizeof(header)); | |
| 88 | |
| 89 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
|
90 spc->init(32000); |
| 95 | 91 spc->load(header, reader); |
| 92 spc->start_track(0); | |
| 93 | |
| 103 | 94 console_ip_is_going = TRUE; |
| 95 | |
| 99 | 96 decode_thread = g_thread_create(play_loop, spc, TRUE, NULL); |
| 97 | |
|
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
|
98 if (!console_ip.output->open_audio(MY_FMT, 32000, 2)) |
| 100 | 99 return; |
| 95 | 100 } |
| 101 | |
| 96 | 102 static void seek(gint time) |
| 103 { | |
| 104 // XXX: Not yet implemented | |
| 105 } | |
| 106 | |
| 107 InputPlugin console_ip = { | |
| 108 NULL, | |
| 109 NULL, | |
| 110 NULL, | |
| 111 console_init, | |
| 112 NULL, | |
| 113 NULL, | |
| 114 is_our_file, | |
| 115 NULL, | |
| 116 play_file, | |
| 117 console_stop, | |
| 118 console_pause, | |
| 119 seek, | |
| 120 NULL, | |
| 121 get_time, | |
| 122 NULL, | |
| 123 NULL, | |
| 124 NULL, | |
| 125 NULL, | |
| 126 NULL, | |
| 127 NULL, | |
| 128 NULL, | |
| 129 NULL, | |
| 130 NULL, | |
| 131 NULL | |
| 132 }; | |
| 133 | |
| 134 static void console_stop(void) | |
| 135 { | |
| 103 | 136 console_ip_is_going = FALSE; |
| 96 | 137 g_thread_join(decode_thread); |
| 138 console_ip.output->close_audio(); | |
| 139 } | |
| 140 | |
|
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
141 extern "C" InputPlugin *get_iplugin_info(void) |
| 96 | 142 { |
| 143 console_ip.description = g_strdup_printf(_("Console music plugin")); | |
| 144 return &console_ip; | |
| 145 } | |
| 146 | |
| 147 static void console_pause(gshort p) | |
| 148 { | |
| 149 console_ip.output->pause(p); | |
| 150 } | |
| 151 | |
| 95 | 152 static void *play_loop(gpointer arg) |
| 153 { | |
| 99 | 154 Spc_Emu *my_spc = (Spc_Emu *) arg; |
|
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
155 Music_Emu::sample_t buf[4096]; |
| 95 | 156 |
| 103 | 157 while (my_spc->play(4096, buf) == NULL && console_ip_is_going == TRUE) |
| 96 | 158 { |
| 100 | 159 console_ip.add_vis_pcm(console_ip.output->written_time(), |
|
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
160 MY_FMT, 1, 4096, buf); |
| 103 | 161 while(console_ip.output->buffer_free() < 4096 && console_ip_is_going == TRUE) |
|
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
162 xmms_usleep(10000); |
|
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
|
163 console_ip.output->write_audio(buf, 8192); |
| 100 | 164 } |
| 95 | 165 |
| 96 | 166 delete spc; |
| 167 g_thread_exit(NULL); | |
| 95 | 168 |
| 96 | 169 return NULL; |
| 95 | 170 } |
| 171 | |
| 96 | 172 static int get_time(void) |
| 173 { | |
| 174 return console_ip.output->output_time(); | |
| 175 } | |
| 95 | 176 |
| 100 | 177 static void console_init(void) |
| 178 { | |
| 179 | |
| 180 } | |
| 181 |
