Mercurial > audlegacy
annotate Plugins/Input/console/Audacious_Driver.cpp @ 95:8247bbf454a8 trunk
[svn] Add code for decoder thread.
author | nenolod |
---|---|
date | Tue, 01 Nov 2005 21:09:52 -0800 |
parents | 2801eda0683f |
children | 8dbd2d31c1f7 |
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 |
94 | 11 #include "libaudacious/configfile.h" |
12 #include "libaudacious/util.h" | |
13 #include "libaudacious/titlestring.h" | |
95 | 14 #include "audacious/output.h" |
94 | 15 #include <gtk/gtk.h> |
16 | |
17 #include <cstring> | |
18 | |
19 static Spc_Emu *spc = NULL; | |
95 | 20 static GThread *decode_thread; |
21 static InputPlugin console_ip; | |
22 | |
23 static void *play_loop(gpointer arg); | |
94 | 24 |
25 static int is_our_file(gchar *filename) | |
26 { | |
27 gchar *ext; | |
28 | |
29 ext = strrchr(filename, '.'); | |
30 | |
31 if (ext) | |
32 { | |
33 if (!strcasecmp(ext, ".spc")) | |
34 return 1; | |
35 } | |
36 | |
37 return 0; | |
38 } | |
39 | |
40 static gchar *get_title(gchar *filename) | |
41 { | |
42 gchar *title; | |
43 Emu_Std_Reader reader; | |
44 Spc_Emu::header_t header; | |
45 | |
46 reader.open(filename); | |
47 reader.read(&header, sizeof(header)); | |
48 | |
49 title = g_strdup(header.song); | |
50 | |
51 return title; | |
52 } | |
95 | 53 |
54 static void get_song_info(char *filename, char **title, int *length) | |
55 { | |
56 (*title) = get_title(filename); | |
57 (*length) = -1; | |
58 } | |
59 | |
60 static void play_file(char *filename) | |
61 { | |
62 Emu_Std_Reader reader; | |
63 Spc_Emu::header_t header; | |
64 | |
65 reader.open(filename); | |
66 reader.read(&header, sizeof(header)); | |
67 | |
68 spc = new Spc_Emu; | |
69 spc->init(44100); | |
70 spc->load(header, reader); | |
71 spc->start_track(0); | |
72 | |
73 decode_thread = g_thread_create(play_loop, NULL, FALSE, NULL); | |
74 } | |
75 | |
76 static void *play_loop(gpointer arg) | |
77 { | |
78 Music_Emu::sample_t buf[1024]; | |
79 | |
80 while (spc->play(1024, buf)) | |
81 { | |
82 produce_audio(console_ip.output->written_time(), | |
83 FMT_S16_LE, 2, 1024, (char *) buf, | |
84 NULL); | |
85 xmms_usleep(100000); | |
86 } | |
87 | |
88 delete spc; | |
89 g_thread_exit(NULL); | |
90 | |
91 return NULL; | |
92 } | |
93 | |
94 |