annotate src/xsf/plugin.c @ 3052:95b34f46a231

Comment out MPEG2/MPEG4 determination using the variable id. It is not used anywhere. Code analysis run, unique ID 6nYoHM.
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 18 Apr 2009 19:06:20 +0100
parents 3134a0987162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 /*
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 Audio Overload SDK - main driver. for demonstration only, not user friendly!
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4 Copyright (c) 2007-2008 R. Belmont and Richard Bannister.
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 All rights reserved.
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
10 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
11 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
12 * Neither the names of R. Belmont and Richard Bannister nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 #include <stdio.h>
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 #include <stdlib.h>
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 #include <string.h>
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30
2971
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2965
diff changeset
31 #include <audlegacy/plugin.h>
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33 #include "ao.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 #include "corlett.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35 #include "vio2sf.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 /* xsf_get_lib: called to load secondary files */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 static gchar *path;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 int xsf_get_lib(char *filename, void **buffer, unsigned int *length)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41 guchar *filebuf;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42 gsize size;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 char buf[PATH_MAX];
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47 aud_vfs_file_get_contents(buf, (gchar **) &filebuf, &size);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
49 *buffer = filebuf;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
50 *length = (uint64)size;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 return AO_SUCCESS;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 static gint seek = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 Tuple *xsf_tuple(gchar *filename)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 Tuple *t;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 corlett_t *c;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
60 guchar *buf;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61 gsize sz;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
62
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 aud_vfs_file_get_contents(filename, (gchar **) &buf, &sz);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 if (!buf)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 return NULL;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
67
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68 if (corlett_decode(buf, sz, NULL, NULL, &c) != AO_SUCCESS)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 return NULL;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 t = aud_tuple_new_from_filename(filename);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73 aud_tuple_associate_int(t, FIELD_LENGTH, NULL, c->inf_length ? psfTimeToMS(c->inf_length) + psfTimeToMS(c->inf_fade) : -1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 aud_tuple_associate_string(t, FIELD_ARTIST, NULL, c->inf_artist);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75 aud_tuple_associate_string(t, FIELD_ALBUM, NULL, c->inf_game);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76 aud_tuple_associate_string(t, -1, "game", c->inf_game);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
77 aud_tuple_associate_string(t, FIELD_TITLE, NULL, c->inf_title);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
78 aud_tuple_associate_string(t, FIELD_COPYRIGHT, NULL, c->inf_copy);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 aud_tuple_associate_string(t, FIELD_QUALITY, NULL, "sequenced");
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80 aud_tuple_associate_string(t, FIELD_CODEC, NULL, "Nintendo DS Audio");
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81 aud_tuple_associate_string(t, -1, "console", "Nintendo DS");
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83 free(c);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 g_free(buf);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 return t;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
89 gchar *xsf_title(gchar *filename, gint *length)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
90 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91 gchar *title = NULL;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 Tuple *tuple = xsf_tuple(filename);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94 if (tuple != NULL)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97 *length = aud_tuple_get_int(tuple, FIELD_LENGTH, NULL);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
98 aud_tuple_free(tuple);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
99 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
100 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 title = g_path_get_basename(filename);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103 *length = -1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106 return title;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109 void xsf_update(unsigned char *buffer, long count, InputPlayback *playback);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111 void xsf_play(InputPlayback *data)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113 guchar *buffer;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
114 gsize size;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
115 gint length;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116 gchar *title = xsf_title(data->filename, &length);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 gint16 samples[44100*2];
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118 gint seglen = 44100 / 60;
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
119 gfloat pos;
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
121 path = g_strdup(data->filename);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 aud_vfs_file_get_contents(data->filename, (gchar **) &buffer, &size);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 if (xsf_start(buffer, size) != AO_SUCCESS)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126 free(buffer);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
127 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
128 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
129
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
130 data->output->open_audio(FMT_S16_NE, 44100, 2);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
131
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
132 data->set_params(data, title, length, 44100*2*2*8, 44100, 2);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 data->playing = TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 data->set_pb_ready(data);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137 for (;;)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138 {
2964
629d5494c8f1 Ok, really fix the EOF stuff.
William Pitcock <nenolod@atheme.org>
parents: 2962
diff changeset
139 while (data->playing && !seek && !data->eof)
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 xsf_gen(samples, seglen);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142 xsf_update(samples, seglen * 4, data);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
143
2964
629d5494c8f1 Ok, really fix the EOF stuff.
William Pitcock <nenolod@atheme.org>
parents: 2962
diff changeset
144 if (data->output->output_time() > length)
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145 data->eof = TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
146 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148 if (seek)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149 {
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
150 if (seek > data->output->output_time())
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
151 {
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
152 pos = data->output->output_time();
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
153 while (pos < seek)
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
154 {
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
155 xsf_gen(samples, seglen);
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
156 pos += 16.666;
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
157 }
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
158
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
159 data->output->flush(seek);
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
160 seek = 0;
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
161
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
162 continue;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
163 }
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
164 else if (seek < data->output->output_time())
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
165 {
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
166 data->eof = FALSE;
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
167
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
168 g_print("xsf_term\n");
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
169 xsf_term();
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
170
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
171 g_print("xsf_start... ");
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
172 if (xsf_start(buffer, size) == AO_SUCCESS)
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
173 {
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
174 g_print("ok!\n");
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
175 pos = 0;
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
176 while (pos < seek)
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
177 {
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
178 xsf_gen(samples, seglen);
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
179 pos += 16.666; /* each segment is 16.666ms */
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
180 }
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
181
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
182 data->output->flush(seek);
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
183 seek = 0;
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
184
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
185 continue;
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
186 }
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
187 else
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
188 {
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
189 g_print("fail :(\n");
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
190
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
191 data->output->close_audio();
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
192
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
193 g_free(buffer);
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
194 g_free(path);
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
195 g_free(title);
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
196
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
197 data->playing = FALSE;
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
198
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
199 return;
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2964
diff changeset
200 }
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
201 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
202 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
203
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
204 xsf_term();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
205
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
206 data->output->buffer_free();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
207 data->output->buffer_free();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
208
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
209 while (data->eof && data->output->buffer_playing())
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
210 g_usleep(10000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
211
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
212 data->output->close_audio();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
213
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
214 break;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
215 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
216
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
217 g_free(buffer);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
218 g_free(path);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
219 g_free(title);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
220
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
221 data->playing = FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
222 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
223
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
224 void xsf_update(unsigned char *buffer, long count, InputPlayback *playback)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
225 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
226 const int mask = ~((((16 / 8) * 2)) - 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
227
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
228 if (buffer == NULL)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
229 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
230 playback->playing = FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
231 playback->eof = TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
232
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
233 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
234 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
235
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
236 while (count > 0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
237 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
238 int t = playback->output->buffer_free() & mask;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
239 if (t > count)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
240 playback->pass_audio(playback, FMT_S16_NE, 2, count, buffer, NULL);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
241 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
242 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
243 if (t)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
244 playback->pass_audio(playback, FMT_S16_NE, 2, t, buffer, NULL);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
245
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
246 g_usleep((count-t)*1000*5/441/2);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
247 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
248 count -= t;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
249 buffer += t;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
250 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
251 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
252
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
253 void xsf_Stop(InputPlayback *playback)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
254 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
255 playback->playing = FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
256 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
257
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
258 void xsf_pause(InputPlayback *playback, short p)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
259 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
260 playback->output->pause(p);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
261 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
262
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
263 int xsf_is_our_fd(gchar *filename, VFSFile *file)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
264 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
265 gchar magic[4];
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
266 aud_vfs_fread(magic, 1, 4, file);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
267
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
268 if (!memcmp(magic, "PSF$", 4))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
269 return 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
270
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
271 return 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
272 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
273
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
274 void xsf_Seek(InputPlayback *playback, int time)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
275 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
276 seek = time * 1000;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
277 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
278
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
279 gchar *xsf_fmts[] = { "2sf", "mini2sf", NULL };
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
280
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
281 InputPlugin xsf_ip =
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
282 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
283 .description = "2SF Audio Plugin",
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
284 .play_file = xsf_play,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
285 .stop = xsf_Stop,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
286 .pause = xsf_pause,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
287 .seek = xsf_Seek,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
288 .get_song_tuple = xsf_tuple,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
289 .is_our_file_from_vfs = xsf_is_our_fd,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
290 .vfs_extensions = xsf_fmts,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
291 };
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
292
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
293 InputPlugin *xsf_iplist[] = { &xsf_ip, NULL };
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
294
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
295 DECLARE_PLUGIN(psf2, NULL, NULL, xsf_iplist, NULL, NULL, NULL, NULL, NULL);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
296