Esempio n. 1
0
static int audioMainLoop(SceSize args, void* argp)
{
   psp1_audio_t* psp = *((psp1_audio_t**)argp);

   sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);

   while (psp->running)
   {
      /* Get a non-volatile copy. */
      uint16_t readPos = psp->readPos;

      if (((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK)
            < (AUDIO_OUT_COUNT * 2))
         sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->zeroBuffer);
      else
      {
         sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX,
               psp->buffer + readPos);
         readPos += AUDIO_OUT_COUNT;
         readPos &= AUDIO_BUFFER_SIZE_MASK;
         psp->readPos = readPos;
      }
   }

   sceAudioSRCChRelease();
   sceKernelExitThread(0);
   return 0;
}
Esempio n. 2
0
bool JMP3::update() {
   if (!init_done) {
      return false;
   }
#ifdef MP3_SUPPORT   
	int retry = 8;//FIXME:magic number
	JMP3_update_start:

   if (!m_paused) {
      if (sceMp3CheckStreamDataNeeded(m_mp3Handle) > 0) {
         fillBuffers();
      }

      short* tempBuffer;
      int numDecoded = 0;

      while (true) {
         numDecoded = sceMp3Decode(m_mp3Handle, &tempBuffer);
         if (numDecoded > 0)
            break;

         int ret = sceMp3CheckStreamDataNeeded(m_mp3Handle);
         if (ret <= 0)
            break;

         fillBuffers();
      }

      // Okay, let's see if we can't get something outputted :/
      if (numDecoded == 0 || ((unsigned)numDecoded == 0x80671402)) {
	  if (retry-- > 0){
           //give me a recovery chance after suspend/resume...
            sceKernelDelayThread(1);
            goto JMP3_update_start;
         }

         sceMp3ResetPlayPosition(m_mp3Handle);
         if (!m_loop)
            m_paused = true;

         m_samplesPlayed = 0;
      } else {
         if (m_channel < 0 || m_lastDecoded != numDecoded) {
            if (m_channel >= 0)
               sceAudioSRCChRelease();

            m_channel = sceAudioSRCChReserve(numDecoded / (2 * m_numChannels), m_samplingRate, m_numChannels);
         }

         // Output
         m_samplesPlayed += sceAudioSRCOutputBlocking(m_volume, tempBuffer);
         m_playTime = (m_samplingRate > 0) ? (m_samplesPlayed / (m_samplingRate/1000)) : 0;
		 m_lastDecoded = numDecoded;

      }
   }
#endif   
   return true;
}
Esempio n. 3
0
static int audioMainLoop(SceSize args, void* argp)
{
    psp_audio_t* psp = *((psp_audio_t**)argp);

#ifdef VITA
    int port = sceAudioOutOpenPort(PSP2_AUDIO_OUT_PORT_TYPE_MAIN, AUDIO_OUT_COUNT,
                                   psp->rate, PSP2_AUDIO_OUT_MODE_STEREO);
#else
    sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);
#endif

    while (psp->running)
    {
        /* Get a non-volatile copy. */
        uint16_t readPos = psp->readPos;
        bool cond        = ((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK)
                           < (AUDIO_OUT_COUNT * 2);

#ifdef VITA
        sceAudioOutOutput(port,
                          cond ? psp->zeroBuffer : (psp->buffer + readPos));
#else
        sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, cond ? (psp->zeroBuffer)
                                  : (psp->buffer + readPos));
#endif

        if (!cond)
        {
            readPos += AUDIO_OUT_COUNT;
            readPos &= AUDIO_BUFFER_SIZE_MASK;
            psp->readPos = readPos;
        }
    }

#ifdef VITA
    sceAudioOutReleasePort(port);
#else
    sceAudioSRCChRelease();
#endif
    sceKernelExitThread(0);
    return 0;
}
Esempio n. 4
0
bool JMP3::unload() {
JLOG("Start JMP3::unload");
   if (!init_done) {
      JLOG("JMP3::unload called but init_done is false!");
      return false;
   }
#ifdef MP3_SUPPORT   
   if (m_channel >= 0)
      sceAudioSRCChRelease();

   sceMp3ReleaseMp3Handle(m_mp3Handle);

   sceMp3TermResource();

   sceIoClose(m_fileHandle);

   //delete[] m_inBuffer;

   //delete[] m_outBuffer;
#endif   
JLOG("End JMP3::unload");
   return true;
}
Esempio n. 5
0
int releaseAudio(void){
	while(sceAudioOutput2GetRestSample() > 0);
	return sceAudioSRCChRelease();
}
Esempio n. 6
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;
}
Esempio n. 7
0
static int audioMainLoop(SceSize args, void* argp)
{
   psp_audio_t* psp = *((psp_audio_t**)argp);

#ifdef VITA
   int port = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, AUDIO_OUT_COUNT,
      psp->rate, SCE_AUDIO_OUT_MODE_STEREO);
#else
   sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);
#endif

   while (psp->running)
   {
#ifdef VITA
      
      //sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT);

      sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0);
      uint16_t readPos = psp->readPos;
      uint16_t readPos2 = psp->readPos;
      bool cond        = ((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK)
            < (AUDIO_OUT_COUNT * 2);
      if (!cond)
      {
         readPos += AUDIO_OUT_COUNT;
         readPos &= AUDIO_BUFFER_SIZE_MASK;
         psp->readPos = readPos;
      }
      sceKernelUnlockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1);
      sceKernelSignalLwCond(&psp->cond);
      
      sceAudioOutOutput(port,
        cond ? (psp->zeroBuffer)
              : (psp->buffer + readPos2));
              
      
#else
      /* Get a non-volatile copy. */
      uint16_t readPos = psp->readPos;
      bool cond        = ((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK)
            < (AUDIO_OUT_COUNT * 2);

      sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, cond ? (psp->zeroBuffer)
            : (psp->buffer + readPos));

      if (!cond)
      {
         readPos += AUDIO_OUT_COUNT;
         readPos &= AUDIO_BUFFER_SIZE_MASK;
         psp->readPos = readPos;
      }

#endif

   }

#ifdef VITA
   sceAudioOutReleasePort(port);
#else
   sceAudioSRCChRelease();
   sceKernelExitThread(0);
#endif
   return 0;
}