Advertisement
GeeckoDev

test mp3

Oct 27th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.23 KB | None | 0 0
  1. #include <pspkernel.h>
  2. #include <pspaudio.h>
  3. #include <psputility.h>
  4. #include <pspmp3.h>
  5.  
  6. #include <math.h>
  7. #include <malloc.h>
  8.  
  9. int exit_callback(int arg1, int arg2, void *common) {
  10.   sceKernelExitGame();
  11.   return 0; }
  12. int CallbackThread(SceSize args, void *argp) {
  13.   int cbid;
  14.   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
  15.   sceKernelRegisterExitCallback(cbid);
  16.   sceKernelSleepThreadCB();
  17.   return 0; }
  18. int SetupCallbacks() {
  19.   int thid = 0;
  20.   thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
  21.   if(thid >= 0) sceKernelStartThread(thid, 0, 0);
  22.   return thid; }
  23.  
  24. PSP_MODULE_INFO("App",0,1,1);
  25. PSP_HEAP_SIZE_MAX();
  26.  
  27. #define BUF_SIZE 16384
  28.  
  29. void fill(SceUID file, SceUID stream)
  30. {
  31.   unsigned char* dst;
  32.   int write, pos;
  33.  
  34.   sceMp3GetInfoToAddStreamData(stream, &dst, &write, &pos);
  35.   sceIoLseek32(file, pos, PSP_SEEK_SET);
  36.   int read = sceIoRead(file, dst, write);
  37.   sceMp3NotifyAddStreamData(stream, read);
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43.   SetupCallbacks();
  44.  
  45.   SceMp3InitArg arg;
  46.   //void *back, *front;
  47.   SceUID file, stream;
  48.  
  49.   // Chargement des modules
  50.   sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
  51.   sceUtilityLoadModule(PSP_MODULE_AV_MP3);
  52.   // Ouverture du fichier
  53.   file = sceIoOpen("./audio.mp3", PSP_O_RDONLY, 0777);
  54.   // Initialisation du stream mp3
  55.   sceMp3InitResource();
  56.   arg.mp3StreamStart = 0;
  57.   arg.mp3StreamEnd = sceIoLseek32(file, 0, PSP_SEEK_END);
  58.   arg.unk1 = 0;
  59.   arg.unk2 = 0;
  60.   arg.mp3Buf = memalign(64, 16*1024); // TODO vérifier ?
  61.   arg.mp3BufSize = 16*1024;
  62.   arg.pcmBuf = memalign(64, 8*1152); // TODO vérifier ?
  63.   arg.pcmBufSize = 8*1152;
  64.   stream = sceMp3ReserveMp3Handle(&arg);
  65.   fill(file, stream);
  66.   sceMp3Init(stream);
  67.   // Réservation d'un canal audio
  68.   sceAudioChReserve(0, 1152, PSP_AUDIO_FORMAT_STEREO);
  69.  
  70.   short* buf;
  71.  
  72.   while (1)
  73.   {
  74.     if (sceMp3CheckStreamDataNeeded(stream) > 0)
  75.     {
  76.       fill(file, stream);
  77.     }
  78.     while (1)
  79.     {
  80.       if (sceMp3Decode(stream, &buf) > 0) break;
  81.       if (sceMp3CheckStreamDataNeeded(stream) <= 0) break;
  82.       fill(file, stream);
  83.     }
  84.  
  85.     sceAudioOutputBlocking(0, 0x8000, buf);
  86.   }
  87.  
  88.   sceAudioChRelease(0);
  89.   sceKernelExitGame();
  90.   return 0;
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement