annotate src/psf2/plugin.c @ 3158:8b97f9560dc3

More clean-up of roll-up code (should fix bug #37; if not, it's a WM problem).
author John Lindgren <john.lindgren@tds.net>
date Fri, 01 May 2009 16:59:54 -0400
parents 3134a0987162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 /*
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 Audio Overload SDK - main driver. for demonstration only, not user friendly!
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4 Copyright (c) 2007-2008 R. Belmont and Richard Bannister.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 All rights reserved.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7
62cc6d667119 Import a bunch of stuff for new psf2 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:
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9
62cc6d667119 Import a bunch of stuff for new psf2 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.
62cc6d667119 Import a bunch of stuff for new psf2 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.
62cc6d667119 Import a bunch of stuff for new psf2 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.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 */
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 #include <stdio.h>
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 #include <stdlib.h>
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 #include <string.h>
62cc6d667119 Import a bunch of stuff for new psf2 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: 2953
diff changeset
31 #include <audlegacy/plugin.h>
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
32
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33 #include "ao.h"
2744
af1338519322 Plugin works kinda, but stopping after track ends isn't done yet.
William Pitcock <nenolod@atheme.org>
parents: 2742
diff changeset
34 #include "corlett.h"
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35 #include "eng_protos.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36
2953
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
37 /* ao_get_lib: called to load secondary files */
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
38 static gchar *path;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40 int ao_get_lib(char *filename, uint8 **buffer, uint64 *length)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41 {
2747
ead11a126bdd clean up warnings.
William Pitcock <nenolod@atheme.org>
parents: 2746
diff changeset
42 guchar *filebuf;
ead11a126bdd clean up warnings.
William Pitcock <nenolod@atheme.org>
parents: 2746
diff changeset
43 gsize size;
2746
aa2e0f33f55d use aud_vfs_file_get_contents().
William Pitcock <nenolod@atheme.org>
parents: 2744
diff changeset
44 char buf[PATH_MAX];
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45
2746
aa2e0f33f55d use aud_vfs_file_get_contents().
William Pitcock <nenolod@atheme.org>
parents: 2744
diff changeset
46 snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47
2747
ead11a126bdd clean up warnings.
William Pitcock <nenolod@atheme.org>
parents: 2746
diff changeset
48 aud_vfs_file_get_contents(buf, (gchar **) &filebuf, &size);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
49
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
50 *buffer = filebuf;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51 *length = (uint64)size;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 return AO_SUCCESS;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55
2751
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
56 static gint seek = 0;
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
57
2749
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
58 Tuple *psf2_tuple(gchar *filename)
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
59 {
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
60 Tuple *t;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
61 corlett_t *c;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
62 guchar *buf;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
63 gsize sz;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
64
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
65 aud_vfs_file_get_contents(filename, (gchar **) &buf, &sz);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
66
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
67 if (!buf)
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
68 return NULL;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
69
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
70 if (corlett_decode(buf, sz, NULL, NULL, &c) != AO_SUCCESS)
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
71 return NULL;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
72
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
73 t = aud_tuple_new_from_filename(filename);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
74
2752
cd2d2118fdee Fix length calculation to include fades.
William Pitcock <nenolod@atheme.org>
parents: 2751
diff changeset
75 aud_tuple_associate_int(t, FIELD_LENGTH, NULL, c->inf_length ? psfTimeToMS(c->inf_length) + psfTimeToMS(c->inf_fade) : -1);
2749
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
76 aud_tuple_associate_string(t, FIELD_ARTIST, NULL, c->inf_artist);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
77 aud_tuple_associate_string(t, FIELD_ALBUM, NULL, c->inf_game);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
78 aud_tuple_associate_string(t, -1, "game", c->inf_game);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
79 aud_tuple_associate_string(t, FIELD_TITLE, NULL, c->inf_title);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
80 aud_tuple_associate_string(t, FIELD_COPYRIGHT, NULL, c->inf_copy);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
81 aud_tuple_associate_string(t, FIELD_QUALITY, NULL, "sequenced");
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
82 aud_tuple_associate_string(t, FIELD_CODEC, NULL, "PlayStation2 Audio");
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
83 aud_tuple_associate_string(t, -1, "console", "PlayStation 2");
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
84
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
85 free(c);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
86 g_free(buf);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
87
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
88 return t;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
89 }
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
90
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
91 gchar *psf2_title(gchar *filename, gint *length)
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
92 {
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
93 gchar *title = NULL;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
94 Tuple *tuple = psf2_tuple(filename);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
95
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
96 if (tuple != NULL)
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
97 {
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
98 title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
99 *length = aud_tuple_get_int(tuple, FIELD_LENGTH, NULL);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
100 aud_tuple_free(tuple);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
101 }
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
102 else
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
103 {
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
104 title = g_path_get_basename(filename);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
105 *length = -1;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
106 }
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
107
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
108 return title;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
109 }
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
110
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
111 void psf2_play(InputPlayback *data)
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 {
2747
ead11a126bdd clean up warnings.
William Pitcock <nenolod@atheme.org>
parents: 2746
diff changeset
113 guchar *buffer;
ead11a126bdd clean up warnings.
William Pitcock <nenolod@atheme.org>
parents: 2746
diff changeset
114 gsize size;
2749
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
115 gint length;
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
116 gchar *title = psf2_title(data->filename, &length);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117
2746
aa2e0f33f55d use aud_vfs_file_get_contents().
William Pitcock <nenolod@atheme.org>
parents: 2744
diff changeset
118 path = g_strdup(data->filename);
2747
ead11a126bdd clean up warnings.
William Pitcock <nenolod@atheme.org>
parents: 2746
diff changeset
119 aud_vfs_file_get_contents(data->filename, (gchar **) &buffer, &size);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120
2738
d0011cde16b7 blah blah blah
William Pitcock <nenolod@atheme.org>
parents: 2737
diff changeset
121 if (psf2_start(buffer, size) != AO_SUCCESS)
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123 free(buffer);
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
124 return;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
127 data->output->open_audio(FMT_S16_NE, 44100, 2);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
128
2749
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
129 data->set_params(data, title, length, 44100*2*2*8, 44100, 2);
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
130
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
131 data->playing = TRUE;
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
132 data->set_pb_ready(data);
2751
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
133
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
134 for (;;)
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 {
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
136 psf2_execute(data);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137
2751
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
138 if (seek)
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
139 {
2753
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
140 data->eof = FALSE;
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
141 data->output->flush(seek);
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
142
2953
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
143 psf2_stop();
2753
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
144
2953
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
145 if (psf2_start(buffer, size) == AO_SUCCESS)
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
146 {
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
147 psf2_seek(seek);
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
148 seek = 0;
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
149 continue;
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
150 }
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
151 else
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
152 {
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
153 data->output->close_audio();
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
154 break;
2cbc458d8286 Fix backwards seeking in PSF2 files.
William Pitcock <nenolod@atheme.org>
parents: 2753
diff changeset
155 }
2751
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
156 }
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
157
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
158 psf2_stop();
2750
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
159
2751
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
160 data->output->buffer_free();
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
161 data->output->buffer_free();
2750
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
162
2751
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
163 while (data->eof && data->output->buffer_playing())
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
164 g_usleep(10000);
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
165
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
166 data->output->close_audio();
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
167
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
168 break;
533d73cfa1ff Finalize event loop for the playback thread; the plugin is now done except for seeking.
William Pitcock <nenolod@atheme.org>
parents: 2750
diff changeset
169 }
2750
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
170
2748
fe0d1cff2cd0 memory leak cleanups.
William Pitcock <nenolod@atheme.org>
parents: 2747
diff changeset
171 g_free(buffer);
2746
aa2e0f33f55d use aud_vfs_file_get_contents().
William Pitcock <nenolod@atheme.org>
parents: 2744
diff changeset
172 g_free(path);
2749
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
173 g_free(title);
2750
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
174
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
175 data->playing = FALSE;
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
176 }
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
177
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
178 void psf2_update(unsigned char *buffer, long count, InputPlayback *playback)
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
179 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
180 const int mask = ~((((16 / 8) * 2)) - 1);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
181
2750
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
182 if (buffer == NULL)
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
183 {
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
184 playback->playing = FALSE;
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
185 playback->eof = TRUE;
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
186
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
187 return;
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
188 }
6319a15e7243 Plugin is mostly usable now.
William Pitcock <nenolod@atheme.org>
parents: 2749
diff changeset
189
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
190 while (count > 0)
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
191 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
192 int t = playback->output->buffer_free() & mask;
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
193 if (t > count)
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
194 playback->pass_audio(playback, FMT_S16_NE, 2, count, buffer, NULL);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
195 else
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
196 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
197 if (t)
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
198 playback->pass_audio(playback, FMT_S16_NE, 2, t, buffer, NULL);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
199
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
200 g_usleep((count-t)*1000*5/441/2);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
201 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
202 count -= t;
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
203 buffer += t;
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
204 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
205
2753
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
206 if (seek)
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
207 {
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
208 if (psf2_seek(seek))
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
209 {
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
210 playback->output->flush(seek);
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
211 seek = 0;
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
212 }
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
213 else
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
214 {
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
215 playback->eof = TRUE;
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
216 return;
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
217 }
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
218 }
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
219 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
220
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
221 void psf2_Stop(InputPlayback *playback)
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
222 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
223 playback->playing = FALSE;
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
224 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
225
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
226 void psf2_pause(InputPlayback *playback, short p)
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
227 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
228 playback->output->pause(p);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
229 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
230
2749
290357060cdb More work on tuples.
William Pitcock <nenolod@atheme.org>
parents: 2748
diff changeset
231 int psf2_is_our_fd(gchar *filename, VFSFile *file)
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
232 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
233 gchar magic[4];
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
234 aud_vfs_fread(magic, 1, 4, file);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
235
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
236 if (!memcmp(magic, "PSF\x02", 4))
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
237 return 1;
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
238
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
239 return 0;
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
240 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
241
2753
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
242 void psf2_Seek(InputPlayback *playback, int time)
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
243 {
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
244 seek = time * 1000;
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
245 }
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
246
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
247 gchar *psf2_fmts[] = { "psf2", "minipsf2", NULL };
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
248
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
249 InputPlugin psf2_ip =
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
250 {
2753
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
251 .description = "PSF2 Audio Plugin",
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
252 .play_file = psf2_play,
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
253 .stop = psf2_Stop,
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
254 .pause = psf2_pause,
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
255 .seek = psf2_Seek,
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
256 .get_song_tuple = psf2_tuple,
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
257 .is_our_file_from_vfs = psf2_is_our_fd,
be414d015fec Implement seeking (you can seek forward), it crashes when you seek backwards though :(.
William Pitcock <nenolod@atheme.org>
parents: 2752
diff changeset
258 .vfs_extensions = psf2_fmts,
2742
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
259 };
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
260
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
261 InputPlugin *psf2_iplist[] = { &psf2_ip, NULL };
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
262
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
263 DECLARE_PLUGIN(psf2, NULL, NULL, psf2_iplist, NULL, NULL, NULL, NULL, NULL);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
264