|
1 | 1 | #include <pspaudio.h> |
2 | 2 | #include <pspthreadman.h> |
3 | | -#include <string.h> |
| 3 | +#include <cstring> |
4 | 4 |
|
5 | 5 | #include "fs.h" |
6 | 6 | #include "kernel_functions.h" |
@@ -37,32 +37,37 @@ namespace Audio { |
37 | 37 |
|
38 | 38 | static void Decode(void *buf, unsigned int length, void *userdata) { |
39 | 39 | if ((!playing) || (paused)) { |
40 | | - s16 *buf_s16 = static_cast<s16 *>(buf); |
41 | | - for (unsigned int count = 0; count < length * 4; count++) |
42 | | - *(buf_s16 + count) = 0; |
| 40 | + std::memset(buf, 0, length * 4); |
43 | 41 | } |
44 | | - else |
45 | | - (* decoder.decode)(buf, length, userdata); |
| 42 | + else { |
| 43 | + (*decoder.decode)(buf, length, userdata); |
| 44 | + } |
46 | 45 | } |
47 | 46 |
|
48 | 47 | void Init(const std::string &path) { |
49 | 48 | playing = true; |
50 | 49 | paused = false; |
| 50 | + const char *ext = FS::GetFileExt(path.c_str()); |
51 | 51 |
|
52 | | - std::string ext = FS::GetFileExt(path); |
53 | | - |
54 | | - if (!ext.compare(".FLAC")) |
| 52 | + if (strncasecmp(ext, "flac", 4) == 0) { |
55 | 53 | file_type = FILE_TYPE_FLAC; |
56 | | - else if (!ext.compare(".MP3")) |
| 54 | + } |
| 55 | + else if (strncasecmp(ext, "mp3", 3) == 0) { |
57 | 56 | file_type = FILE_TYPE_MP3; |
58 | | - else if (!ext.compare(".OGG")) |
| 57 | + } |
| 58 | + else if (strncasecmp(ext, "ogg", 3) == 0) { |
59 | 59 | file_type = FILE_TYPE_OGG; |
60 | | - else if (!ext.compare(".OPUS")) |
| 60 | + } |
| 61 | + else if (strncasecmp(ext, "opus", 4) == 0) { |
61 | 62 | file_type = FILE_TYPE_OPUS; |
62 | | - else if (!ext.compare(".WAV")) |
| 63 | + } |
| 64 | + else if (strncasecmp(ext, "wav", 3) == 0) { |
63 | 65 | file_type = FILE_TYPE_WAV; |
64 | | - else if ((!ext.compare(".IT")) || (!ext.compare(".MOD")) || (!ext.compare(".S3M")) || (!ext.compare(".XM"))) |
| 66 | + } |
| 67 | + else if ((strncasecmp(ext, "it", 2) == 0) || (strncasecmp(ext, "mod", 3) == 0) || (strncasecmp(ext, "s3m", 3) == 0) |
| 68 | + || (strncasecmp(ext, "xm", 2) == 0)) { |
65 | 69 | file_type = FILE_TYPE_XM; |
| 70 | + } |
66 | 71 |
|
67 | 72 | switch(file_type) { |
68 | 73 | case FILE_TYPE_FLAC: |
@@ -184,9 +189,8 @@ namespace Audio { |
184 | 189 | (* decoder.term)(); |
185 | 190 |
|
186 | 191 | // Clear metadata struct |
187 | | - if (metadata.has_meta) { |
188 | | - if (metadata.cover_image) |
189 | | - g2dTexFree(&metadata.cover_image); |
| 192 | + if (metadata.has_meta && metadata.cover_image) { |
| 193 | + g2dTexFree(&metadata.cover_image); |
190 | 194 | } |
191 | 195 |
|
192 | 196 | metadata = { 0 }; |
|
0 commit comments