U3-Robot
August 14th, 2009, 17:23
Why kgsws's test file for MOHH exploit (from sdk folder) not compiling? I only modified main.c to load mp3 file. I also included audio libs in the makefile (wrong?) and write includes in sdk.h.
BUT I GET MANY ERRORS:
Microsoft Windows XP [Версия 5.1.2600]
(С) Корпорация Майкрософт, 1985-2001.
K:\Documents and Settings\ADMIN>cd K:\Documents and Settings\ADMIN\Рабочий стол\
mohexploitv2\src\sdk
K:\Documents and Settings\ADMIN\Рабочий стол\mohexploitv2\src\sdk>make clean
rm -rf *~ *.o *.elf *.bin main.s *.bin test
K:\Documents and Settings\ADMIN\Рабочий стол\mohexploitv2\src\sdk>make
psp-gcc -D PSP -I K:/pspsdk/psp/sdk/include -W -Wall -O2 -G0 -fno-pic -mno-abica
lls -w -fomit-frame-pointer -S main.c -o main.s
psp-as main.s -o main.o
psp-gcc -D PSP -I K:/pspsdk/psp/sdk/include -W -Wall -O2 -G0 -fno-pic -mno-abica
lls -w -fomit-frame-pointer -S lib.c -o lib.s
psp-as lib.s -o lib.o
psp-as sdk.S -o sdk.o
K:/pspsdk/bin/psp-ld -T linker.x -LK:/pspsdk/psp/sdk/lib main.o lib.o sdk.o -o m
ain.elf
K:/pspsdk/bin/psp-ld: warning: cannot find entry symbol _start; defaulting to 00
00000008e50000
main.o: In function `error':
main.c:(.text+0x1c): undefined reference to `pspDebugScreenClear'
main.c:(.text+0x28): undefined reference to `pspDebugScreenSetXY'
main.c:(.text+0x30): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x40): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x5c): undefined reference to `sceDisplayWaitVblankStart'
main.c:(.text+0x70): undefined reference to `sceCtrlReadBufferPositive'
main.o: In function `fillStreamBuffer':
main.c:(.text+0xc8): undefined reference to `sceMp3GetInfoToAddStreamData'
main.c:(.text+0xdc): undefined reference to `sceIoLseek32'
main.c:(.text+0x134): undefined reference to `sprintf'
main.c:(.text+0x148): undefined reference to `sceMp3NotifyAddStreamData'
main.c:(.text+0x184): undefined reference to `sprintf'
main.c:(.text+0x1b0): undefined reference to `sprintf'
main.c:(.text+0x1c8): undefined reference to `sceIoLseek32'
main.c:(.text+0x1e8): undefined reference to `sprintf'
main.o: In function `main':
main.c:(.text+0x284): undefined reference to `pspDebugScreenInit'
main.c:(.text+0x28c): undefined reference to `pspDebugScreenClear'
main.c:(.text+0x2ac): undefined reference to `sceUtilityLoadModule'
main.c:(.text+0x2bc): undefined reference to `sceUtilityLoadModule'
main.c:(.text+0x2e8): undefined reference to `sceMp3InitResource'
main.c:(.text+0x304): undefined reference to `sceIoLseek32'
main.c:(.text+0x340): undefined reference to `sceMp3ReserveMp3Handle'
main.c:(.text+0x35c): undefined reference to `sceMp3Init'
main.c:(.text+0x36c): undefined reference to `sceMp3GetSamplingRate'
main.c:(.text+0x378): undefined reference to `sceMp3GetMp3ChannelNum'
main.c:(.text+0x3b4): undefined reference to `sceDisplayWaitVblankStart'
main.c:(.text+0x3c0): undefined reference to `pspDebugScreenSetXY'
main.c:(.text+0x3cc): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x3e0): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x3f0): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x3f8): undefined reference to `sceMp3GetBitRate'
main.c:(.text+0x408): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x430): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x450): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x488): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x494): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x4ec): undefined reference to `sceMp3SetLoopNum'
main.c:(.text+0x528): undefined reference to `sceAudioSRCChRelease'
main.c:(.text+0x530): undefined reference to `sceMp3ReleaseMp3Handle'
main.c:(.text+0x540): undefined reference to `sceMp3TermResource'
main.c:(.text+0x5a8): undefined reference to `sprintf'
main.c:(.text+0x5c0): undefined reference to `sceMp3CheckStreamDataNeeded'
main.c:(.text+0x5dc): undefined reference to `sceMp3Decode'
main.c:(.text+0x5ec): undefined reference to `sceMp3CheckStreamDataNeeded'
main.c:(.text+0x610): undefined reference to `sceMp3ResetPlayPosition'
main.c:(.text+0x64c): undefined reference to `sprintf'
main.c:(.text+0x674): undefined reference to `sceAudioSRCChRelease'
main.c:(.text+0x694): undefined reference to `sceAudioSRCChReserve'
main.c:(.text+0x6a4): undefined reference to `sceAudioSRCOutputBlocking'
main.c:(.text+0x6b4): undefined reference to `sceMp3ResetPlayPosition'
main.c:(.text+0x6d4): undefined reference to `sprintf'
main.c:(.text+0x72c): undefined reference to `sprintf'
main.c:(.text+0x73c): undefined reference to `sceUtilityLoadModule'
main.c:(.text+0x75c): undefined reference to `sprintf'
main.c:(.text+0x7a0): undefined reference to `sprintf'
main.c:(.text+0x7b0): undefined reference to `sceMp3InitResource'
main.c:(.text+0x7d0): undefined reference to `sprintf'
main.c:(.text+0x7f8): undefined reference to `sprintf'
main.c:(.text+0x814): undefined reference to `sceMp3Init'
main.c:(.text+0x834): undefined reference to `sprintf'
main.c:(.text+0x858): undefined reference to `sprintf'
main.c:(.text+0x868): undefined reference to `sceMp3TermResource'
main.c:(.text+0x884): undefined reference to `sprintf'
main.o: In function `CallbackThread':
main.c:(.text+0x8b4): undefined reference to `sceKernelCreateCallback'
main.c:(.text+0x8bc): undefined reference to `sceKernelRegisterExitCallback'
main.c:(.text+0x8c4): undefined reference to `sceKernelSleepThreadCB'
main.o:(.rodata.sceModuleInfo+0x20): undefined reference to `_gp'
make: *** [main] Error 1
K:\Documents and Settings\ADMIN\Рабочий стол\mohexploitv2\src\sdkThat means, that some libs are unacessible!
Here is my main.c:
#include "sdk.h"
/* Define the module info section */
PSP_MODULE_INFO("Mp3Test", 0, 0, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(-1024);
#define MP3FILE "ms0:/test.mp3"
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
static int isrunning = 1;
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
isrunning = 0;
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if (thid >= 0)
sceKernelStartThread(thid, 0, 0);
return thid;
}
// Input and Output buffers
char mp3Buf[16*1024] __attribute__((aligned(64)));
short pcmBuf[16*(1152/2)] __attribute__((aligned(64)));
// Macro to allow formatted input without having to use stdargs.h
#define ERRORMSG(...) { char msg[128]; sprintf(msg,__VA_ARGS__); error(msg); }
// Print out an error message and quit after user input
void error( char* msg )
{
SceCtrlData pad;
pspDebugScreenClear();
pspDebugScreenSetXY(0, 0);
printf(msg);
printf("Press X to quit.\n");
while (isrunning)
{
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CROSS)
break;
sceDisplayWaitVblankStart();
}
sceKernelExitGame();
}
int fillStreamBuffer( int fd, int handle )
{
char* dst;
int write;
int pos;
// Get Info on the stream (where to fill to, how much to fill, where to fill from)
int status = sceMp3GetInfoToAddStreamData( handle, &dst, &write, &pos);
if (status<0)
{
ERRORMSG("ERROR: sceMp3GetInfoToAddStreamData returned 0x%08X\n", status);
}
// Seek file to position requested
status = sceIoLseek32( fd, pos, SEEK_SET );
if (status<0)
{
ERRORMSG("ERROR: sceIoLseek32 returned 0x%08X\n", status);
}
// Read the amount of data
int read = sceIoRead( fd, dst, write );
if (read < 0)
{
ERRORMSG("ERROR: Could not read from file - 0x%08X\n", read);
}
if (read==0)
{
// End of file?
return 0;
}
// Notify mp3 library about how much we really wrote to the stream buffer
status = sceMp3NotifyAddStreamData( handle, read );
if (status<0)
{
ERRORMSG("ERROR: sceMp3NotifyAddStreamData returned 0x%08X\n", status);
}
return (pos>0);
}
/* main routine */
int main(int argc, char *argv[])
{
SceCtrlData pad;
//init screen and callbacks
pspDebugScreenInit();
pspDebugScreenClear();
SetupCallbacks();
// Setup Pad
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(0);
// Load modules
int status = sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
if (status<0)
{
ERRORMSG("ERROR: sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC) returned 0x%08X\n", status);
}
status = sceUtilityLoadModule(PSP_MODULE_AV_MP3);
if (status<0)
{
ERRORMSG("ERROR: sceUtilityLoadModule(PSP_MODULE_AV_MP3) returned 0x%08X\n", status);
}
// Open the input file
int fd = sceIoOpen( MP3FILE, PSP_O_RDONLY, 0777 );
if (fd<0)
{
ERRORMSG("ERROR: Could not open file '%s' - 0x%08X\n", MP3FILE, fd);
}
// Init mp3 resources
status = sceMp3InitResource();
if (status<0)
{
ERRORMSG("ERROR: sceMp3InitResource returned 0x%08X\n", status);
}
// Reserve a mp3 handle for our playback
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);
int handle = sceMp3ReserveMp3Handle( &mp3Init );
if (handle<0)
{
ERRORMSG("ERROR: sceMp3ReserveMp3Handle returned 0x%08X\n", handle);
}
// Fill the stream buffer with some data so that sceMp3Init has something to work with
fillStreamBuffer( fd, handle );
status = sceMp3Init( handle );
if (status<0)
{
ERRORMSG("ERROR: sceMp3Init returned 0x%08X\n", status);
}
int channel = -1;
int samplingRate = sceMp3GetSamplingRate( handle );
int numChannels = sceMp3GetMp3ChannelNum( handle );
int lastDecoded = 0;
int volume = PSP_AUDIO_VOLUME_MAX;
int numPlayed = 0;
int paused = 0;
int lastButtons = 0;
int loop = 0;
while (isrunning)
{
sceDisplayWaitVblankStart();
pspDebugScreenSetXY(0, 0);
printf("PSP Mp3 Sample v1.0 by Raphael\n\n");
printf("Playing '%s'...\n", MP3FILE);
printf(" %i Hz\n", samplingRate);
printf(" %i kbit/s\n", sceMp3GetBitRate( handle ));
printf(" %s\n", numChannels==2?"Stereo":"Mono");
printf(" %s\n\n", loop==0?"No loop":"Loop");
int playTime = samplingRate>0?numPlayed / samplingRate:0;
printf(" Playtime: %02i:%02i\n", playTime/60, playTime%60 );
printf("\n\n\nPress CIRCLE to Pause/Resume playback\nPress TRIANGLE to reset playback\nPress CROSS to switch loop mode\nPress SQUARE to stop playback and quit\n");
if (!paused)
{
// Check if we need to fill our stream buffer
if (sceMp3CheckStreamDataNeeded( handle )>0)
{
fillStreamBuffer( fd, handle );
}
// Decode some samples
short* buf;
int bytesDecoded;
int retries = 0;
// We retry in case it's just that we reached the end of the stream and need to loop
for (;retries<1;retries++)
{
bytesDecoded = sceMp3Decode( handle, &buf );
if (bytesDecoded>0)
break;
if (sceMp3CheckStreamDataNeeded( handle )<=0)
break;
if (!fillStreamBuffer( fd, handle ))
{
numPlayed = 0;
}
}
if (bytesDecoded<0 && bytesDecoded!=0x80671402)
{
ERRORMSG("ERROR: sceMp3Decode returned 0x%08X\n", bytesDecoded);
}
// Nothing more to decode? Must have reached end of input buffer
if (bytesDecoded==0 || bytesDecoded==0x80671402)
{
paused = 1;
sceMp3ResetPlayPosition( handle );
numPlayed = 0;
}
else
{
// Reserve the Audio channel for our output if not yet done
if (channel<0 || lastDecoded!=bytesDecoded)
{
if (channel>=0)
sceAudioSRCChRelease();
channel = sceAudioSRCChReserve( bytesDecoded/(2*numChannels), samplingRate, numChannels );
}
// Output the decoded samples and accumulate the number of played samples to get the playtime
numPlayed += sceAudioSRCOutputBlocking( volume, buf );
}
}
sceCtrlPeekBufferPositive(&pad, 1);
if (pad.Buttons!=lastButtons)
{
if (pad.Buttons & PSP_CTRL_CIRCLE)
{
paused ^= 1;
}
if (pad.Buttons & PSP_CTRL_TRIANGLE)
{
// Reset the stream and playback status
sceMp3ResetPlayPosition( handle );
numPlayed = 0;
}
if (pad.Buttons & PSP_CTRL_CROSS)
{
loop = (loop==0?-1:0);
status = sceMp3SetLoopNum( handle, loop );
if (status<0)
{
ERRORMSG("ERROR: sceMp3SetLoopNum returned 0x%08X\n", status);
}
}
if (pad.Buttons & PSP_CTRL_SQUARE)
{
break;
}
lastButtons = pad.Buttons;
}
}
// Cleanup time...
if (channel>=0)
sceAudioSRCChRelease();
status = sceMp3ReleaseMp3Handle( handle );
if (status<0)
{
ERRORMSG("ERROR: sceMp3ReleaseMp3Handle returned 0x%08X\n", status);
}
status = sceMp3TermResource();
if (status<0)
{
ERRORMSG("ERROR: sceMp3TermResource returned 0x%08X\n", status);
}
status = sceIoClose( fd );
if (status<0)
{
ERRORMSG("ERROR: sceIoClose returned 0x%08X\n", status);
}
sceKernelExitGame();
return 0;
}Here is my sdk.h:
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <stdio.h>
#include <pspmp3.h>
#include <psputility.h>
#ifndef __MOH-SDK__
#define __MOH-SDK__
typedef unsigned char byte;
#endif
Here is my makefile:
PSPSDK=$(shell psp-config --pspsdk-path)
PSPLIBSDIR = $(PSPSDK)/..
PSPDEV=$(shell psp-config --pspdev-path)
INCLUDE=$(PSPSDK)/include
LIBS = -lpspaudio -lpspmp3
all: main
clean:
rm -rf *~ *.o *.elf *.bin main.s *.bin test
CC = psp-gcc
CFLAGS := -D PSP -I $(INCLUDE) -W -Wall -O2 -G0 -fno-pic -mno-abicalls -w -fomit-frame-pointer
ASM = psp-as
sdk.o: sdk.S
$(ASM) sdk.S -o sdk.o
lib.o: lib.c
$(CC) $(CFLAGS) -S lib.c -o lib.s
$(ASM) lib.s -o lib.o
main.o: main.c
$(CC) $(CFLAGS) -S main.c -o main.s
$(ASM) main.s -o main.o
main: main.o lib.o sdk.o linker.x
$(PSPDEV)/bin/psp-ld -T linker.x -L$(PSPSDK)/lib main.o lib.o sdk.o -o main.elf
$(PSPDEV)/bin/psp-strip -s main.elf
$(PSPDEV)/bin/psp-objcopy -O binary main.elf test
BUT I GET MANY ERRORS:
Microsoft Windows XP [Версия 5.1.2600]
(С) Корпорация Майкрософт, 1985-2001.
K:\Documents and Settings\ADMIN>cd K:\Documents and Settings\ADMIN\Рабочий стол\
mohexploitv2\src\sdk
K:\Documents and Settings\ADMIN\Рабочий стол\mohexploitv2\src\sdk>make clean
rm -rf *~ *.o *.elf *.bin main.s *.bin test
K:\Documents and Settings\ADMIN\Рабочий стол\mohexploitv2\src\sdk>make
psp-gcc -D PSP -I K:/pspsdk/psp/sdk/include -W -Wall -O2 -G0 -fno-pic -mno-abica
lls -w -fomit-frame-pointer -S main.c -o main.s
psp-as main.s -o main.o
psp-gcc -D PSP -I K:/pspsdk/psp/sdk/include -W -Wall -O2 -G0 -fno-pic -mno-abica
lls -w -fomit-frame-pointer -S lib.c -o lib.s
psp-as lib.s -o lib.o
psp-as sdk.S -o sdk.o
K:/pspsdk/bin/psp-ld -T linker.x -LK:/pspsdk/psp/sdk/lib main.o lib.o sdk.o -o m
ain.elf
K:/pspsdk/bin/psp-ld: warning: cannot find entry symbol _start; defaulting to 00
00000008e50000
main.o: In function `error':
main.c:(.text+0x1c): undefined reference to `pspDebugScreenClear'
main.c:(.text+0x28): undefined reference to `pspDebugScreenSetXY'
main.c:(.text+0x30): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x40): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x5c): undefined reference to `sceDisplayWaitVblankStart'
main.c:(.text+0x70): undefined reference to `sceCtrlReadBufferPositive'
main.o: In function `fillStreamBuffer':
main.c:(.text+0xc8): undefined reference to `sceMp3GetInfoToAddStreamData'
main.c:(.text+0xdc): undefined reference to `sceIoLseek32'
main.c:(.text+0x134): undefined reference to `sprintf'
main.c:(.text+0x148): undefined reference to `sceMp3NotifyAddStreamData'
main.c:(.text+0x184): undefined reference to `sprintf'
main.c:(.text+0x1b0): undefined reference to `sprintf'
main.c:(.text+0x1c8): undefined reference to `sceIoLseek32'
main.c:(.text+0x1e8): undefined reference to `sprintf'
main.o: In function `main':
main.c:(.text+0x284): undefined reference to `pspDebugScreenInit'
main.c:(.text+0x28c): undefined reference to `pspDebugScreenClear'
main.c:(.text+0x2ac): undefined reference to `sceUtilityLoadModule'
main.c:(.text+0x2bc): undefined reference to `sceUtilityLoadModule'
main.c:(.text+0x2e8): undefined reference to `sceMp3InitResource'
main.c:(.text+0x304): undefined reference to `sceIoLseek32'
main.c:(.text+0x340): undefined reference to `sceMp3ReserveMp3Handle'
main.c:(.text+0x35c): undefined reference to `sceMp3Init'
main.c:(.text+0x36c): undefined reference to `sceMp3GetSamplingRate'
main.c:(.text+0x378): undefined reference to `sceMp3GetMp3ChannelNum'
main.c:(.text+0x3b4): undefined reference to `sceDisplayWaitVblankStart'
main.c:(.text+0x3c0): undefined reference to `pspDebugScreenSetXY'
main.c:(.text+0x3cc): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x3e0): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x3f0): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x3f8): undefined reference to `sceMp3GetBitRate'
main.c:(.text+0x408): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x430): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x450): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x488): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x494): undefined reference to `pspDebugScreenPrintf'
main.c:(.text+0x4ec): undefined reference to `sceMp3SetLoopNum'
main.c:(.text+0x528): undefined reference to `sceAudioSRCChRelease'
main.c:(.text+0x530): undefined reference to `sceMp3ReleaseMp3Handle'
main.c:(.text+0x540): undefined reference to `sceMp3TermResource'
main.c:(.text+0x5a8): undefined reference to `sprintf'
main.c:(.text+0x5c0): undefined reference to `sceMp3CheckStreamDataNeeded'
main.c:(.text+0x5dc): undefined reference to `sceMp3Decode'
main.c:(.text+0x5ec): undefined reference to `sceMp3CheckStreamDataNeeded'
main.c:(.text+0x610): undefined reference to `sceMp3ResetPlayPosition'
main.c:(.text+0x64c): undefined reference to `sprintf'
main.c:(.text+0x674): undefined reference to `sceAudioSRCChRelease'
main.c:(.text+0x694): undefined reference to `sceAudioSRCChReserve'
main.c:(.text+0x6a4): undefined reference to `sceAudioSRCOutputBlocking'
main.c:(.text+0x6b4): undefined reference to `sceMp3ResetPlayPosition'
main.c:(.text+0x6d4): undefined reference to `sprintf'
main.c:(.text+0x72c): undefined reference to `sprintf'
main.c:(.text+0x73c): undefined reference to `sceUtilityLoadModule'
main.c:(.text+0x75c): undefined reference to `sprintf'
main.c:(.text+0x7a0): undefined reference to `sprintf'
main.c:(.text+0x7b0): undefined reference to `sceMp3InitResource'
main.c:(.text+0x7d0): undefined reference to `sprintf'
main.c:(.text+0x7f8): undefined reference to `sprintf'
main.c:(.text+0x814): undefined reference to `sceMp3Init'
main.c:(.text+0x834): undefined reference to `sprintf'
main.c:(.text+0x858): undefined reference to `sprintf'
main.c:(.text+0x868): undefined reference to `sceMp3TermResource'
main.c:(.text+0x884): undefined reference to `sprintf'
main.o: In function `CallbackThread':
main.c:(.text+0x8b4): undefined reference to `sceKernelCreateCallback'
main.c:(.text+0x8bc): undefined reference to `sceKernelRegisterExitCallback'
main.c:(.text+0x8c4): undefined reference to `sceKernelSleepThreadCB'
main.o:(.rodata.sceModuleInfo+0x20): undefined reference to `_gp'
make: *** [main] Error 1
K:\Documents and Settings\ADMIN\Рабочий стол\mohexploitv2\src\sdkThat means, that some libs are unacessible!
Here is my main.c:
#include "sdk.h"
/* Define the module info section */
PSP_MODULE_INFO("Mp3Test", 0, 0, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(-1024);
#define MP3FILE "ms0:/test.mp3"
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
static int isrunning = 1;
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
isrunning = 0;
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if (thid >= 0)
sceKernelStartThread(thid, 0, 0);
return thid;
}
// Input and Output buffers
char mp3Buf[16*1024] __attribute__((aligned(64)));
short pcmBuf[16*(1152/2)] __attribute__((aligned(64)));
// Macro to allow formatted input without having to use stdargs.h
#define ERRORMSG(...) { char msg[128]; sprintf(msg,__VA_ARGS__); error(msg); }
// Print out an error message and quit after user input
void error( char* msg )
{
SceCtrlData pad;
pspDebugScreenClear();
pspDebugScreenSetXY(0, 0);
printf(msg);
printf("Press X to quit.\n");
while (isrunning)
{
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CROSS)
break;
sceDisplayWaitVblankStart();
}
sceKernelExitGame();
}
int fillStreamBuffer( int fd, int handle )
{
char* dst;
int write;
int pos;
// Get Info on the stream (where to fill to, how much to fill, where to fill from)
int status = sceMp3GetInfoToAddStreamData( handle, &dst, &write, &pos);
if (status<0)
{
ERRORMSG("ERROR: sceMp3GetInfoToAddStreamData returned 0x%08X\n", status);
}
// Seek file to position requested
status = sceIoLseek32( fd, pos, SEEK_SET );
if (status<0)
{
ERRORMSG("ERROR: sceIoLseek32 returned 0x%08X\n", status);
}
// Read the amount of data
int read = sceIoRead( fd, dst, write );
if (read < 0)
{
ERRORMSG("ERROR: Could not read from file - 0x%08X\n", read);
}
if (read==0)
{
// End of file?
return 0;
}
// Notify mp3 library about how much we really wrote to the stream buffer
status = sceMp3NotifyAddStreamData( handle, read );
if (status<0)
{
ERRORMSG("ERROR: sceMp3NotifyAddStreamData returned 0x%08X\n", status);
}
return (pos>0);
}
/* main routine */
int main(int argc, char *argv[])
{
SceCtrlData pad;
//init screen and callbacks
pspDebugScreenInit();
pspDebugScreenClear();
SetupCallbacks();
// Setup Pad
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(0);
// Load modules
int status = sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
if (status<0)
{
ERRORMSG("ERROR: sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC) returned 0x%08X\n", status);
}
status = sceUtilityLoadModule(PSP_MODULE_AV_MP3);
if (status<0)
{
ERRORMSG("ERROR: sceUtilityLoadModule(PSP_MODULE_AV_MP3) returned 0x%08X\n", status);
}
// Open the input file
int fd = sceIoOpen( MP3FILE, PSP_O_RDONLY, 0777 );
if (fd<0)
{
ERRORMSG("ERROR: Could not open file '%s' - 0x%08X\n", MP3FILE, fd);
}
// Init mp3 resources
status = sceMp3InitResource();
if (status<0)
{
ERRORMSG("ERROR: sceMp3InitResource returned 0x%08X\n", status);
}
// Reserve a mp3 handle for our playback
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);
int handle = sceMp3ReserveMp3Handle( &mp3Init );
if (handle<0)
{
ERRORMSG("ERROR: sceMp3ReserveMp3Handle returned 0x%08X\n", handle);
}
// Fill the stream buffer with some data so that sceMp3Init has something to work with
fillStreamBuffer( fd, handle );
status = sceMp3Init( handle );
if (status<0)
{
ERRORMSG("ERROR: sceMp3Init returned 0x%08X\n", status);
}
int channel = -1;
int samplingRate = sceMp3GetSamplingRate( handle );
int numChannels = sceMp3GetMp3ChannelNum( handle );
int lastDecoded = 0;
int volume = PSP_AUDIO_VOLUME_MAX;
int numPlayed = 0;
int paused = 0;
int lastButtons = 0;
int loop = 0;
while (isrunning)
{
sceDisplayWaitVblankStart();
pspDebugScreenSetXY(0, 0);
printf("PSP Mp3 Sample v1.0 by Raphael\n\n");
printf("Playing '%s'...\n", MP3FILE);
printf(" %i Hz\n", samplingRate);
printf(" %i kbit/s\n", sceMp3GetBitRate( handle ));
printf(" %s\n", numChannels==2?"Stereo":"Mono");
printf(" %s\n\n", loop==0?"No loop":"Loop");
int playTime = samplingRate>0?numPlayed / samplingRate:0;
printf(" Playtime: %02i:%02i\n", playTime/60, playTime%60 );
printf("\n\n\nPress CIRCLE to Pause/Resume playback\nPress TRIANGLE to reset playback\nPress CROSS to switch loop mode\nPress SQUARE to stop playback and quit\n");
if (!paused)
{
// Check if we need to fill our stream buffer
if (sceMp3CheckStreamDataNeeded( handle )>0)
{
fillStreamBuffer( fd, handle );
}
// Decode some samples
short* buf;
int bytesDecoded;
int retries = 0;
// We retry in case it's just that we reached the end of the stream and need to loop
for (;retries<1;retries++)
{
bytesDecoded = sceMp3Decode( handle, &buf );
if (bytesDecoded>0)
break;
if (sceMp3CheckStreamDataNeeded( handle )<=0)
break;
if (!fillStreamBuffer( fd, handle ))
{
numPlayed = 0;
}
}
if (bytesDecoded<0 && bytesDecoded!=0x80671402)
{
ERRORMSG("ERROR: sceMp3Decode returned 0x%08X\n", bytesDecoded);
}
// Nothing more to decode? Must have reached end of input buffer
if (bytesDecoded==0 || bytesDecoded==0x80671402)
{
paused = 1;
sceMp3ResetPlayPosition( handle );
numPlayed = 0;
}
else
{
// Reserve the Audio channel for our output if not yet done
if (channel<0 || lastDecoded!=bytesDecoded)
{
if (channel>=0)
sceAudioSRCChRelease();
channel = sceAudioSRCChReserve( bytesDecoded/(2*numChannels), samplingRate, numChannels );
}
// Output the decoded samples and accumulate the number of played samples to get the playtime
numPlayed += sceAudioSRCOutputBlocking( volume, buf );
}
}
sceCtrlPeekBufferPositive(&pad, 1);
if (pad.Buttons!=lastButtons)
{
if (pad.Buttons & PSP_CTRL_CIRCLE)
{
paused ^= 1;
}
if (pad.Buttons & PSP_CTRL_TRIANGLE)
{
// Reset the stream and playback status
sceMp3ResetPlayPosition( handle );
numPlayed = 0;
}
if (pad.Buttons & PSP_CTRL_CROSS)
{
loop = (loop==0?-1:0);
status = sceMp3SetLoopNum( handle, loop );
if (status<0)
{
ERRORMSG("ERROR: sceMp3SetLoopNum returned 0x%08X\n", status);
}
}
if (pad.Buttons & PSP_CTRL_SQUARE)
{
break;
}
lastButtons = pad.Buttons;
}
}
// Cleanup time...
if (channel>=0)
sceAudioSRCChRelease();
status = sceMp3ReleaseMp3Handle( handle );
if (status<0)
{
ERRORMSG("ERROR: sceMp3ReleaseMp3Handle returned 0x%08X\n", status);
}
status = sceMp3TermResource();
if (status<0)
{
ERRORMSG("ERROR: sceMp3TermResource returned 0x%08X\n", status);
}
status = sceIoClose( fd );
if (status<0)
{
ERRORMSG("ERROR: sceIoClose returned 0x%08X\n", status);
}
sceKernelExitGame();
return 0;
}Here is my sdk.h:
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <stdio.h>
#include <pspmp3.h>
#include <psputility.h>
#ifndef __MOH-SDK__
#define __MOH-SDK__
typedef unsigned char byte;
#endif
Here is my makefile:
PSPSDK=$(shell psp-config --pspsdk-path)
PSPLIBSDIR = $(PSPSDK)/..
PSPDEV=$(shell psp-config --pspdev-path)
INCLUDE=$(PSPSDK)/include
LIBS = -lpspaudio -lpspmp3
all: main
clean:
rm -rf *~ *.o *.elf *.bin main.s *.bin test
CC = psp-gcc
CFLAGS := -D PSP -I $(INCLUDE) -W -Wall -O2 -G0 -fno-pic -mno-abicalls -w -fomit-frame-pointer
ASM = psp-as
sdk.o: sdk.S
$(ASM) sdk.S -o sdk.o
lib.o: lib.c
$(CC) $(CFLAGS) -S lib.c -o lib.s
$(ASM) lib.s -o lib.o
main.o: main.c
$(CC) $(CFLAGS) -S main.c -o main.s
$(ASM) main.s -o main.o
main: main.o lib.o sdk.o linker.x
$(PSPDEV)/bin/psp-ld -T linker.x -L$(PSPSDK)/lib main.o lib.o sdk.o -o main.elf
$(PSPDEV)/bin/psp-strip -s main.elf
$(PSPDEV)/bin/psp-objcopy -O binary main.elf test