Mercurial > audlegacy-plugins
comparison src/psf2/plugin.c @ 2746:aa2e0f33f55d
use aud_vfs_file_get_contents().
| author | William Pitcock <nenolod@atheme.org> |
|---|---|
| date | Mon, 30 Jun 2008 23:03:47 -0500 |
| parents | af1338519322 |
| children | ead11a126bdd |
comparison
equal
deleted
inserted
replaced
| 2745:3ba15b5aeadb | 2746:aa2e0f33f55d |
|---|---|
| 56 int ao_get_lib(char *filename, uint8 **buffer, uint64 *length) | 56 int ao_get_lib(char *filename, uint8 **buffer, uint64 *length) |
| 57 { | 57 { |
| 58 uint8 *filebuf; | 58 uint8 *filebuf; |
| 59 uint32 size; | 59 uint32 size; |
| 60 VFSFile *auxfile; | 60 VFSFile *auxfile; |
| 61 | 61 char buf[PATH_MAX]; |
| 62 auxfile = aud_vfs_fopen(filename, "rb"); | 62 |
| 63 if (!auxfile) | 63 snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename); |
| 64 { | 64 |
| 65 char buf[PATH_MAX]; | 65 aud_vfs_file_get_contents(buf, &filebuf, &size); |
| 66 snprintf(buf, PATH_MAX, "%s/%s", dirname(path), filename); | |
| 67 auxfile = aud_vfs_fopen(buf, "rb"); | |
| 68 | |
| 69 if (!auxfile) | |
| 70 { | |
| 71 printf("Unable to find auxiliary file %s\n", buf); | |
| 72 return AO_FAIL; | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 aud_vfs_fseek(auxfile, 0, SEEK_END); | |
| 77 size = aud_vfs_ftell(auxfile); | |
| 78 aud_vfs_fseek(auxfile, 0, SEEK_SET); | |
| 79 | |
| 80 filebuf = malloc(size); | |
| 81 | |
| 82 if (!filebuf) | |
| 83 { | |
| 84 aud_vfs_fclose(auxfile); | |
| 85 printf("ERROR: could not allocate %d bytes of memory\n", size); | |
| 86 return AO_FAIL; | |
| 87 } | |
| 88 | |
| 89 aud_vfs_fread(filebuf, size, 1, auxfile); | |
| 90 aud_vfs_fclose(auxfile); | |
| 91 | 66 |
| 92 *buffer = filebuf; | 67 *buffer = filebuf; |
| 93 *length = (uint64)size; | 68 *length = (uint64)size; |
| 94 | 69 |
| 95 return AO_SUCCESS; | 70 return AO_SUCCESS; |
| 96 } | 71 } |
| 97 | 72 |
| 98 void psf2_play(InputPlayback *data) | 73 void psf2_play(InputPlayback *data) |
| 99 { | 74 { |
| 100 VFSFile *file; | |
| 101 uint8 *buffer; | 75 uint8 *buffer; |
| 102 uint32 size, filesig; | 76 uint32 size, filesig; |
| 103 | 77 |
| 104 path = strdup(data->filename); | 78 path = g_strdup(data->filename); |
| 105 file = aud_vfs_fopen(data->filename, "rb"); | 79 aud_vfs_file_get_contents(data->filename, &buffer, &size); |
| 106 | |
| 107 if (!file) | |
| 108 { | |
| 109 printf("ERROR: could not open file %s\n", data->filename); | |
| 110 return; | |
| 111 } | |
| 112 | |
| 113 aud_vfs_fseek(file, 0, SEEK_END); | |
| 114 size = aud_vfs_ftell(file); | |
| 115 aud_vfs_fseek(file, 0, SEEK_SET); | |
| 116 | |
| 117 buffer = malloc(size); | |
| 118 | |
| 119 if (!buffer) | |
| 120 { | |
| 121 aud_vfs_fclose(file); | |
| 122 printf("ERROR: could not allocate %d bytes of memory\n", size); | |
| 123 return; | |
| 124 } | |
| 125 | |
| 126 // read the file | |
| 127 aud_vfs_fread(buffer, size, 1, file); | |
| 128 aud_vfs_fclose(file); | |
| 129 | 80 |
| 130 // now try to identify the file | 81 // now try to identify the file |
| 131 type = 0; | 82 type = 0; |
| 132 filesig = buffer[0]<<24 | buffer[1]<<16 | buffer[2]<<8 | buffer[3]; | 83 filesig = buffer[0]<<24 | buffer[1]<<16 | buffer[2]<<8 | buffer[3]; |
| 133 while (types[type].sig != 0xffffffff) | 84 while (types[type].sig != 0xffffffff) |
| 165 { | 116 { |
| 166 psf2_execute(data); | 117 psf2_execute(data); |
| 167 } | 118 } |
| 168 | 119 |
| 169 free(buffer); | 120 free(buffer); |
| 121 g_free(path); | |
| 170 } | 122 } |
| 171 | 123 |
| 172 void psf2_update(unsigned char *buffer, long count, InputPlayback *playback) | 124 void psf2_update(unsigned char *buffer, long count, InputPlayback *playback) |
| 173 { | 125 { |
| 174 const int mask = ~((((16 / 8) * 2)) - 1); | 126 const int mask = ~((((16 / 8) * 2)) - 1); |
