GeeckoDev

test mp3 end of stream

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