comparison 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
comparison
equal deleted inserted replaced
144:0faf2fa7fc85 145:8794a4781a15
14 #include <glib/gi18n.h> 14 #include <glib/gi18n.h>
15 #include <gtk/gtk.h> 15 #include <gtk/gtk.h>
16 #include "libaudacious/configfile.h" 16 #include "libaudacious/configfile.h"
17 #include "libaudacious/util.h" 17 #include "libaudacious/util.h"
18 #include "libaudacious/titlestring.h" 18 #include "libaudacious/titlestring.h"
19 #include "audacious/input.h"
19 #include "audacious/output.h" 20 #include "audacious/output.h"
21 #include "audacious/playback.h"
20 22
21 }; 23 };
24
25 struct AudaciousConsoleConfig audcfg = { 180, FALSE, 32000 };
22 26
23 #include <cstring> 27 #include <cstring>
24 28
25 #ifdef WORDS_BIGENDIAN 29 #ifdef WORDS_BIGENDIAN
26 # define MY_FMT FMT_S16_BE 30 # define MY_FMT FMT_S16_BE
36 extern "C" void console_aboutbox(void); 40 extern "C" void console_aboutbox(void);
37 static void console_stop(void); 41 static void console_stop(void);
38 static void console_pause(gshort p); 42 static void console_pause(gshort p);
39 static int get_time(void); 43 static int get_time(void);
40 static gboolean console_ip_is_going; 44 static gboolean console_ip_is_going;
41
42 extern InputPlugin console_ip; 45 extern InputPlugin console_ip;
43 46
44 static int is_our_file(gchar *filename) 47 static int is_our_file(gchar *filename)
45 { 48 {
46 gchar *ext; 49 gchar *ext;
90 } 93 }
91 94
92 static void get_song_info(char *filename, char **title, int *length) 95 static void get_song_info(char *filename, char **title, int *length)
93 { 96 {
94 (*title) = get_title(filename); 97 (*title) = get_title(filename);
95 (*length) = -1; 98
99 if (audcfg.loop_length)
100 (*length) = audcfg.loop_length;
101 else
102 (*length) = -1;
96 } 103 }
97 104
98 static void play_file(char *filename) 105 static void play_file(char *filename)
99 { 106 {
100 gchar *name; 107 gchar *name;
111 118
112 console_ip_is_going = TRUE; 119 console_ip_is_going = TRUE;
113 120
114 name = get_title(filename); 121 name = get_title(filename);
115 122
116 console_ip.set_info(name, -1, spc->voice_count(), 32000, 2); 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
117 129
118 g_free(name); 130 g_free(name);
119 131
120 if (!console_ip.output->open_audio(MY_FMT, 32000, 2)) 132 if (!console_ip.output->open_audio(MY_FMT, 32000, 2))
121 return; 133 return;
176 static void *play_loop(gpointer arg) 188 static void *play_loop(gpointer arg)
177 { 189 {
178 Spc_Emu *my_spc = (Spc_Emu *) arg; 190 Spc_Emu *my_spc = (Spc_Emu *) arg;
179 Music_Emu::sample_t buf[1024]; 191 Music_Emu::sample_t buf[1024];
180 192
181 while (my_spc->play(1024, buf) == NULL && console_ip_is_going == TRUE) 193 for (;;)
182 { 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;
183 console_ip.add_vis_pcm(console_ip.output->written_time(), 203 console_ip.add_vis_pcm(console_ip.output->written_time(),
184 MY_FMT, 1, 2048, buf); 204 MY_FMT, 1, 2048, buf);
185 while(console_ip.output->buffer_free() < 2048) 205 while(console_ip.output->buffer_free() < 2048)
186 xmms_usleep(10000); 206 xmms_usleep(10000);
187 console_ip.output->write_audio(buf, 2048); 207 console_ip.output->write_audio(buf, 2048);
188 } 208 }
189 209
190 delete spc; 210 delete spc;
211 console_ip.output->close_audio();
212 console_ip_is_going = FALSE;
191 g_thread_exit(NULL); 213 g_thread_exit(NULL);
192 214
193 return NULL; 215 return NULL;
194 } 216 }
195 217
196 static int get_time(void) 218 static int get_time(void)
197 { 219 {
198 return console_ip.output->output_time(); 220 if (console_ip_is_going == TRUE)
221 return console_ip.output->output_time();
222 else
223 return -1;
199 } 224 }
200 225
201 static void console_init(void) 226 static void console_init(void)
202 { 227 {
203 228