Skip to content

Commit 28610b5

Browse files
committed
audio: Use opus libs from pspsdk-packages
1 parent 37c7cdf commit 28610b5

17 files changed

Lines changed: 125 additions & 5610 deletions

File tree

app/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ VERSION_MAJOR := 4
1414
VERSION_MINOR := 1
1515
VERSION_MICRO := 2
1616

17-
INCDIR = ../libs/ ../libs/include ../libs/include/libtiff ../libs/libnsbmp ../libs/libnsgif \
18-
../libs/include/opus include
17+
INCDIR = ../libs/ ../libs/include ../libs/include/libtiff ../libs/libnsbmp ../libs/libnsgif include
1918
CFLAGS = -Os -mno-gpopt -Wall -ffast-math -Wno-narrowing -Wno-unused-variable \
20-
-DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_MICRO=$(VERSION_MICRO)
19+
-DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_MICRO=$(VERSION_MICRO) \
20+
-I$(PSPDEV)/psp/include/opus
2121
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -std=gnu++17
2222
ASFLAGS := $(CFLAGS)
2323

2424
BUILD_PRX = 1
2525

2626
LIBDIR = ../libs/lib
2727
LDFLAGS =
28-
LIBS = -lintrafont -lglib2d -lxmp -lmpg123 -lvorbisfile -lvorbis -lopusfile -lopus -lFLAC -logg \
28+
LIBS = -lintrafont -lglib2d -lxmp-lite -lmpg123 -lvorbisfile -lvorbis -lopusfile -lopus -lFLAC -logg \
2929
-larchive -ltiff -lbz2 -llzma -lturbojpeg -ljpeg -lpng16 -lstdc++ -lz \
3030
-lpspkubridge -lpspsystemctrl_user -lpspusbdevice \
3131
-lpspgu -lpspvram -lpspaudio -lpsppower -lpspreg -lpspusb -lpspusbstor -lpspumd

app/include/audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
extern bool playing, paused;
88

99
typedef struct {
10-
bool has_meta = false;
10+
bool hasMeta = false;
1111
std::string title;
1212
std::string album;
1313
std::string artist;
1414
std::string year;
1515
std::string comment;
1616
std::string genre;
17-
g2dTexture *cover_image;
17+
g2dTexture *image;
1818
} AudioMetadata;
1919

2020
extern AudioMetadata metadata;

app/source/audio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ namespace Audio {
189189
(* decoder.term)();
190190

191191
// Clear metadata struct
192-
if (metadata.has_meta && metadata.cover_image) {
193-
g2dTexFree(&metadata.cover_image);
192+
if (metadata.hasMeta && metadata.image) {
193+
g2dTexFree(&metadata.image);
194194
}
195195

196196
metadata = { 0 };

app/source/audio/flac.cpp

Lines changed: 59 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,44 @@ namespace FLAC {
1010
const FLAC__Frame *frame = nullptr;
1111
const FLAC__int32 * const *buffer = nullptr;
1212
FLAC__uint8 channels = 0;
13-
FLAC__uint32 sample_rate = 0;
13+
FLAC__uint32 rate = 0;
1414
FLAC__uint32 bps = 0;
1515
FLAC__uint64 position = 0;
16-
FLAC__uint64 samples_read = 0;
17-
FLAC__uint64 total_samples = 0;
16+
FLAC__uint64 samples = 0;
17+
FLAC__uint64 totalSamples = 0;
1818
} FLACInfo;
1919

2020
static FLAC__StreamDecoder *flac = nullptr;
21-
static FLACInfo cb_info { 0 };
21+
static FLACInfo info { 0 };
2222

23-
static FLAC__StreamDecoderWriteStatus WriteCB(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) {
23+
static FLAC__StreamDecoderWriteStatus WriteCB(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data) {
2424
FLACInfo *info = reinterpret_cast<FLACInfo *>(client_data);
2525

26-
if (info->total_samples == 0) {
27-
Log::Error("No samples to decode!\n");
26+
if (info->totalSamples == 0) {
27+
Log::Error("This decoder only works for FLAC files that have a total_samples count in STREAMINFO\n");
2828
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
2929
}
3030
if ((info->channels != 2) || (info->bps != 16)) {
31-
Log::Error("Not stereo 16-bit!\n");
31+
Log::Error("This decoder only supports 16bit stereo streams\n");
32+
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
33+
}
34+
if (frame->header.channels != 2) {
35+
Log::Error("This frame contains %u channels (should be 2)\n", frame->header.channels);
36+
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
37+
}
38+
if (buffer[0] == NULL) {
39+
Log::Error("buffer [0] is NULL\n");
40+
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
41+
}
42+
if (buffer[1] == NULL) {
43+
Log::Error("buffer [1] is NULL\n");
3244
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
3345
}
3446

3547
info->frame = frame;
3648
info->buffer = buffer;
3749
info->position = 0;
38-
info->samples_read = frame->header.number.sample_number;
50+
info->samples = frame->header.number.sample_number;
3951
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
4052
}
4153

@@ -44,43 +56,40 @@ namespace FLAC {
4456

4557
switch (stream->type) {
4658
case FLAC__METADATA_TYPE_STREAMINFO:
47-
info->total_samples = stream->data.stream_info.total_samples;
48-
info->sample_rate = stream->data.stream_info.sample_rate;
59+
info->totalSamples = stream->data.stream_info.total_samples;
60+
info->rate = stream->data.stream_info.sample_rate;
4961
info->channels = stream->data.stream_info.channels;
5062
info->bps = stream->data.stream_info.bits_per_sample;
5163
break;
5264

5365
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
5466
for (FLAC__uint32 i = 0; i < stream->data.vorbis_comment.num_comments; i++) {
5567
char *tag = reinterpret_cast<char *>(stream->data.vorbis_comment.comments[i].entry);
68+
if (tag != nullptr) {
69+
metadata.hasMeta = true;
70+
}
5671

5772
if (!strncasecmp("TITLE=", tag, 6)) {
58-
metadata.has_meta = true;
5973
metadata.title = tag + 6;
6074
}
6175

6276
if (!strncasecmp("ALBUM=", tag, 6)) {
63-
metadata.has_meta = true;
6477
metadata.album = tag + 6;
6578
}
6679

6780
if (!strncasecmp("ARTIST=", tag, 7)) {
68-
metadata.has_meta = true;
6981
metadata.artist = tag + 7;
7082
}
7183

7284
if (!strncasecmp("DATE=", tag, 5)) {
73-
metadata.has_meta = true;
7485
metadata.year = tag + 5;
7586
}
7687

7788
if (!strncasecmp("COMMENT=", tag, 8)) {
78-
metadata.has_meta = true;
7989
metadata.comment = tag + 8;
8090
}
8191

8292
if (!strncasecmp("GENRE=", tag, 6)) {
83-
metadata.has_meta = true;
8493
metadata.genre = tag + 6;
8594
}
8695
}
@@ -89,16 +98,14 @@ namespace FLAC {
8998
case FLAC__METADATA_TYPE_PICTURE:
9099
if (stream->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER) {
91100
if ((!strcasecmp(stream->data.picture.mime_type, "image/jpeg")) || (!strcasecmp(stream->data.picture.mime_type, "image/jpg"))) {
92-
metadata.has_meta = true;
93-
94-
if (!metadata.cover_image)
95-
metadata.cover_image = Textures::LoadImageBufferJPEG(stream->data.picture.data, stream->data.picture.data_length);
101+
if (!metadata.image) {
102+
metadata.image = Textures::LoadImageBufferJPEG(stream->data.picture.data, stream->data.picture.data_length);
103+
}
96104
}
97105
else if (!strcasecmp(stream->data.picture.mime_type, "image/png")) {
98-
metadata.has_meta = true;
99-
100-
if (!metadata.cover_image)
101-
metadata.cover_image = Textures::LoadImageBufferPNG(stream->data.picture.data, stream->data.picture.data_length);
106+
if (!metadata.image) {
107+
metadata.image = Textures::LoadImageBufferPNG(stream->data.picture.data, stream->data.picture.data_length);
108+
}
102109
}
103110
}
104111
break;
@@ -109,53 +116,34 @@ namespace FLAC {
109116
}
110117

111118
static void ErrorCB(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) {
112-
std::string error;
113-
114-
switch(status) {
115-
case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
116-
error = "Lost sync";
117-
break;
118-
119-
case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
120-
error = "Bad header";
121-
break;
122-
123-
case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH:
124-
error = "Frame CRC mismatch";
125-
break;
126-
127-
case FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM:
128-
error = "Unparseable stream";
129-
break;
130-
131-
default:
132-
break;
133-
}
134-
135-
Log::Error("error: %s\n", error.c_str());
119+
Log::Error("FLAC error callback: %s\n", FLAC__StreamDecoderErrorStatusString[status]);
136120
}
137121

138122
int Init(const std::string &path) {
139123
FLAC__StreamDecoderInitStatus ret = FLAC__STREAM_DECODER_INIT_STATUS_OK;
140124

141-
if ((flac = FLAC__stream_decoder_new()) == nullptr)
125+
if ((flac = FLAC__stream_decoder_new()) == nullptr) {
142126
return -1;
127+
}
143128

144129
if (FLAC__stream_decoder_set_metadata_respond(flac, FLAC__METADATA_TYPE_STREAMINFO) == false) {
145130
Log::Error("FLAC__METADATA_TYPE_STREAMINFO response failed\n");
146131
return -1;
147132
}
148133

149-
if (FLAC__stream_decoder_set_metadata_respond(flac, FLAC__METADATA_TYPE_SEEKTABLE) == false)
134+
if (FLAC__stream_decoder_set_metadata_respond(flac, FLAC__METADATA_TYPE_SEEKTABLE) == false) {
150135
Log::Error("FLAC__METADATA_TYPE_SEEKTABLE response failed\n");
136+
}
151137

152-
if (FLAC__stream_decoder_set_metadata_respond(flac, FLAC__METADATA_TYPE_VORBIS_COMMENT) == false)
138+
if (FLAC__stream_decoder_set_metadata_respond(flac, FLAC__METADATA_TYPE_VORBIS_COMMENT) == false) {
153139
Log::Error("FLAC__METADATA_TYPE_VORBIS_COMMENT response failed\n");
140+
}
154141

155-
if (FLAC__stream_decoder_set_metadata_respond(flac, FLAC__METADATA_TYPE_PICTURE) == false)
142+
if (FLAC__stream_decoder_set_metadata_respond(flac, FLAC__METADATA_TYPE_PICTURE) == false) {
156143
Log::Error("FLAC__METADATA_TYPE_PICTURE response failed\n");
144+
}
157145

158-
if ((ret = FLAC__stream_decoder_init_file(flac, path.c_str(), FLAC::WriteCB, FLAC::MetadataCB, FLAC::ErrorCB, &cb_info)) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
146+
if ((ret = FLAC__stream_decoder_init_file(flac, path.c_str(), FLAC::WriteCB, FLAC::MetadataCB, FLAC::ErrorCB, &info)) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
159147
Log::Error("FLAC__stream_decoder_init_file failed: %s\n", FLAC__StreamDecoderInitStatusString[ret]);
160148
return ret;
161149
}
@@ -164,28 +152,31 @@ namespace FLAC {
164152
}
165153

166154
u32 GetSampleRate(void) {
167-
return cb_info.sample_rate;
155+
return info.rate;
168156
}
169157

170158
u8 GetChannels(void) {
171-
return cb_info.channels;
159+
return info.channels;
172160
}
173161

174162
void Decode(void *buf, unsigned int length, void *userdata) {
175163
unsigned int decoded = 0;
176164
FLAC__bool ret = false;
177165

178-
if (length <= 0)
166+
if (length <= 0) {
179167
return;
168+
}
180169

181170
FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(flac);
182-
if (state == FLAC__STREAM_DECODER_END_OF_STREAM)
171+
if (state == FLAC__STREAM_DECODER_END_OF_STREAM) {
183172
playing = false;
184-
else if (state == FLAC__STREAM_DECODER_ABORTED)
173+
}
174+
else if (state == FLAC__STREAM_DECODER_ABORTED) {
185175
return;
176+
}
186177

187178
while(decoded < length) {
188-
if ((cb_info.frame == nullptr) || (cb_info.position == cb_info.frame->header.blocksize)) {
179+
if ((info.frame == nullptr) || (info.position == info.frame->header.blocksize)) {
189180
ret = FLAC__stream_decoder_process_single(flac);
190181

191182
if (ret == false) {
@@ -201,30 +192,30 @@ namespace FLAC {
201192
}
202193
}
203194

204-
for(; decoded < length && cb_info.position < cb_info.frame->header.blocksize; cb_info.position++, decoded++) {
195+
for(; decoded < length && info.position < info.frame->header.blocksize; info.position++, decoded++) {
205196
// Copy to buffer here; convert from BE to LE
206197
short *buffer = static_cast<short *>(buf);
207-
buffer[decoded * 2] = cb_info.buffer[0][cb_info.position];
208-
buffer[decoded * 2 + 1] = cb_info.buffer[1][cb_info.position];
198+
buffer[decoded * 2] = info.buffer[0][info.position];
199+
buffer[decoded * 2 + 1] = info.buffer[1][info.position];
209200
}
210201
}
211202
}
212203

213204
u64 GetPosition(void) {
214-
return cb_info.samples_read;
205+
return info.samples;
215206
}
216207

217208
u64 GetLength(void) {
218-
return cb_info.total_samples;
209+
return info.totalSamples;
219210
}
220211

221212
u64 Seek(u64 index) {
222-
FLAC__uint64 seek_sample = (cb_info.total_samples * (index / 225.0));
223-
return FLAC__stream_decoder_seek_absolute(flac, seek_sample);
213+
FLAC__uint64 seek = (info.totalSamples * (index / 225.0));
214+
return FLAC__stream_decoder_seek_absolute(flac, seek);
224215
}
225216

226217
void Exit(void) {
227-
cb_info = { 0 };
218+
info = { 0 };
228219
FLAC__stream_decoder_finish(flac);
229220
FLAC__stream_decoder_delete(flac);
230221
}

app/source/audio/mp3.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ namespace MP3 {
144144
}
145145

146146
mpg123_seek(mp3, 0, SEEK_SET);
147-
metadata.has_meta = mpg123_meta_check(mp3);
147+
metadata.hasMeta = mpg123_meta_check(mp3);
148148

149149
mpg123_id3v1 *id3v1;
150150
mpg123_id3v2 *id3v2;
151-
if (metadata.has_meta & MPG123_ID3 && mpg123_id3(mp3, &id3v1, &id3v2) == MPG123_OK) {
151+
if (metadata.hasMeta & MPG123_ID3 && mpg123_id3(mp3, &id3v1, &id3v2) == MPG123_OK) {
152152
if (id3v1)
153153
MP3::ProcessID3v1(metadata, id3v1);
154154
if (id3v2)
@@ -160,15 +160,15 @@ namespace MP3 {
160160
// Front cover or other
161161
if ((pic->type == 3)) {
162162
if ((!strcasecmp(pic->mime_type.p, "image/jpeg")) || (!strcasecmp(pic->mime_type.p, "image/jpg"))) {
163-
metadata.cover_image = Textures::LoadImageBufferJPEG(pic->data, pic->size);
163+
metadata.image = Textures::LoadImageBufferJPEG(pic->data, pic->size);
164164
break;
165165
}
166166
else if (!strcasecmp(pic->mime_type.p, "image/png")) {
167-
metadata.cover_image = Textures::LoadImageBufferPNG(pic->data, pic->size);
167+
metadata.image = Textures::LoadImageBufferPNG(pic->data, pic->size);
168168

169169
// I have trust issues
170-
if (!metadata.cover_image)
171-
metadata.cover_image = Textures::LoadImageBufferJPEG(pic->data, pic->size);
170+
if (!metadata.image)
171+
metadata.image = Textures::LoadImageBufferJPEG(pic->data, pic->size);
172172

173173
break;
174174
}

app/source/audio/ogg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace OGG {
4949
vorbis_comment *comment = ov_comment(&ogg, -1);
5050

5151
if (comment != nullptr) {
52-
metadata.has_meta = true;
52+
metadata.hasMeta = true;
5353
char *value = nullptr;
5454

5555
if ((value = vorbis_comment_query(comment, "title", 0)) != nullptr)

0 commit comments

Comments
 (0)