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