forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SDK Updated with sceMp3 stubs+headers
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sun Aug 10, 2008 12:52 pm    Post subject: SDK Updated with sceMp3 stubs+headers Reply with quote

After some fiddling, InsertWittyName and me figured out how to use sceMp3 library to playback mp3.

The code has been checked into the SVN repository. Feel free to update your SDK if you feel like trying out the library :)

Header:
Code:

/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * pspmp3.h - Prototypes for the sceMp3 library
 *
 * Copyright (c) 2008 David Perry <tias_dp@hotmail.com>
 * Copyright (c) 2008 Alexander Berl <raphael@fx-world.org>
 *
 * $Id: $
 */

#ifndef __SCELIBMP3_H__
#define __SCELIBMP3_H__

#include <psptypes.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct SceMp3InitArg {
   /** Stream start position */
   SceUInt32   mp3StreamStart;
   /** Unknown - set to 0 */
   SceUInt32   unk1;
   /** Stream end position */
   SceUInt32   mp3StreamEnd;
   /** Unknown - set to 0 */
   SceUInt32   unk2;
   /** Pointer to a buffer to contain raw mp3 stream data (+1472 bytes workspace) */
   SceVoid*   mp3Buf;
   /** Size of mp3Buf buffer (must be >= 8192) */
   SceInt32   mp3BufSize;
   /** Pointer to decoded pcm samples buffer */
   SceVoid*   pcmBuf;
   /** Size of pcmBuf buffer (must be >= 9216) */
   SceInt32   pcmBufSize;
} SceMp3InitArg;

/**
 * sceMp3ReserveMp3Handle
 *
 * @param args - Pointer to SceMp3InitArg structure
 *
 * @returns sceMp3 handle on success, < 0 on error.
 */
SceInt32 sceMp3ReserveMp3Handle(SceMp3InitArg* args);

/**
 * sceMp3ReleaseMp3Handle
 *
 * @param handle - sceMp3 handle
 *
 * @returns 0 if success, < 0 on error.
 */
SceInt32 sceMp3ReleaseMp3Handle(SceInt32 handle);

/**
 * sceMp3InitResource
 *
 * @returns 0 if success, < 0 on error.
 */
SceInt32 sceMp3InitResource();

/**
 * sceMp3TermResource
 *
 * @returns 0 if success, < 0 on error.
 */
SceInt32 sceMp3TermResource();

/**
 * sceMp3Init
 *
 * @param handle - sceMp3 handle
 *
 * @returns 0 if success, < 0 on error.
 */
SceInt32 sceMp3Init(SceInt32 handle);

/**
 * sceMp3Decode
 *
 * @param handle - sceMp3 handle
 * @param dst - Pointer to destination pcm samples buffer
 *
 * @returns number of bytes in decoded pcm buffer, < 0 on error.
 */
SceInt32 sceMp3Decode(SceInt32 handle, SceShort16** dst);

/**
 * sceMp3GetInfoToAddStreamData
 *
 * @param handle - sceMp3 handle
 * @param dst - Pointer to stream data buffer
 * @param towrite - Space remaining in stream data buffer
 * @param srcpos - Position in source stream to start reading from
 *
 * @returns 0 if success, < 0 on error.
 */
SceInt32 sceMp3GetInfoToAddStreamData(SceInt32 handle, SceUChar8** dst, SceInt32* towrite, SceInt32* srcpos);

/**
 * sceMp3NotifyAddStreamData
 *
 * @param handle - sceMp3 handle
 * @param size - number of bytes added to the stream data buffer
 *
 * @returns 0 if success, < 0 on error.
 */
SceInt32 sceMp3NotifyAddStreamData(SceInt32 handle, SceInt32 size);

/**
 * sceMp3CheckStreamDataNeeded
 *
 * @param handle - sceMp3 handle
 *
 * @returns 1 if more stream data is needed, < 0 on error.
 */
SceInt32 sceMp3CheckStreamDataNeeded(SceInt32 handle);

/**
 * sceMp3SetLoopNum
 *
 * @param handle - sceMp3 handle
 * @param loop - Number of loops
 *
 * @returns 0 if success, < 0 on error.
 */
SceInt32 sceMp3SetLoopNum(SceInt32 handle, SceInt32 loop);

/**
 * sceMp3GetLoopNum
 *
 * @param handle - sceMp3 handle
 *
 * @returns Number of loops
 */
SceInt32 sceMp3GetLoopNum(SceInt32 handle);

/**
 * sceMp3GetSumDecodedSample
 *
 * @param handle - sceMp3 handle
 *
 * @returns Number of decoded samples
 */
SceInt32 sceMp3GetSumDecodedSample(SceInt32 handle);

/**
 * sceMp3GetMaxOutputSample
 *
 * @param handle - sceMp3 handle
 *
 * @returns Number of max samples to output
 */
SceInt32 sceMp3GetMaxOutputSample(SceInt32 handle);

/**
 * sceMp3GetSamplingRate
 *
 * @param handle - sceMp3 handle
 *
 * @returns Sampling rate of the mp3
 */
SceInt32 sceMp3GetSamplingRate(SceInt32 handle);

/**
 * sceMp3GetBitRate
 *
 * @param handle - sceMp3 handle
 *
 * @returns Bitrate of the mp3
 */
SceInt32 sceMp3GetBitRate(SceInt32 handle);

/**
 * sceMp3GetMp3ChannelNum
 *
 * @param handle - sceMp3 handle
 *
 * @returns Number of channels of the mp3
 */
SceInt32 sceMp3GetMp3ChannelNum(SceInt32 handle);

/**
 * sceMp3ResetPlayPosition
 *
 * @param handle - sceMp3 handle
 *
 * @returns < 0 on error
 */
SceInt32 sceMp3ResetPlayPosition(SceInt32 handle);


#ifdef __cplusplus
}
#endif

#endif



Sample:
Code:

/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Sample to demonstrate proper use of the mp3 library
 *
 * Copyright (c) 2008 Alexander Berl <raphael@fx-world.org>
 *
 * $Id: $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <pspaudio.h>
#include <pspmp3.h>
#include <psputility.h>


/* Define the module info section */
PSP_MODULE_INFO("Mp3Test", 0, 0, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(-1024);

#define MP3FILE "ms0:/MUSIC/Test.mp3"

/* Define printf, just to make typing easier */
#define printf  pspDebugScreenPrintf

static int isrunning = 1;
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
    isrunning = 0;

   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
    int cbid;
    cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback(cbid);
    sceKernelSleepThreadCB();

   return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
    int thid = 0;
    thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
    if (thid >= 0)
   sceKernelStartThread(thid, 0, 0);
    return thid;
}


// Input and Output buffers
char   mp3Buf[16*1024]  __attribute__((aligned(64)));
short   pcmBuf[16*(1152/2)]  __attribute__((aligned(64)));


// Macro to allow formatted input without having to use stdargs.h
#define ERRORMSG(...) { char msg[128]; sprintf(msg,__VA_ARGS__); error(msg); }

// Print out an error message and quit after user input
void error( char* msg )
{
   SceCtrlData pad;
   pspDebugScreenClear();
   pspDebugScreenSetXY(0, 0);
   printf(msg);
   printf("Press X to quit.\n");
   while (isrunning)
   {
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CROSS)
         break;
      sceDisplayWaitVblankStart();
   }
   sceKernelExitGame();
}

int fillStreamBuffer( int fd, int handle )
{
   char* dst;
   int write;
   int pos;
   // Get Info on the stream (where to fill to, how much to fill, where to fill from)
   int status = sceMp3GetInfoToAddStreamData( handle, &dst, &write, &pos);
   if (status<0)
   {
      ERRORMSG("ERROR: sceMp3GetInfoToAddStreamData returned 0x%08X\n", status);
   }

   // Seek file to position requested
   status = sceIoLseek32( fd, pos, SEEK_SET );
   if (status<0)
   {
      ERRORMSG("ERROR: sceIoLseek32 returned 0x%08X\n", status);
   }
   
   // Read the amount of data
   int read = sceIoRead( fd, dst, write );
   if (read < 0)
   {
      ERRORMSG("ERROR: Could not read from file - 0x%08X\n", read);
   }
   
   if (read==0)
   {
      // End of file?
      return 0;
   }
   
   // Notify mp3 library about how much we really wrote to the stream buffer
   status = sceMp3NotifyAddStreamData( handle, read );
   if (status<0)
   {
      ERRORMSG("ERROR: sceMp3NotifyAddStreamData returned 0x%08X\n", status);
   }
   
   return (pos>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;
}

_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
KickinAezz



Joined: 03 Jun 2007
Posts: 328

PostPosted: Sun Aug 10, 2008 1:07 pm    Post subject: Reply with quote

Any advantages over our ME mp3 player?
_________________
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
Back to top
View user's profile Send private message
SilverSpring



Joined: 27 Feb 2007
Posts: 115

PostPosted: Sun Aug 10, 2008 1:50 pm    Post subject: Reply with quote

The libaac have identical function names so maybe the prototypes are the same/similar to libmp3:

Code:

0x6c05813b sceAac_6C05813B (module_start alias)
0x61aa43c9 sceAac_61AA43C9 (module_stop alias)
0xe0c89aca sceAacInit
0x33b8c009 sceAacExit
0x5cffc57c sceAacInitResource
0x23d35cae sceAacTermResource
0x7e4cfee4 sceAacDecode
0x523347d9 sceAacGetLoopNum
0xbbdd6403 sceAacSetLoopNum
0xd7c51541 sceAacCheckStreamDataNeeded
0xac6dcbe3 sceAacNotifyAddStreamData
0x02098c69 sceAacGetInfoToAddStreamData
0x6dc7758a sceAacGetMaxOutputSample
0x506bf66c sceAacGetSumDecodedSample
0xd2da2bba sceAacResetPlayPosition


I haven't looked into it or tested it but libaac was added in 3.95 firmware (libaac.prx) and maybe the usage is similar.
Back to top
View user's profile Send private message Visit poster's website
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 10, 2008 3:00 pm    Post subject: Reply with quote

Is the sce lib hardware accelerated?
Back to top
View user's profile Send private message
SilverSpring



Joined: 27 Feb 2007
Posts: 115

PostPosted: Sun Aug 10, 2008 3:26 pm    Post subject: Reply with quote

Torch wrote:
Is the sce lib hardware accelerated?


Yes it's already using Media Engine decoding.
Back to top
View user's profile Send private message Visit poster's website
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Aug 10, 2008 3:31 pm    Post subject: Reply with quote

SilverSpring wrote:

Yes it's already using Media Engine decoding.


Speaking of the ME, is the sound equalizer stuff done by the ME or is it software?
Are there any functions which I can use to set custom equalizer settings, because the built in ones sound awful.

I read somewhere that the equalizer stuff was done like an FPGA and that the various presets where actually stored as an FPGA logic and the hardware gets "reprogrammed" with the preset codes when you press then note button.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sun Aug 10, 2008 10:20 pm    Post subject: Reply with quote

KickinAezz wrote:
Any advantages over our ME mp3 player?

Easier interface to getting it to work with streaming. Also you don't have to fill those 'magic' buffers with decoding parameters.
And to say the least, the sample already provides near perfect playback, even though it's single threaded and uses only a small decoding buffer of 16kb. Equal performance and reliability is only achieved with lots of threaded coding and bigger buffers with the previous method.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sun Aug 10, 2008 10:21 pm    Post subject: Reply with quote

SilverSpring wrote:
The libaac have identical function names so maybe the prototypes are the same/similar to libmp3:

Code:

0x6c05813b sceAac_6C05813B (module_start alias)
0x61aa43c9 sceAac_61AA43C9 (module_stop alias)
0xe0c89aca sceAacInit
0x33b8c009 sceAacExit
0x5cffc57c sceAacInitResource
0x23d35cae sceAacTermResource
0x7e4cfee4 sceAacDecode
0x523347d9 sceAacGetLoopNum
0xbbdd6403 sceAacSetLoopNum
0xd7c51541 sceAacCheckStreamDataNeeded
0xac6dcbe3 sceAacNotifyAddStreamData
0x02098c69 sceAacGetInfoToAddStreamData
0x6dc7758a sceAacGetMaxOutputSample
0x506bf66c sceAacGetSumDecodedSample
0xd2da2bba sceAacResetPlayPosition


I haven't looked into it or tested it but libaac was added in 3.95 firmware (libaac.prx) and maybe the usage is similar.


Thanks, that might be worth looking into too :)
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
pspZorba



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Sun Aug 10, 2008 10:30 pm    Post subject: Reply with quote

Thank you guys

That's what I was waiting for to add music in my dev.
_________________
--pspZorba--
NO to K1.5 !
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Aug 11, 2008 5:10 am    Post subject: Reply with quote

Don't know when I'd use it, but it's great to have it if I did. Great work!
Back to top
View user's profile Send private message AIM Address
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Tue Aug 12, 2008 6:36 am    Post subject: Reply with quote

?Raphael, you have posted the header and a sample but there's no library needed?
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Tue Aug 12, 2008 6:44 am    Post subject: Reply with quote

Update your SDK.

The library, header and sample are all there.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Tue Aug 12, 2008 9:24 am    Post subject: Reply with quote

SilverSpring wrote:
The libaac have identical function names so maybe the prototypes are the same/similar to libmp3:

Code:

0x6c05813b sceAac_6C05813B (module_start alias)
0x61aa43c9 sceAac_61AA43C9 (module_stop alias)
0xe0c89aca sceAacInit
0x33b8c009 sceAacExit
0x5cffc57c sceAacInitResource
0x23d35cae sceAacTermResource
0x7e4cfee4 sceAacDecode
0x523347d9 sceAacGetLoopNum
0xbbdd6403 sceAacSetLoopNum
0xd7c51541 sceAacCheckStreamDataNeeded
0xac6dcbe3 sceAacNotifyAddStreamData
0x02098c69 sceAacGetInfoToAddStreamData
0x6dc7758a sceAacGetMaxOutputSample
0x506bf66c sceAacGetSumDecodedSample
0xd2da2bba sceAacResetPlayPosition


I haven't looked into it or tested it but libaac was added in 3.95 firmware (libaac.prx) and maybe the usage is similar.


Well, since we need some way of loading the libAAC.prx properly in user mode, I fiddled with sceUtilityLoadModule a bit.

I found the following values to load other modules than the ones already known:

Quote:

#define PSP_MODULE_AV_VAUDIO 0x0305
#define PSP_MODULE_AV_AAC 0x0306
#define PSP_MODULE_AV_G729 0x0307

#define PSP_MODULE_NP_COMMON 0x0400 // sceNpCore, sceNp, sceNpAuth
#define PSP_MODULE_NP_SERVICE 0x0401
#define PSP_MODULE_NP_MATCHING2 0x0402

// scePspNpDrm_driver
#define PSP_MODULE_NP_DRM 0x0500

// sceIrDA_Driver
#define PSP_MODULE_IRDA 0x0600


I'll add those to pspUtility.h and commit it. Looks like AAC decoding is not far :)

PS: Anyone knows what the NP modules might be for (NetPlay maybe)? I guess the PspNpDrm is for the NP9660 UMD driver, no?
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
kralyk



Joined: 06 Apr 2008
Posts: 114
Location: Czech Republic, central EU

PostPosted: Tue Aug 12, 2008 9:31 am    Post subject: Reply with quote

Brilliant, thanks for your work Raphael and InsertWittyName
Back to top
View user's profile Send private message
AlphaDingDong



Joined: 21 Mar 2008
Posts: 29
Location: The interwebs

PostPosted: Thu Aug 21, 2008 2:04 pm    Post subject: Reply with quote

I've been getting error code 0x807F00FD from sceMp3Init wherever I try to use it, including the sample. I can't find the error code listed anywhere.

Any idea what's happening here?
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Thu Aug 21, 2008 2:25 pm    Post subject: Reply with quote

AlphaDingDong wrote:
I've been getting error code 0x807F00FD from sceMp3Init wherever I try to use it, including the sample. I can't find the error code listed anywhere.

Any idea what's happening here?

Most likely an error code meaning that the header is not a valid mp3header. That's the case when you have an ID3 tag at the start of the mp3. sceMp3 doesn't parse that unfortunately, so you have to do it yourself (and give the proper streamStart/streamEnd address to mp3InitArgs) or strip id3 tags from the mp3s you play.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
AlphaDingDong



Joined: 21 Mar 2008
Posts: 29
Location: The interwebs

PostPosted: Thu Aug 21, 2008 3:20 pm    Post subject: Reply with quote

That's probably it. Thanks.
Back to top
View user's profile Send private message
wxnlyq



Joined: 03 Oct 2008
Posts: 4

PostPosted: Fri Oct 03, 2008 1:04 pm    Post subject: Reply with quote

I've been succeed to play a mp3 file using the pspmp3 lib.
But when I try to run it in a separate thread, it failed(PSP is shutdown).

It seem that when sceIoOpen is called, some error occurs.
Why I can't open a file in the thread?

Because the sample code is written to play a single file, but I want to multiple mp3 file at the same time,How can I do it?

Could somebody give me a help.
Code:

#mp3.h
#include "Mp3.h"
#define printf pspDebugScreenPrintf

void Mp3::init() {
   loadModules();
}

Mp3::Mp3(const std::string& filename, int inBufferSize, int outBufferSize) :
   m_volume(PSP_AUDIO_VOLUME_MAX), m_paused(true), m_samplesPlayed(0) {
   load(filename);
}

Mp3::~Mp3() {
   unload();
}

bool Mp3::loadModules() {
   int loadAvCodec = sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
   if (loadAvCodec < 0) {
      std::cout << "Failed to load AV_AVCODEC module.\n";
      return false;
   }

   int loadMp3 = sceUtilityLoadModule(PSP_MODULE_AV_MP3);
   if (loadMp3 < 0) {
      std::cout << "Failed to load AV_MP3 module.\n";
      return false;
   }

   return true;
}

bool Mp3::fillBuffers() {
   SceUChar8* dest;
   SceInt32 length;
   SceInt32 pos;

   int ret = sceMp3GetInfoToAddStreamData(m_mp3Handle, &dest, &length, &pos);
   if (ret < 0)
      return false;

   if (sceIoLseek32(m_fileHandle, pos, SEEK_SET) < 0) {
      std::cout << "Seek failed.\n";
      return false;
   }

   int readLength = sceIoRead(m_fileHandle, dest, length);
   if (readLength < 0)
      return false;

   ret = sceMp3NotifyAddStreamData(m_mp3Handle, readLength);
   if (ret < 0)
      return false;

   return true;
}

bool Mp3::load(const std::string& filename, int inBufferSize, int outBufferSize) {
   printf("load\n");
   try {
      m_inBufferSize = inBufferSize;
      printf("1\n");
      m_inBuffer = new char[m_inBufferSize];
      if (!m_inBuffer)
         throw std::runtime_error("Failed to allocate in buffer.");

      m_outBufferSize = outBufferSize;
      printf("2\n");
      m_outBuffer = new short[outBufferSize];
      if (!m_outBuffer)
         throw std::runtime_error("Failed to allocate out buffer.");

      printf("3:%s\n",filename.c_str());
      m_fileHandle = sceIoOpen(filename.c_str(), PSP_O_RDONLY, 0777);
      if (m_fileHandle < 0)
         throw std::runtime_error("Failed to open mp3 file.");

      printf("4\n");
      int ret = sceMp3InitResource();
      if (ret < 0)
         throw std::runtime_error("Failed to init sceMp3.");

      SceMp3InitArg initArgs;

      int fileSize = sceIoLseek32(m_fileHandle, 0, SEEK_END);
      sceIoLseek32(m_fileHandle, 0, SEEK_SET);

      unsigned char* testbuffer = new unsigned char[7456];
      sceIoRead(m_fileHandle, testbuffer, 7456);

      delete testbuffer;

      initArgs.unk1 = 0;
      initArgs.unk2 = 0;
      initArgs.mp3StreamStart = 0;
      initArgs.mp3StreamEnd = fileSize;
      initArgs.mp3BufSize = m_inBufferSize;
      initArgs.mp3Buf = (SceVoid*) m_inBuffer;
      initArgs.pcmBufSize = m_outBufferSize;
      initArgs.pcmBuf = (SceVoid*) m_outBuffer;

      printf("5\n");
      m_mp3Handle = sceMp3ReserveMp3Handle(&initArgs);
      if (m_mp3Handle < 0)
         throw std::runtime_error("Failed to reserve mp3 handle.");

      // Alright we are all set up, let's fill the first buffer.
      fillBuffers();

      // Start this bitch up!
      printf("6\n");
      int start = sceMp3Init(m_mp3Handle);
      if (start < 0)
         throw std::runtime_error("Failed to init sceMp3.");

      printf("7\n");
      m_numChannels = sceMp3GetMp3ChannelNum(m_mp3Handle);
      printf("8\n");
      m_samplingRate = sceMp3GetSamplingRate(m_mp3Handle);
   } catch (std::exception& e) {
      printf("exceptiuon:%s\n", e.what());
      std::cout << "Error: " << e.what() << "\n";
      return false;
   }

   return true;
}

bool Mp3::unload() {
   if (m_channel >= 0)
      sceAudioSRCChRelease();

   sceMp3ReleaseMp3Handle(m_mp3Handle);
   sceMp3TermResource();

   sceIoClose(m_fileHandle);

   delete[] m_inBuffer;
   delete[] m_outBuffer;

   return true;
}

bool Mp3::update() {
   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 || numDecoded == WeirdSceMp3Error) {
         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) : 0;
      }
   }

   return true;
}

bool Mp3::play() {
   return (m_paused = false);
}

bool Mp3::pause() {
   return (m_paused = true);
}

bool Mp3::setLoop(bool loop) {
   sceMp3SetLoopNum(m_mp3Handle, (loop == true) ? -1 : 0);
   return (m_loop = loop);
}

int Mp3::setVolume(int volume) {
   return (m_volume = volume);
}

int Mp3::playTime() const {
   return m_playTime;
}

int Mp3::playTimeMinutes() {
   return m_playTime / 60;
}

int Mp3::playTimeSeconds() {
   return m_playTime % 60;
}



Code:

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>
#include <pspdisplay.h>
#include "Mp3.h"
#include "Log.h"
#include "MyMp3.h"
PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1)
;PSP_MAIN_THREAD_ATTR(0);
PSP_HEAP_SIZE_KB(18*1024);
#define printf pspDebugScreenPrintf
// TWILIGHT ZONE! <do doo do doo>
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
   sceKernelExitGame();
   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
   int cbid;

   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);

   sceKernelSleepThreadCB();

   return 0;
}
int MyCallbackThread(SceSize args, void *argp) {
   printf("init\n");
   Mp3::init();
   printf("new Mp3\n");
   Mp3 *mp3 = new Mp3("music.mp3");
   mp3->setLoop(true);
   printf("play\n");
   mp3->play();
   while (1) {
      printf("CallbackThread1:%d\n", mp3->playTime());
      mp3->update();
   }
   delete mp3;
   return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
   int thid = 0;

   thid = sceKernelCreateThread("update_thread", MyCallbackThread, 0x11, 0xFA0, 0, 0);
   if (thid >= 0) {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}
// END OF TWILIGHT ZONE! <do doo do do>
int main() {
   scePowerSetClockFrequency(333, 333, 166);

   pspDebugScreenInit();
   SetupCallbacks();

   SceCtrlData pad;

   int thid = 0;

   thid = sceKernelCreateThread("mythread", CallbackThread, 0x11, 0xFA0, 0, 0);
   if (thid >= 0) {
      sceKernelStartThread(thid, 0, 0);
   }

//   Mp3::init();
//   Mp3 *mp3 = new Mp3("music.mp3");
//   mp3->setLoop(true);
//   mp3->play();

   while (1) {
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CROSS) {
         break;
      }
      sceDisplayWaitVblankStart();
//      printf("CallbackThread1:%d\n", mp3->playTime());
//      mp3->update();
   }
//   delete mp3;

}
Back to top
View user's profile Send private message
wxnlyq



Joined: 03 Oct 2008
Posts: 4

PostPosted: Fri Oct 03, 2008 1:17 pm    Post subject: Reply with quote

In the sample code, sceAudioSRCOutputBlocking is used to send the audio data.
When I try to change the sceAudioSRCChRelease/sceAudioSRCChReserve/sceAudioSRCOutputBlocking to sceAudioChRelease/sceAudioChReserve/sceAudioOutputBlocking, the sound comes to noise.
How can I use sceAudioOutputBlocking to assign a channel to feed the data?
Back to top
View user's profile Send private message
wxnlyq



Joined: 03 Oct 2008
Posts: 4

PostPosted: Fri Oct 03, 2008 1:49 pm    Post subject: Reply with quote

I set the filepath to be absolute and now it can be run in a thread.
But when MyCallbackThread and MyCallbackThread1 are run at the same time, problem occurs.

1、Why I can't use a relative path to open a file?
2、Can't pspmp3 lib be used in multithread?

Code:

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>
#include <pspdisplay.h>
#include "Mp3.h"
#include "Log.h"
#include "MyMp3.h"
PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1)
;PSP_MAIN_THREAD_ATTR(0);
PSP_HEAP_SIZE_KB(18*1024);
#define printf pspDebugScreenPrintf
// TWILIGHT ZONE! <do doo do doo>
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
   sceKernelExitGame();
   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
   int cbid;

   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);

   sceKernelSleepThreadCB();

   return 0;
}
int MyCallbackThread(SceSize args, void *argp) {
   printf("1new Mp3\n");
   Mp3 *mp3 = new Mp3("ms0:/08.mp3");
   mp3->setLoop(true);
   printf("1play\n");
   mp3->play();
   while (1) {
      printf("1MyCallbackThread:%d\n", mp3->playTime());
      mp3->update();
   }
   delete mp3;
   return 0;
}
int MyCallbackThread1(SceSize args, void *argp) {
   printf("2new Mp3\n");
   Mp3 *mp3 = new Mp3("ms0:/music.mp3");
   mp3->setLoop(true);
   printf("2play\n");
   mp3->play();
   while (1) {
      printf("2MyCallbackThread:%d\n", mp3->playTime());
      mp3->update();
   }
   delete mp3;
   return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
   int thid = 0;

   thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
   if (thid >= 0) {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}
// END OF TWILIGHT ZONE! <do doo do do>
int main() {
   scePowerSetClockFrequency(333, 333, 166);

   pspDebugScreenInit();
   SetupCallbacks();

   SceCtrlData pad;

   int thid = 0;

   Mp3::init();
   thid = sceKernelCreateThread("mythread", MyCallbackThread, 0x11, 0xFA0, 0, 0);
   if (thid >= 0) {
      sceKernelStartThread(thid, 0, 0);
   }
   thid = sceKernelCreateThread("mythread1", MyCallbackThread1, 0x11, 0xFA0, 0, 0);
   if (thid >= 0) {
      sceKernelStartThread(thid, 0, 0);
   }

//   Mp3 *mp3 = new Mp3("music.mp3");
//   mp3->setLoop(true);
//   mp3->play();

   while (1) {
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CROSS) {
         break;
      }
      //sceDisplayWaitVblankStart();
//      printf("CallbackThread1:%d\n", mp3->playTime());
//      mp3->update();
   }
//   delete mp3;

}
Back to top
View user's profile Send private message
sakya



Joined: 28 Apr 2006
Posts: 190

PostPosted: Fri Oct 03, 2008 7:21 pm    Post subject: Reply with quote

Hi! :)

wxnlyq wrote:
1、Why I can't use a relative path to open a file?

Did you try to change the current dir with sceIoChdir to be sure that the current directory is what you think?

Ciaooo
Sakya
Back to top
View user's profile Send private message Visit poster's website
wxnlyq



Joined: 03 Oct 2008
Posts: 4

PostPosted: Fri Oct 03, 2008 7:32 pm    Post subject: Reply with quote

sakya wrote:
Hi! :)

wxnlyq wrote:
1、Why I can't use a relative path to open a file?

Did you try to change the current dir with sceIoChdir to be sure that the current directory is what you think?

Ciaooo
Sakya

music.mp3 is located in the directory where my EBOOT.PBP exits.
In the main, I can use sceIoOpen("music.mp3",...) to open the file,
but in the MyCallbackThread, sceIoOpen("music.mp3",...) fail to find it.

Isn't the current dir different between threads?
Back to top
View user's profile Send private message
theHobbit



Joined: 30 Sep 2006
Posts: 65

PostPosted: Thu Oct 09, 2008 10:18 am    Post subject: Reply with quote

Does anyone have an idea on how to implement a seek function with this library?
Back to top
View user's profile Send private message
homemister



Joined: 24 Mar 2008
Posts: 25

PostPosted: Fri Nov 14, 2008 12:46 pm    Post subject: Reply with quote

DONE!
Here is the code i used. I uses some of the ID3 functions to get the starting place for the mp3.
Code:
/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Sample to demonstrate proper use of the mp3 library
 *
 * Copyright (c) 2008 Alexander Berl <raphael@fx-world.org>
 *
 * $Id: $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <pspaudio.h>
#include <pspmp3.h>
#include <psputility.h>
#include <string.h>

#include <stdio.h>

#include <stdlib.h>

#include <malloc.h>
#include "../players/id3.h"
#include "../players/player.h"
#include <stdio.h>

#include <string.h>

#include <pspkernel.h>

#include <stdlib.h>
#include <pspiofilemgr.h>

static char mp3Buf[32*1024]  __attribute__((aligned(64)));
static short pcmBuf[32*(1152/2)]  __attribute__((aligned(64)));
//static int fd;
static int playmp3;
static SceUID mp3thread = -1;
static int handle;
static int channel = -1;
static int EOS = 0;
static int paused;
static char *MP3FILE;
static int samplingRate;
static int numChannels;
static int lastDecoded = 0;
static int volume = PSP_AUDIO_VOLUME_MAX;
static int numPlayed = 0;
static int loop = 0;
static short* buf;
static int pos;
static int posreal;
static int endpos;
static int data_starthm;
static int perc;
static SceInt64 res;
static int kbit;
static int size;
static int fillStreamBuffer( int fd, int handle )
{
   char* dst;
   int write;
   // Get Info on the stream (where to fill to, how much to fill, where to fill from)
   sceMp3GetInfoToAddStreamData( handle, &dst, &write, &pos);
   // Seek file to position requested
   sceIoLseek32Async( fd, posreal, SEEK_SET );
   sceIoWaitAsync(fd, &res);
   // Read the amount of data
   sceIoReadAsync( fd, dst, write );
   sceIoWaitAsync(fd, &res);
   posreal = posreal + res;
   // Notify mp3 library about how much we really wrote to the stream buffer
   sceMp3NotifyAddStreamData( handle, res );
   return (pos>0);
}
int decodeThread2(SceSize args, void *argp){
   fd = sceIoOpen(MP3FILE, PSP_O_RDONLY, 0777 );
   sceIoChangeAsyncPriority(fd, 0x10);

   data_starthm = ID3v2TagSize(MP3FILE);
   // Init mp3 resources
   sceMp3InitResource();
   sceIoLseek32Async(fd, 0, PSP_SEEK_SET);
   sceIoWaitAsync(fd, &res);
   sceIoLseek32Async( fd, 0, SEEK_END );
   sceIoWaitAsync(fd, &res);
   endpos = res;
   if(data_starthm > (endpos-1000)){
      data_starthm = 0;
   }
   size = (endpos - data_starthm);
   posreal = data_starthm;
   // Reserve a mp3 handle for our playback
   SceMp3InitArg mp3Init;
   mp3Init.mp3StreamStart = data_starthm;
   mp3Init.mp3StreamEnd = endpos;
   mp3Init.unk1 = 0;
   mp3Init.unk2 = 0;
   mp3Init.mp3Buf = mp3Buf;
   mp3Init.mp3BufSize = sizeof(mp3Buf);
   mp3Init.pcmBuf = pcmBuf;
   mp3Init.pcmBufSize = sizeof(pcmBuf);

   handle = sceMp3ReserveMp3Handle( &mp3Init );
   
   // Fill the stream buffer with some data so that sceMp3Init has something to work with
   fillStreamBuffer( fd, handle );
   
   sceMp3Init( handle );
   numChannels = sceMp3GetMp3ChannelNum( handle );
   kbit = sceMp3GetBitRate(handle);
   samplingRate = sceMp3GetSamplingRate(handle);
   lastDecoded = 0;
   volume = PSP_AUDIO_VOLUME_MAX;
   numPlayed = 0;
   loop = 0;
   while(playmp3)
   {
      while (paused)
      {
         perc = (posreal*100/endpos);
         if(perc >= 99){
            EOS = 1;
            paused = 0;
         }
         samplingRate = sceMp3GetSamplingRate(handle);
         // Check if we need to fill our stream buffer
         if (sceMp3CheckStreamDataNeeded( handle )>0)
         {
            fillStreamBuffer( fd, handle );
         }
         // Decode some samples
         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;
            }
         }
         // 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 );
      }
   sceKernelDelayThread(10000);
   }
   return 0;
}
/* main routine */
int LoadMp3(char *MP3FILEpath)
{
   playmp3 = 1;
   paused = 0;
   EOS = 0;
   MP3FILE = MP3FILEpath;
   mp3thread = sceKernelCreateThread("decodeThread2", decodeThread2, 12, 256*1024, PSP_THREAD_ATTR_USER, NULL);
   sceKernelStartThread(mp3thread, 0, NULL);
   return data_starthm;
            //sceMp3ResetPlayPosition( handle );
}
void PlayMp3()
{
   playmp3 = 1;
   paused = 1;
   EOS = 0;
}
void PauseMp3()
{
   if(paused == 1){
      paused = 0;
   }else{
      paused = 1;
   }
}
void LoopMp3(int num)
{
   sceMp3SetLoopNum(handle, num);
}
void StopMp3(void)
{
   playmp3 = 0;
   paused = 0;
   EOS = 0;
   sceKernelWaitThreadEnd(mp3thread, NULL);

       sceKernelDeleteThread(mp3thread);
   if (channel>=0)
      sceAudioSRCChRelease();
   sceMp3ReleaseMp3Handle( handle );
   sceMp3TermResource();
   sceIoClose( fd );
}
int getPos(void){

    return posreal;

}


int setPos(int value){
   posreal = value;

    return posreal;

}
int GetTime(void){

   int playTime = samplingRate>0?(posreal*8) / (kbit*1024):0;
   return playTime;

}
short *VisMp3(void) {
   return(buf);
}
int EOSMp3(void){

    return EOS;

}
int PercentMp3(void){

    return perc;

}
void setvolume(int num){
    volume = 327.68*num;

}
char *Mp3Filename(){

    return MP3FILE;

}
int rawlength(){
   return ((size*8) / (kbit*1024));
}
static void getMP3TagInfo(char *filename, struct fileInfo *targetInfo){

    //ID3:

    struct ID3Tag ID3;

    ID3 = ParseID3(filename);

    strcpy(targetInfo->title, ID3.ID3Title);

    strcpy(targetInfo->artist, ID3.ID3Artist);

    strcpy(targetInfo->album, ID3.ID3Album);

    strcpy(targetInfo->year, ID3.ID3Year);

    strcpy(targetInfo->genre, ID3.ID3GenreText);

    strcpy(targetInfo->trackNumber, ID3.ID3TrackText);

    targetInfo->encapsulatedPictureType = ID3.ID3EncapsulatedPictureType;

    targetInfo->encapsulatedPictureOffset = ID3.ID3EncapsulatedPictureOffset;

    targetInfo->encapsulatedPictureLength = ID3.ID3EncapsulatedPictureLength;

}
struct fileInfo Taginfo2(char *filename){

    struct fileInfo tempInfo;

    initFileInfo(&tempInfo);
    getMP3TagInfo(filename, &tempInfo);

    return tempInfo;

}

struct fileInfo Taginfo(char *filename){

    struct fileInfo tempInfo;

    initFileInfo(&tempInfo);
    getMP3TagInfo(filename, &tempInfo);
    tempInfo.kbit = kbit;
    tempInfo.hz = samplingRate;
   if(numChannels < 2){
      sprintf(tempInfo.mode,"mono");
   }else{
      sprintf(tempInfo.mode,"stereo");
   }
   int secs = (size*8) / (kbit*1024);
   int h = secs / 3600;

   int m = (secs - h * 3600) / 60;

   int s = secs - h * 3600 - m * 60;

   snprintf(tempInfo.strLength, sizeof(tempInfo.strLength), "%2.2i:%2.2i:%2.2i", h, m, s);

   return tempInfo;

}
Back to top
View user's profile Send private message
theHobbit



Joined: 30 Sep 2006
Posts: 65

PostPosted: Sat Nov 15, 2008 11:07 am    Post subject: Reply with quote

Thanks, i will give it a try. Do you know if this works with 48k samplerate?

I've been trying to play a song with 48k with no luck :(
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Mon Nov 17, 2008 5:17 pm    Post subject: Slowness issues ? Reply with quote

I've tried to use the sample in order to decode some mp3s, and it works fine as long I don't try to do anything else, but the sound becomes choppy whenever my app does an access to the disk, and overall adding mp3 output slows my application, a lot.
I have the following questions:

1) would increasing the sizes of mp3Buf and/or pcmBuf (as defined in Raphael's sample) help ? If so, why, and what would be the drawbacks ?

2) Would putting the mp3 playing routine in a separate thread help ? And if so, why ? (I have close to no knowledge in threads)

3) any other suggestion ?

Basically my main loop looks like this (pseudo code):
Code:

while (1){
 update sound
 update data
 render on screen
}

The "update sound" is basically the update method defined in wxnlyq's code a few posts above
Update data does some processing, checks user input, and sometimes loads files on the disk. When this happens, the sound becomes choppy.

(I was using Cooleye's method, in a separate thread until now, but I have weird problems with it and thought it'd be better to use the "latest" method)
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Mon Nov 17, 2008 9:17 pm    Post subject: Re: Slowness issues ? Reply with quote

replying to myself:

willow :--) wrote:

1) would increasing the sizes of mp3Buf and/or pcmBuf (as defined in Raphael's sample) help ? If so, why, and what would be the drawbacks ?

No, that didn't help.

Quote:

2) Would putting the mp3 playing routine in a separate thread help ?

Yes, that did the trick !
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Sun Nov 23, 2008 11:41 pm    Post subject: Reply with quote

Quote:
Here is the code i used. I uses some of the ID3 functions to get the starting place for the mp3.

I have a late SDK with this mp3 sample, but where can I find id3.h and player.h ?
Art.
_________________
If not actually, then potentially.
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Mon Nov 24, 2008 1:38 am    Post subject: Reply with quote

It's in Sakya's lightMP3 source code IIRC.
Back to top
View user's profile Send private message
jsharrad



Joined: 20 Oct 2005
Posts: 102

PostPosted: Mon Nov 24, 2008 7:58 am    Post subject: Reply with quote

Surely homemeister wouldn't be using sakya's GPL player code in his non GPL luaplayer? :P
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group