comparison src/psf2/plugin.c @ 2953:2cbc458d8286

Fix backwards seeking in PSF2 files.
author William Pitcock <nenolod@atheme.org>
date Wed, 15 Oct 2008 14:20:45 -0500
parents be414d015fec
children 3134a0987162
comparison
equal deleted inserted replaced
2952:63bf9d97ce65 2953:2cbc458d8286
32 32
33 #include "ao.h" 33 #include "ao.h"
34 #include "corlett.h" 34 #include "corlett.h"
35 #include "eng_protos.h" 35 #include "eng_protos.h"
36 36
37 /* file types */
38 static uint32 type;
39
40 static struct
41 {
42 uint32 sig;
43 char *name;
44 int32 (*start)(uint8 *, uint32);
45 int32 (*stop)(void);
46 int32 (*command)(int32, int32);
47 uint32 rate;
48 } types[] = {
49 { 0x50534602, "Sony PlayStation 2 (.psf2)", psf2_start, psf2_stop, psf2_command, 60 },
50 { 0xffffffff, "", NULL, NULL, NULL, 0 }
51 };
52
53 static char *path;
54
55 /* ao_get_lib: called to load secondary files */ 37 /* ao_get_lib: called to load secondary files */
38 static gchar *path;
39
56 int ao_get_lib(char *filename, uint8 **buffer, uint64 *length) 40 int ao_get_lib(char *filename, uint8 **buffer, uint64 *length)
57 { 41 {
58 guchar *filebuf; 42 guchar *filebuf;
59 gsize size; 43 gsize size;
60 char buf[PATH_MAX]; 44 char buf[PATH_MAX];
126 110
127 void psf2_play(InputPlayback *data) 111 void psf2_play(InputPlayback *data)
128 { 112 {
129 guchar *buffer; 113 guchar *buffer;
130 gsize size; 114 gsize size;
131 uint32 filesig;
132 gint length; 115 gint length;
133 gchar *title = psf2_title(data->filename, &length); 116 gchar *title = psf2_title(data->filename, &length);
134 117
135 path = g_strdup(data->filename); 118 path = g_strdup(data->filename);
136 aud_vfs_file_get_contents(data->filename, (gchar **) &buffer, &size); 119 aud_vfs_file_get_contents(data->filename, (gchar **) &buffer, &size);
137 120
138 // now try to identify the file 121 if (psf2_start(buffer, size) != AO_SUCCESS)
139 type = 0; 122 {
140 filesig = buffer[0]<<24 | buffer[1]<<16 | buffer[2]<<8 | buffer[3];
141 while (types[type].sig != 0xffffffff)
142 {
143 if (filesig == types[type].sig)
144 {
145 break;
146 }
147 else
148 {
149 type++;
150 }
151 }
152
153 // now did we identify it above or just fall through?
154 if (types[type].sig == 0xffffffff)
155 {
156 printf("ERROR: File is unknown, signature bytes are %02x %02x %02x %02x\n", buffer[0], buffer[1], buffer[2], buffer[3]);
157 free(buffer); 123 free(buffer);
158 return; 124 return;
159 } 125 }
160
161 if (psf2_start(buffer, size) != AO_SUCCESS)
162 {
163 free(buffer);
164 printf("ERROR: Engine rejected file!\n");
165 return;
166 }
167 126
168 data->output->open_audio(FMT_S16_NE, 44100, 2); 127 data->output->open_audio(FMT_S16_NE, 44100, 2);
169 128
170 data->set_params(data, title, length, 44100*2*2*8, 44100, 2); 129 data->set_params(data, title, length, 44100*2*2*8, 44100, 2);
171 130
179 if (seek) 138 if (seek)
180 { 139 {
181 data->eof = FALSE; 140 data->eof = FALSE;
182 data->output->flush(seek); 141 data->output->flush(seek);
183 142
184 psf2_command(COMMAND_RESTART, 0); 143 psf2_stop();
185 psf2_seek(seek); 144
186 145 if (psf2_start(buffer, size) == AO_SUCCESS)
187 seek = 0; 146 {
188 continue; 147 psf2_seek(seek);
148 seek = 0;
149 continue;
150 }
151 else
152 {
153 data->output->close_audio();
154 break;
155 }
189 } 156 }
190 157
191 psf2_stop(); 158 psf2_stop();
192 159
193 data->output->buffer_free(); 160 data->output->buffer_free();