Advertisement
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 <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();
- #define BUF_SIZE 16384
- void fill(SceUID file, SceUID stream)
- {
- unsigned char* dst;
- int write, pos;
- sceMp3GetInfoToAddStreamData(stream, &dst, &write, &pos);
- sceIoLseek32(file, pos, PSP_SEEK_SET);
- int read = sceIoRead(file, dst, write);
- sceMp3NotifyAddStreamData(stream, read);
- }
- int main()
- {
- SetupCallbacks();
- SceMp3InitArg arg;
- //void *back, *front;
- 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 = memalign(64, 16*1024); // TODO vérifier ?
- arg.mp3BufSize = 16*1024;
- arg.pcmBuf = memalign(64, 8*1152); // TODO vérifier ?
- arg.pcmBufSize = 8*1152;
- stream = sceMp3ReserveMp3Handle(&arg);
- fill(file, stream);
- sceMp3Init(stream);
- // Réservation d'un canal audio
- sceAudioChReserve(0, 1152, PSP_AUDIO_FORMAT_STEREO);
- short* buf;
- while (1)
- {
- if (sceMp3CheckStreamDataNeeded(stream) > 0)
- {
- fill(file, stream);
- }
- while (1)
- {
- if (sceMp3Decode(stream, &buf) > 0) break;
- if (sceMp3CheckStreamDataNeeded(stream) <= 0) break;
- fill(file, stream);
- }
- sceAudioOutputBlocking(0, 0x8000, buf);
- }
- sceAudioChRelease(0);
- sceKernelExitGame();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement