Skip to content

Commit

Permalink
Merge pull request #198 from unknownbrackets/mp3
Browse files Browse the repository at this point in the history
Add initial tests for sceMp3 functions
  • Loading branch information
hrydgard authored Apr 24, 2019
2 parents 32d3e04 + 207be3b commit 3aa0b00
Show file tree
Hide file tree
Showing 39 changed files with 1,755 additions and 24 deletions.
30 changes: 6 additions & 24 deletions tests/audio/mp3/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
TARGET = mp3test
OBJS = mp3test.o
PSP_EBOOT_TITLE = mp3test test
TARGETS = mp3test initresource reserve release infotoadd notifyadd checkneeded init \
getsamplerate getbitrate getchannel getmpegversion getmaxoutput
EXTRA_OBJS = mp3-imports.o
EXTRA_LIBS = -lpspaudio -lpspmp3 -lstdc++ -lc

BUILD_PRX = 1
PSP_FW_VERSION = 500

PSP_DRIVE = /cygdrive/j
USE_PSPSDK_LIBC = 1

INCDIR = ../../../common
CFLAGS = -g -G0 -Wall -O0 -fno-strict-aliasing
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR = ../../../common
LDFLAGS = -G0
LIBS= -lpspaudio -lpspsnd -lpspmp3 -lpspgu -lpsprtc -lpspctrl -lpspmath -lcommon -lc -lm

EXTRA_TARGETS = EBOOT.PBP
#PSP_EBOOT_ICON = icon.png

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

COMMON_DIR = ../../../common
include $(COMMON_DIR)/common.mk
90 changes: 90 additions & 0 deletions tests/audio/mp3/checkneeded.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <common.h>
#include <pspmp3.h>
#include <psputility.h>

static u8 dummyMp3[72] __attribute__((aligned(64))) = {
0xFF, 0xE3, 0x18, 0xC4,
0x00, 0x00, 0x00, 0x03,
0x48, 0x00, 0x00, 0x00,
0x00, 0x4C, 0x41, 0x4D,
0x45, 0x33, 0x2E, 0x39,
0x38, 0x2E, 0x32, 0x00,
};
static u8 mp3Buf[8192] __attribute__((aligned(64)));
static short pcmBuf[4608] __attribute__((aligned(64)));

static void testCheckNeeded(const char *title, int handle) {
int result = sceMp3CheckStreamDataNeeded(handle);
checkpoint("%s: %08x", title, result);
}

extern "C" int main(int argc, char *argv[]) {
sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
sceUtilityLoadModule(PSP_MODULE_AV_MP3);

sceMp3InitResource();

u8 *dst = (u8 *)-1, *dst2 = NULL;
SceInt32 towrite = 0x1337, towrite2 = 0;
SceInt32 srcpos = 0x1337, srcpos2 = 0;
int handle;

SceMp3InitArg mp3Init;
mp3Init.mp3StreamStart = 0;
mp3Init.mp3StreamEnd = sizeof(dummyMp3);
mp3Init.unk1 = 0;
mp3Init.unk2 = 0;
mp3Init.mp3Buf = mp3Buf;
mp3Init.mp3BufSize = sizeof(mp3Buf);
mp3Init.pcmBuf = pcmBuf;
mp3Init.pcmBufSize = sizeof(pcmBuf);

checkpointNext("Handles");
testCheckNeeded(" Unreserved", 0);
handle = sceMp3ReserveMp3Handle(NULL);
testCheckNeeded(" NULL info arg", handle);
sceMp3ReleaseMp3Handle(handle);
handle = sceMp3ReserveMp3Handle(&mp3Init);
testCheckNeeded(" Basic info arg", handle);
sceMp3ReleaseMp3Handle(handle);
testCheckNeeded(" Negative", -1);
testCheckNeeded(" 2", 2);

handle = sceMp3ReserveMp3Handle(&mp3Init);
checkpointNext("Sequence");
testCheckNeeded(" First", handle);
testCheckNeeded(" Second", handle);
sceMp3GetInfoToAddStreamData(handle, &dst, &towrite, &srcpos);
int maxcopy = (int)sizeof(dummyMp3) / 2 > towrite ? towrite : (int)sizeof(dummyMp3) / 2;
memcpy(dst, dummyMp3, maxcopy);
sceMp3NotifyAddStreamData(handle, maxcopy);
testCheckNeeded(" Add half", handle);
sceMp3GetInfoToAddStreamData(handle, &dst, &towrite, &srcpos);
maxcopy = (int)sizeof(dummyMp3) / 2 > towrite ? towrite : (int)sizeof(dummyMp3) / 2;
if (srcpos + maxcopy <= (int)sizeof(dummyMp3)) {
memcpy(dst, dummyMp3 + srcpos, maxcopy);
sceMp3NotifyAddStreamData(handle, maxcopy);
testCheckNeeded(" Add remaining", handle);
}
sceMp3ReleaseMp3Handle(handle);

handle = sceMp3ReserveMp3Handle(&mp3Init);
checkpointNext("Post decode");
sceMp3GetInfoToAddStreamData(handle, &dst, &towrite, &srcpos);
maxcopy = (int)sizeof(dummyMp3) > towrite ? towrite : (int)sizeof(dummyMp3);
if (srcpos + maxcopy <= (int)sizeof(dummyMp3)) {
memcpy(dst, dummyMp3 + srcpos, maxcopy);
}
sceMp3NotifyAddStreamData(handle, maxcopy);

testCheckNeeded(" After add", handle);
short *out = NULL;
sceMp3Init(handle);
sceMp3Decode(handle, &out);
testCheckNeeded(" After decode", handle);

handle = sceMp3ReserveMp3Handle(&mp3Init);
sceMp3TermResource();
checkpointNext("After term");
testCheckNeeded(" Prev allocated handle", handle);
}
19 changes: 19 additions & 0 deletions tests/audio/mp3/checkneeded.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[x] Handles
[x] Unreserved: 80671102
[x] NULL info arg: 80671102
[x] Basic info arg: 00000001
[x] Negative: 80671001
[x] 2: 80671001

[x] Sequence
[x] First: 00000001
[x] Second: 00000001
[x] Add half: 00000001
[x] Add remaining: 00000000

[x] Post decode
[x] After add: 00000000
[r] After decode: 00000000

[x] After term
[x] Prev allocated handle: 80671102
Binary file added tests/audio/mp3/checkneeded.prx
Binary file not shown.
124 changes: 124 additions & 0 deletions tests/audio/mp3/getbitrate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <common.h>
#include <pspiofilemgr.h>
#include <pspmp3.h>
#include <psputility.h>
#include <psputils.h>

extern "C" int sceMp3LowLevelInit(int handle, int unk);
extern "C" int sceMp3LowLevelDecode(int handle, const void *src, int *srcConsumed, short *samples, int *sampleBytesWritten);

static u8 mp3Buf[8192] __attribute__((aligned(64)));
static short pcmBuf[4608] __attribute__((aligned(64)));

static int initHeader(SceMp3InitArg *mp3Init, const u8 *header, int size, int offset = 0) {
memset(mp3Buf, 0, sizeof(mp3Buf));
int handle = sceMp3ReserveMp3Handle(mp3Init);
if (handle < 0) {
return handle;
}

u8 *dst = NULL;
int result = sceMp3GetInfoToAddStreamData(handle, &dst, NULL, NULL);
if (result < 0) {
sceMp3ReleaseMp3Handle(handle);
return result;
}

memcpy(dst + offset, header, size);
sceKernelDcacheWritebackInvalidateRange(mp3Buf, sizeof(mp3Buf));

result = sceMp3Init(handle);
if (result < 0) {
sceMp3ReleaseMp3Handle(handle);
return result;
}
return handle;
}

static void testGetBitRate(const char *title, int handle) {
int result = sceMp3GetBitRate(handle);
if (result >= 0) {
checkpoint("%s: %d", title, result);
} else {
checkpoint("%s: %08x", title, result);
}
}

extern "C" int main(int argc, char *argv[]) {
sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
sceUtilityLoadModule(PSP_MODULE_AV_MP3);

sceMp3InitResource();

int fd = sceIoOpen("sample.mp3", PSP_O_RDONLY, 0777);

short *out = NULL;
int handle;

SceMp3InitArg mp3Init;
mp3Init.mp3StreamStart = 0;
mp3Init.mp3StreamEnd = sceIoLseek32(fd, 0, SEEK_END);
mp3Init.unk1 = 0;
mp3Init.unk2 = 0;
mp3Init.mp3Buf = mp3Buf;
mp3Init.mp3BufSize = sizeof(mp3Buf);
mp3Init.pcmBuf = pcmBuf;
mp3Init.pcmBufSize = sizeof(pcmBuf);

checkpointNext("Handles");
testGetBitRate(" Unreserved", 0);
handle = sceMp3ReserveMp3Handle(NULL);
testGetBitRate(" NULL info arg", handle);
sceMp3ReleaseMp3Handle(handle);
handle = sceMp3ReserveMp3Handle(&mp3Init);
testGetBitRate(" Basic info arg", handle);
sceMp3ReleaseMp3Handle(handle);
testGetBitRate(" Negative", -1);
testGetBitRate(" 2", 2);

static const u8 baseHeader[] = {
0xFF, 0xFB, 0x10, 0x00,
};

checkpointNext("After init");
handle = sceMp3ReserveMp3Handle(NULL);
sceMp3LowLevelInit(handle, 0);
testGetBitRate(" Low level init", handle);
sceIoLseek32(fd, 0, SEEK_SET);
sceIoRead(fd, mp3Buf, 4096);
int consumed, written;
sceMp3LowLevelDecode(handle, mp3Buf, &consumed, pcmBuf, &written);
testGetBitRate(" Low level decode", handle);
sceMp3ReleaseMp3Handle(handle);
handle = initHeader(&mp3Init, baseHeader, sizeof(baseHeader));
testGetBitRate(" After init", handle);
sceMp3ReleaseMp3Handle(handle);
handle = initHeader(&mp3Init, baseHeader, sizeof(baseHeader));
sceMp3Decode(handle, &out);
testGetBitRate(" After decode", handle);
sceMp3ReleaseMp3Handle(handle);

checkpointNext("Bitrates");
static const int bitrates[] = { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1 };
for (int bits = 0; bits < ARRAY_SIZE(bitrates); ++bits) {
char temp[64];
snprintf(temp, sizeof(temp), " Bitrate %d", bitrates[bits]);
u8 header[4];
memcpy(header, baseHeader, sizeof(header));
header[2] = bits << 4;
handle = initHeader(&mp3Init, header, sizeof(header));
if (handle < 0) {
checkpoint("%s: Failed (%08x)", temp, handle);
} else {
testGetBitRate(temp, handle);
}
sceMp3ReleaseMp3Handle(handle);
}

handle = sceMp3ReserveMp3Handle(&mp3Init);
sceMp3TermResource();
checkpointNext("After term");
testGetBitRate(" Prev allocated handle", handle);

return 0;
}
33 changes: 33 additions & 0 deletions tests/audio/mp3/getbitrate.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[x] Handles
[x] Unreserved: 80671103
[x] NULL info arg: 80671103
[x] Basic info arg: 80671103
[x] Negative: 80671001
[x] 2: 80671001

[x] After init
[r] Low level init: 0
[r] Low level decode: 0
[r] After init: 32
[r] After decode: 32

[x] Bitrates
[r] Bitrate 0: Failed (807f00fd)
[r] Bitrate 32: 32
[r] Bitrate 40: 40
[r] Bitrate 48: 48
[r] Bitrate 56: 56
[r] Bitrate 64: 64
[r] Bitrate 80: 80
[r] Bitrate 96: 96
[r] Bitrate 112: 112
[r] Bitrate 128: 128
[r] Bitrate 160: 160
[r] Bitrate 192: 192
[r] Bitrate 224: 224
[r] Bitrate 256: 256
[r] Bitrate 320: 320
[r] Bitrate -1: Failed (807f00fd)

[x] After term
[x] Prev allocated handle: 80671103
Binary file added tests/audio/mp3/getbitrate.prx
Binary file not shown.
Loading

0 comments on commit 3aa0b00

Please sign in to comment.