Mercurial > audlegacy
annotate Plugins/Input/console/Audacious_Driver.cpp @ 99:4b2b964a7694 trunk
[svn] What i have right now is this.
author | nenolod |
---|---|
date | Tue, 01 Nov 2005 21:53:40 -0800 |
parents | e42694a28331 |
children | 05d05f290c04 |
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 | |
24 static Spc_Emu *spc = NULL; | |
95 | 25 static GThread *decode_thread; |
26 | |
27 static void *play_loop(gpointer arg); | |
96 | 28 static void console_stop(void); |
29 static void console_pause(gshort p); | |
30 static int get_time(void); | |
94 | 31 |
32 static int is_our_file(gchar *filename) | |
33 { | |
34 gchar *ext; | |
35 | |
36 ext = strrchr(filename, '.'); | |
37 | |
38 if (ext) | |
39 { | |
40 if (!strcasecmp(ext, ".spc")) | |
41 return 1; | |
42 } | |
43 | |
44 return 0; | |
45 } | |
46 | |
47 static gchar *get_title(gchar *filename) | |
48 { | |
49 gchar *title; | |
50 Emu_Std_Reader reader; | |
51 Spc_Emu::header_t header; | |
52 | |
53 reader.open(filename); | |
54 reader.read(&header, sizeof(header)); | |
55 | |
56 title = g_strdup(header.song); | |
57 | |
99 | 58 printf("song title is: %s\n", title); |
59 | |
94 | 60 return title; |
61 } | |
95 | 62 |
63 static void get_song_info(char *filename, char **title, int *length) | |
64 { | |
65 (*title) = get_title(filename); | |
66 (*length) = -1; | |
99 | 67 |
68 printf("get_song_info() finished\n"); | |
95 | 69 } |
70 | |
71 static void play_file(char *filename) | |
72 { | |
73 Emu_Std_Reader reader; | |
74 Spc_Emu::header_t header; | |
75 | |
76 reader.open(filename); | |
77 reader.read(&header, sizeof(header)); | |
78 | |
79 spc = new Spc_Emu; | |
80 spc->init(44100); | |
81 spc->load(header, reader); | |
82 spc->start_track(0); | |
83 | |
99 | 84 decode_thread = g_thread_create(play_loop, spc, TRUE, NULL); |
85 | |
86 printf("decode_thread started.\n"); | |
95 | 87 } |
88 | |
96 | 89 static void seek(gint time) |
90 { | |
91 // XXX: Not yet implemented | |
92 } | |
93 | |
94 static void console_init(void) | |
95 { | |
96 // nothing to do here | |
97 } | |
98 | |
99 InputPlugin console_ip = { | |
100 NULL, | |
101 NULL, | |
102 NULL, | |
103 console_init, | |
104 NULL, | |
105 NULL, | |
106 is_our_file, | |
107 NULL, | |
108 play_file, | |
109 console_stop, | |
110 console_pause, | |
111 seek, | |
112 NULL, | |
113 get_time, | |
114 NULL, | |
115 NULL, | |
116 NULL, | |
117 NULL, | |
118 NULL, | |
119 NULL, | |
120 NULL, | |
121 NULL, | |
122 NULL, | |
123 NULL | |
124 }; | |
125 | |
126 static void console_stop(void) | |
127 { | |
128 g_thread_join(decode_thread); | |
129 console_ip.output->close_audio(); | |
130 } | |
131 | |
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
132 extern "C" InputPlugin *get_iplugin_info(void) |
96 | 133 { |
134 console_ip.description = g_strdup_printf(_("Console music plugin")); | |
135 return &console_ip; | |
136 } | |
137 | |
138 static void console_pause(gshort p) | |
139 { | |
140 console_ip.output->pause(p); | |
141 } | |
142 | |
95 | 143 static void *play_loop(gpointer arg) |
144 { | |
99 | 145 Spc_Emu *my_spc = (Spc_Emu *) arg; |
96 | 146 Music_Emu::sample_t buf[1024]; |
95 | 147 |
99 | 148 printf("inside decode_thread, my_spc = %p, spc = %p\n", my_spc, spc); |
149 | |
150 do | |
96 | 151 { |
99 | 152 printf("buf = %s\n", buf); |
96 | 153 produce_audio(console_ip.output->written_time(), |
154 FMT_S16_LE, 2, 1024, (char *) buf, | |
155 NULL); | |
99 | 156 printf("writing audio to output device\n"); |
96 | 157 xmms_usleep(100000); |
99 | 158 } while (my_spc->play(1024, buf)); |
159 | |
160 printf("we're through in decode_thread, cleaning up\n"); | |
95 | 161 |
96 | 162 delete spc; |
163 g_thread_exit(NULL); | |
95 | 164 |
96 | 165 return NULL; |
95 | 166 } |
167 | |
96 | 168 static int get_time(void) |
169 { | |
170 return console_ip.output->output_time(); | |
171 } | |
95 | 172 |