Skip to content

Commit 81e988e

Browse files
committed
fs: Clean up/optimize FS code and minor code consistency changes
1 parent 16a6427 commit 81e988e

5 files changed

Lines changed: 301 additions & 235 deletions

File tree

app/include/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace FS {
2525
int MakeDir(const std::string &path);
2626
int RecursiveMakeDir(const std::string &path);
2727
int CreateFile(const std::string &path);
28-
std::string GetFileExt(const std::string &filename);
28+
const char* GetFileExt(const char *filename);
2929
FileType GetFileType(const std::string &filename);
3030
SceOff GetFileSize(const std::string &path);
3131
char *GetFileTimestamp(SceIoStat &stat, FileTimestamp time);

app/source/audio.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <pspaudio.h>
22
#include <pspthreadman.h>
3-
#include <string.h>
3+
#include <cstring>
44

55
#include "fs.h"
66
#include "kernel_functions.h"
@@ -37,32 +37,37 @@ namespace Audio {
3737

3838
static void Decode(void *buf, unsigned int length, void *userdata) {
3939
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);
4341
}
44-
else
45-
(* decoder.decode)(buf, length, userdata);
42+
else {
43+
(*decoder.decode)(buf, length, userdata);
44+
}
4645
}
4746

4847
void Init(const std::string &path) {
4948
playing = true;
5049
paused = false;
50+
const char *ext = FS::GetFileExt(path.c_str());
5151

52-
std::string ext = FS::GetFileExt(path);
53-
54-
if (!ext.compare(".FLAC"))
52+
if (strncasecmp(ext, "flac", 4) == 0) {
5553
file_type = FILE_TYPE_FLAC;
56-
else if (!ext.compare(".MP3"))
54+
}
55+
else if (strncasecmp(ext, "mp3", 3) == 0) {
5756
file_type = FILE_TYPE_MP3;
58-
else if (!ext.compare(".OGG"))
57+
}
58+
else if (strncasecmp(ext, "ogg", 3) == 0) {
5959
file_type = FILE_TYPE_OGG;
60-
else if (!ext.compare(".OPUS"))
60+
}
61+
else if (strncasecmp(ext, "opus", 4) == 0) {
6162
file_type = FILE_TYPE_OPUS;
62-
else if (!ext.compare(".WAV"))
63+
}
64+
else if (strncasecmp(ext, "wav", 3) == 0) {
6365
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)) {
6569
file_type = FILE_TYPE_XM;
70+
}
6671

6772
switch(file_type) {
6873
case FILE_TYPE_FLAC:
@@ -184,9 +189,8 @@ namespace Audio {
184189
(* decoder.term)();
185190

186191
// 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);
190194
}
191195

192196
metadata = { 0 };

0 commit comments

Comments
 (0)