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