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