Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pspkernel.h>
- #include <pspaudio.h>
- #include <psputility.h>
- #include <pspmp3.h>
- #include <pspdebug.h>
- #include <math.h>
- #include <malloc.h>
- int exit_callback(int arg1, int arg2, void *common) {
- sceKernelExitGame();
- return 0; }
- int CallbackThread(SceSize args, void *argp) {
- int cbid;
- cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
- sceKernelRegisterExitCallback(cbid);
- sceKernelSleepThreadCB();
- return 0; }
- int SetupCallbacks() {
- int thid = 0;
- thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
- if(thid >= 0) sceKernelStartThread(thid, 0, 0);
- return thid; }
- PSP_MODULE_INFO("App",0,1,1);
- PSP_HEAP_SIZE_MAX();
- int lastPos=0;
- int fill(SceUID file, SceUID stream)
- {
- unsigned char* dst;
- int write, pos, ret;
- pspDebugScreenPrintf("fill: file=%d, stream=%d\n",
- file, stream);
- ret = sceMp3GetInfoToAddStreamData(stream, &dst, &write, &pos);
- pspDebugScreenPrintf("sceMp3GetInfoToAddStreamData: write=%d, pos=%d >> %d\n",
- write, pos, ret);
- if (pos < lastPos) return 1;
- lastPos = pos;
- sceIoLseek32(file, pos, PSP_SEEK_SET);
- int read = sceIoRead(file, dst, write);
- ret = sceMp3NotifyAddStreamData(stream, read);
- pspDebugScreenPrintf("sceMp3NotifyAddStreamData: read=%d >> %d\n",
- read, ret);
- return 0;
- }
- int main()
- {
- SetupCallbacks();
- pspDebugScreenInit();
- SceMp3InitArg arg;
- SceUID file, stream;
- // Chargement des modules
- sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
- sceUtilityLoadModule(PSP_MODULE_AV_MP3);
- // Ouverture du fichier
- file = sceIoOpen("./audio.mp3", PSP_O_RDONLY, 0777);
- // Initialisation du stream mp3
- sceMp3InitResource();
- arg.mp3StreamStart = 0;
- arg.mp3StreamEnd = sceIoLseek32(file, 0, PSP_SEEK_END);
- arg.unk1 = 0;
- arg.unk2 = 0;
- arg.mp3Buf = malloc(8192);
- arg.mp3BufSize = 8192;
- arg.pcmBuf = malloc(9216);
- arg.pcmBufSize = 9216;
- stream = sceMp3ReserveMp3Handle(&arg);
- fill(file, stream);
- sceMp3Init(stream);
- // Réservation d'un canal audio
- sceAudioChReserve(0, 1152, PSP_AUDIO_FORMAT_STEREO);
- short* buf;
- int ret;
- while (1)
- {
- if (sceMp3CheckStreamDataNeeded(stream) > 0)
- {
- ret = fill(file, stream);
- if (ret) break; // Fin du fichier
- }
- ret = sceMp3Decode(stream, &buf);
- pspDebugScreenPrintf("sceMp3Decode >> %d\n",
- ret);
- ret = sceAudioOutputBlocking(0, 0x8000, buf);
- pspDebugScreenPrintf("sceAudioOutputBlocking >> %d\n",
- ret);
- }
- sceAudioChRelease(0);
- sceMp3ReleaseMp3Handle(stream);
- sceMp3TermResource();
- sceKernelExitGame();
- return 0;
- }
Add Comment
Please, Sign In to add comment