Random Homebrew: Remote Joy Lite Plugin
Remote Joy is a program to show your PSP's screen on your PC. This is the PSP plugin counterpart, yo [...]
Friends: Coding 'n Cracking - Nymphaea - PS3 Forum - darkforestgroup - daxhordes.org - Tgames - coldbird - gopsp.it - pspstation.org - prometheus - hgoel.info - MakeSmartTV - ps vita

sceMp3init Problem

Forum rules
Any post not directly related to programming will be moderated.
Do not request people to code something for you.
Avoid posting messages that do not bring anything to the conversation. We want the threads in this subforum to stay focused.

sceMp3init Problem

Postby thecobra » Sun Jun 10, 2012 7:12 pm

Hi everyone,

I been working a bit on the VHBL and trying to solve some problems that Some Homebrew are having with it. In the progress i got some homebrew to work better with it and reduce the amount of Homebrew crashing with it. I got to the point that i got GWP to load and start up instead of crashing like it did before. My problem is that it give a "can't start Audio Thread" error <- That GWP. I try to load the sample mp3 program and that also gave me an error with sceMp3Init. I found this weird so i tried to load the mp3 example without the sc3 exploit but i still got that same error.

Anyone knows from what may be the cause of that. I don't think it the file since the psp in xmb can load the mp3 file fine and the name of the file and the path is correct so i don't get why sceMp3Init will cause an error running directly from xmb.

Any help will be appreciated.

The code is the sample that comes with sdk. Here the code:

Spoiler
/*
* 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;
}


Thank you
Image
Tools

PSP Hack Device
PSVita 1.80 eCFW <Thank to wololo Community>
PSVita 1.67 vHBL Dead :(
PSP FAT 6.60 - CFW pro
thecobra
HBL Collaborator
 
Posts: 167
Joined: Thu Feb 24, 2011 7:50 pm

Re: sceMp3init Problem

Postby noname120 » Mon Jun 11, 2012 10:31 am

Of what I remember, the MP3 player is initialized once in the hbl because we can't load it again when unloaded. (Don't know why)

If I'm not wrong, imports should be fixed to your own function sceMp3initFix
noname120
 
Posts: 660
Joined: Thu Oct 07, 2010 4:29 pm

Re: sceMp3init Problem

Postby wth » Mon Jun 11, 2012 11:36 am

Well apparently for now this part of hbl is just commented out, so it doesn't look like anything is affecting the mp3 library currently in hbl
http://code.google.com/p/valentine-hbl/ ... c?r=57#175
http://code.google.com/p/valentine-hbl/ ... c?r=52#245

but I guess games importing the mp3 library already do initialize it, so it may explain why homebrews trying to init it again fail
wth
HBL Developer
 
Posts: 587
Joined: Wed Aug 31, 2011 4:44 pm

Re: sceMp3init Problem

Postby thecobra » Mon Jun 11, 2012 4:51 pm

Thanks but that doesn't explain why the mp3 example still give the same error even when i am running it directly(Running it from XMB). If it comes to it, i probably will have to patch the sceMp3Init but first i want to make sure it 100% HBL and not the PSP/Game itself. I know the mp3 example work because when i had it on a lower fw it use to work( 5.xx) but now on 6.60 it fails? that doesn't make sense to me unless the mp3 NIDS has been changed and i don't think that it.

Any other option or suggestions?
Image
Tools

PSP Hack Device
PSVita 1.80 eCFW <Thank to wololo Community>
PSVita 1.67 vHBL Dead :(
PSP FAT 6.60 - CFW pro
thecobra
HBL Collaborator
 
Posts: 167
Joined: Thu Feb 24, 2011 7:50 pm

Re: sceMp3init Problem

Postby noname120 » Tue Jun 12, 2012 7:24 am

You mean if you run the hbl from the xmb or the sample from the xmb ?
noname120
 
Posts: 660
Joined: Thu Oct 07, 2010 4:29 pm

Re: sceMp3init Problem

Postby thecobra » Tue Jun 12, 2012 2:48 pm

noname120 wrote:You mean if you run the hbl from the xmb or the sample from the xmb ?


the sample.
Image
Tools

PSP Hack Device
PSVita 1.80 eCFW <Thank to wololo Community>
PSVita 1.67 vHBL Dead :(
PSP FAT 6.60 - CFW pro
thecobra
HBL Collaborator
 
Posts: 167
Joined: Thu Feb 24, 2011 7:50 pm

Re: sceMp3init Problem

Postby noname120 » Tue Jun 12, 2012 9:11 pm

You mean not working with the regular launch from the xmb and not signed ? :?
noname120
 
Posts: 660
Joined: Thu Oct 07, 2010 4:29 pm

Re: sceMp3init Problem

Postby thecobra » Wed Jun 13, 2012 1:54 am

noname120 wrote:You mean not working with the regular launch from the xmb and not signed ? :?


yeah but the PSP is on cfw so no need to sign it.

I guess I just have to relook into it tomorrow. I can't think of any reason of why scemp3init will fail since everything else is loaded normally and it the only thing running at the time. only thing that comes up to my mind is the mp3 file itself not readable: (

p.s. didn't know if you where being sarcastic or asking a legit question lol :lol:
Image
Tools

PSP Hack Device
PSVita 1.80 eCFW <Thank to wololo Community>
PSVita 1.67 vHBL Dead :(
PSP FAT 6.60 - CFW pro
thecobra
HBL Collaborator
 
Posts: 167
Joined: Thu Feb 24, 2011 7:50 pm

Re: sceMp3init Problem

Postby noname120 » Wed Jun 13, 2012 8:07 am

Weird, I'll test this afternoon :)

Can I see the makefile ? Do you import anything ?

Provide all necessary files please.
noname120
 
Posts: 660
Joined: Thu Oct 07, 2010 4:29 pm

Re: sceMp3init Problem

Postby thecobra » Wed Jun 13, 2012 3:35 pm

noname120 wrote:Weird, I'll test this afternoon :)

Can I see the makefile ? Do you import anything ?

Provide all necessary files please.


The program can be found on the pspsdk sample folder. I haven't really change anything in it(that i can think of) so it the same. The only file that different is the mp3 i use but i can't provide that since i think it illegal to provide mp3 files that i bought online. You can test it with any mp3 file instead. the mp3 is a typical mp3 file you use on any mp3 player so .....

here the link for the sample online:
http://psp.jim.sh/svn/psp/trunk/pspsdk/src/samples/mp3/

I going to retest it again tonight to see if it just me...

Let me know if it work fine for you on 6.60 cfw
Image
Tools

PSP Hack Device
PSVita 1.80 eCFW <Thank to wololo Community>
PSVita 1.67 vHBL Dead :(
PSP FAT 6.60 - CFW pro
thecobra
HBL Collaborator
 
Posts: 167
Joined: Thu Feb 24, 2011 7:50 pm

Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests