annotate src/psf2/plugin.c @ 2742:fd5373830ac1

Initial plugin. Don't use this unless you like aud to use 100% cpu.
author William Pitcock <nenolod@atheme.org>
date Mon, 30 Jun 2008 22:12:23 -0500
parents f16fdcabe069
children af1338519322
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
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
31 #include <audacious/plugin.h>
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"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 #include "eng_protos.h"
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36 /* file types */
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 static uint32 type;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 static struct
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41 uint32 sig;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42 char *name;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 int32 (*start)(uint8 *, uint32);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44 int32 (*stop)(void);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 int32 (*command)(int32, int32);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46 uint32 rate;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47 int32 (*fillinfo)(ao_display_info *);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48 } types[] = {
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
49 { 0x50534602, "Sony PlayStation 2 (.psf2)", psf2_start, psf2_stop, psf2_command, 60, psf2_fill_info },
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
50 { 0xffffffff, "", NULL, NULL, NULL, 0, NULL }
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51 };
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 static char *path;
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 /* ao_get_lib: called to load secondary files */
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 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
57 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 uint8 *filebuf;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 uint32 size;
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
60 VFSFile *auxfile;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61
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
62 auxfile = aud_vfs_fopen(filename, "rb");
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 if (!auxfile)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 char buf[PATH_MAX];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename);
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
67 auxfile = aud_vfs_fopen(buf, "rb");
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 if (!auxfile)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 printf("Unable to find auxiliary file %s\n", buf);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 return AO_FAIL;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75
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
76 aud_vfs_fseek(auxfile, 0, SEEK_END);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
77 size = aud_vfs_ftell(auxfile);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
78 aud_vfs_fseek(auxfile, 0, SEEK_SET);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80 filebuf = malloc(size);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 if (!filebuf)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83 {
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
84 aud_vfs_fclose(auxfile);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 printf("ERROR: could not allocate %d bytes of memory\n", size);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 return AO_FAIL;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88
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
89 aud_vfs_fread(filebuf, size, 1, auxfile);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
90 aud_vfs_fclose(auxfile);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 *buffer = filebuf;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 *length = (uint64)size;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 return AO_SUCCESS;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97
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
98 void psf2_play(InputPlayback *data)
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
99 {
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
100 VFSFile *file;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101 uint8 *buffer;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 uint32 size, filesig;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103
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
104 path = strdup(data->filename);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
105 file = aud_vfs_fopen(data->filename, "rb");
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107 if (!file)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108 {
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
109 printf("ERROR: could not open file %s\n", data->filename);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
110 return;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112
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
113 aud_vfs_fseek(file, 0, SEEK_END);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
114 size = aud_vfs_ftell(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
115 aud_vfs_fseek(file, 0, SEEK_SET);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 buffer = malloc(size);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
119 if (!buffer)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120 {
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
121 aud_vfs_fclose(file);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 printf("ERROR: could not allocate %d bytes of memory\n", size);
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
123 return;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 }
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 // read the 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
127 aud_vfs_fread(buffer, size, 1, 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
128 aud_vfs_fclose(file);
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
129
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
130 // now try to identify the file
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
131 type = 0;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
132 filesig = buffer[0]<<24 | buffer[1]<<16 | buffer[2]<<8 | buffer[3];
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133 while (types[type].sig != 0xffffffff)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 if (filesig == types[type].sig)
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137 break;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
139 else
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 type++;
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
143 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
144
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145 // now did we identify it above or just fall through?
2738
d0011cde16b7 blah blah blah
William Pitcock <nenolod@atheme.org>
parents: 2737
diff changeset
146 if (types[type].sig == 0xffffffff)
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148 printf("ERROR: File is unknown, signature bytes are %02x %02x %02x %02x\n", buffer[0], buffer[1], buffer[2], buffer[3]);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149 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
150 return;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
151 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
152
2738
d0011cde16b7 blah blah blah
William Pitcock <nenolod@atheme.org>
parents: 2737
diff changeset
153 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
154 {
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
155 free(buffer);
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
156 printf("ERROR: Engine rejected file!\n");
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
157 return;
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
158 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
159
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
160 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
161
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
162 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
163 data->set_pb_ready(data);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
164 while (data->playing)
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
165 {
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
166 psf2_execute(data);
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
167 }
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
168
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
169 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
170 }
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
171
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
172 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
173 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
174 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
175
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 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
177 {
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 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
179 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
180 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
181 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
182 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
183 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
184 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
185
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
186 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
187 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
188 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
189 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
190 }
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 #if 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
193 if (seek)
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 {
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 if(sexypsf_seek(seek))
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 playback->output->flush(seek);
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 seek = 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
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 else // negative time - must make a C time machine
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 sexypsf_stop();
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 return;
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 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
206 if (stop)
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
207 sexypsf_stop();
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
208 #endif
2737
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
209 }
62cc6d667119 Import a bunch of stuff for new psf2 plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
210
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
211 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
212 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
213 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
214 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
215
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
216 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
217 {
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
218 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
219 }
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
220
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 static int
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 is_our_fd(gchar *filename, VFSFile *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
223 {
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 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
225 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
226
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 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
228 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
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 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
231 }
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 *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
234
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 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
236 {
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 .description = "PSF2 Audio Plugin",
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 .play_file = psf2_play,
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 .stop = psf2_Stop,
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 .pause = psf2_pause,
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 #if 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
242 .seek = sexypsf_xmms_seek,
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
243 .get_song_info = sexypsf_xmms_getsonginfo,
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
244 .get_song_tuple = get_aud_tuple_psf,
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
245 #endif
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
246 .is_our_file_from_vfs = is_our_fd,
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 .vfs_extensions = psf2_fmts,
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
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 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
251
fd5373830ac1 Initial plugin. Don't use this unless you like aud to use 100% cpu.
William Pitcock <nenolod@atheme.org>
parents: 2741
diff changeset
252 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
253