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 

Problems with mp3player

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 04, 2006 4:14 am    Post subject: Problems with mp3player Reply with quote

Hi folks,

I am using the mp3player.h and .c of the yelarb tutorials. Now it works great except for mp3 files that are to large or something then it crashes (not sure if it is because it is to large but it seems that way.)

has somebody else gotten this problem with it and has someone solved it?

or does anybody had any idea?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Sun Jun 04, 2006 7:14 am    Post subject: Re: Problems with mp3player Reply with quote

Ghoti wrote:
Hi folks,

I am using the mp3player.h and .c of the yelarb tutorials. Now it works great except for mp3 files that are to large or something then it crashes (not sure if it is because it is to large but it seems that way.)

has somebody else gotten this problem with it and has someone solved it?

or does anybody had any idea?


how large are your files?

Your program will crash if the file cannot be found.
Also, you don't want a file bitrate that is over 192kbps or that can cause problems.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 04, 2006 8:20 am    Post subject: Reply with quote

the file it hangs on is 10.6 mb and has a bitrate of 256. however when i tried it another time it didn't hang on that file.

it seems that it just hangs for no reason (not that i can see at the moment) any ideas?

tomorrow i will try to debug the code of the mp3player to look where exactly it crashes.

P.S. (it seems that also 320 bitrated files run or is it that it won't always run with the mp3player code but most of the time it will and with 192 or below it always run correct ?? )
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Sun Jun 04, 2006 8:48 am    Post subject: Reply with quote

Ghoti wrote:
the file it hangs on is 10.6 mb and has a bitrate of 256. however when i tried it another time it didn't hang on that file.

it seems that it just hangs for no reason (not that i can see at the moment) any ideas?

tomorrow i will try to debug the code of the mp3player to look where exactly it crashes.

P.S. (it seems that also 320 bitrated files run or is it that it won't always run with the mp3player code but most of the time it will and with 192 or below it always run correct ?? )


To my knowledge, you should aim for 192kbps, that will also reduce the filesize. Considering you're running on such a small system, it shouldn't be an issue, as you're not exactly aiming for 5.1 sound.

Also can I ask if you are playing more than one file in your program. Remember to free the files once you've finished. If you try to load another file, or the same file again it will cause a crash.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 04, 2006 6:46 pm    Post subject: Reply with quote

well i only do a next when you press a button or if the sounds has ended (just background music) i don't use any other sounds yet so only the music sound and i always do mp3_end() which has the stop, and freetune code and one line for something of the sammpling or something.

but the strange thing is it just stops random with songs it doesn't really matter what kind of song i guess, it even runs a mp3 that has the status corrupted in the psp mp3 gui (the standaard psp mp3 playing) so it is really strange
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Sun Jun 04, 2006 6:51 pm    Post subject: Reply with quote

Ghoti wrote:
well i only do a next when you press a button or if the sounds has ended (just background music) i don't use any other sounds yet so only the music sound and i always do mp3_end() which has the stop, and freetune code and one line for something of the sammpling or something.

but the strange thing is it just stops random with songs it doesn't really matter what kind of song i guess, it even runs a mp3 that has the status corrupted in the psp mp3 gui (the standaard psp mp3 playing) so it is really strange


Could you through some code up, and give a description of when it crashes.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Sun Jun 04, 2006 6:51 pm    Post subject: Reply with quote

Soz double post
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 04, 2006 8:13 pm    Post subject: Reply with quote

Hi here is the code from the mp3player.c :

Code:
//////////////////////////////////////////////////////////////////////
// Functions - Local and not public
//////////////////////////////////////////////////////////////////////

//  This is the initialiser and module loader
//  This is a general call, which loads the module from the
//  given address into the modplayer
//
//  It basically loads into an internal format, so once this function
//  has returned the buffer at 'data' will not be needed again.
int MP3_Load(char *filename)
{
    int fd;
    eos = 0;
    //psp_stats pstat;
    //sceIoGetstat(filename, &pstat);
   printTextScreen(10, 50, "LOAD: voor het openen", 16777215);
   flipScreen();
    if ((fd = sceIoOpen(filename, PSP_O_RDONLY, 0777)) > 0) {
      printTextScreen(10, 60, "LOAD: goed gegaan open", 16777215);
      flipScreen();
      //  opened file, so get size now
      size = sceIoLseek(fd, 0, PSP_SEEK_END);
      sceIoLseek(fd, 0, PSP_SEEK_SET);
      printTextScreen(10, 70, "LOAD: na het zoeken", 16777215);
      flipScreen();
      ptr = (unsigned char *) malloc(size + 8);
      memset(ptr, 0, size + 8);
      printTextScreen(10, 80, "LOAD: na memset", 16777215);
      flipScreen();
         if (ptr != 0) {      // Read file in
            sceIoRead(fd, ptr, size);
         } else {
            printf("Error allocing\n");
            sceIoClose(fd);
            return 0;
         }
      printTextScreen(10, 60, "LOAD: voor close", 16777215);
      flipScreen();
      // Close file
      sceIoClose(fd);
    }
   else {
      return 0;
    }
    //  Set volume to full ready to play
    //SetMasterVolume(64);
    isPlaying = FALSE;
    return 1;
}


the '

Code:
ptr = (unsigned char *) malloc(size + 8);
      memset(ptr, 0, size + 8);
cuases the crash

(checked that with the printtextscreen functions)
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Sun Jun 04, 2006 9:06 pm    Post subject: Reply with quote

The problem won't be with mp3player.c, unless you've modified how it works. As it works fine with me. Make sure you're code is something like this...

Code:

// Set everything up
MP3_Init(1);
// Load my music
MP3_Load("res/menu/duende.mp3");

// Go into loop until mp3 ends
while(MP3_EndOfStream()==0)
{
     // Game loop
}

// Stop MP3 and free the memory
MP3_Stop();
MP3_FreeTune();


I sense that somewhere you're not freeing the memory properly, and that's why it's crashing at that point. Or your file path to your mp3 is mucked up.

If you can, post your code that runs the mp3 and I'll test it on my machine.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 04, 2006 9:22 pm    Post subject: Reply with quote

Code:
//--------------------------------------
//
// MusicPlayerNext: to get the next mp3.
//
//--------------------------------------

   int MusicPlayerNext(){
      
   // check whether the dir is empty thsi iteration
      if (MusicStatus == 1){
         if ((dirEntryMusic = readdir(MainMusicDir)) == NULL) {
            MainMusicDir = opendir("ms0:/PSP/MUSIC/");
            sprintf(cCurrentPath, "ms0:/PSP/MUSIC/");
            MusicPlayerNext();
            return 0;
         }
      }
      else {
         if ((dirEntryMusic = readdir(SubMusicDir)) == NULL) {
            MusicStatus = 1;
            sprintf(cCurrentPath, "ms0:/PSP/MUSIC/");
            MusicPlayerNext();
            return 0;
         }
      }
      
   // load the filename
      sprintf(sSong, "%s", dirEntryMusic->d_name);

   // compare if string = .
      if (strcmp(sSong, ".") ==0){
         MusicPlayerNext();
      }

   // compare if string = ..
      if (strcmp(sSong, "..") == 0){
         MusicPlayerNext();
      }

      if ((strstr(dirEntryMusic->d_name,"MP3") != NULL) || (strstr(dirEntryMusic->d_name,"mp3") != NULL)) {
   
      // save full path
         sprintf(sSong, "%s%s",cCurrentPath, dirEntryMusic->d_name);
      // Load and play the song
         MP3_End();
         
         printTextScreen(10, 30, "na end", 16777215);
         flipScreen();
         MP3_Init(1);
         printTextScreen(10, 40, dirEntryMusic->d_name, 16777215);
         flipScreen();
         if (MP3_Load(sSong) == 0){
            printTextScreen(10, 50, "false load", 16777215);
            flipScreen();
            MusicPlayerNext();
         }
         else {
            printTextScreen(10, 60, "good load", 16777215);
            flipScreen();
            MP3_Play();
            printTextScreen(10, 70, "goodplay", 16777215);
            flipScreen();
         }
         return 0;
      }
      else {

         sprintf(sSong, "%s%s/", cCurrentPath, dirEntryMusic->d_name);
         sprintf(cCurrentPath, "%s", sSong);

         MusicStatus = 2;
         SubMusicDir = opendir(cCurrentPath);
         MusicPlayerNext();
      }

      return 0;
   }


the above is my code, i have not altered the mp3player ( i only deleted some of the debugging info because it is not nice to seee inside a game) the function searches the next mp3 in the k:/psp/music folder where you have your mp3 songs.

the problem is in the MP3_Load function


EDIT ::: do i have to INIT it with every mp3 again?? i now only init it once when my game starts
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Sun Jun 04, 2006 9:44 pm    Post subject: Reply with quote

I use the INIT function everytime.

Can you get the program to print out the string sSong before the load. I'm wondering if it's not being set up correctly.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 04, 2006 10:15 pm    Post subject: Reply with quote

i use this:

Code:
sprintf(sSongTest, "SONG: %s%s",cCurrentPath, dirEntryMusic->d_name);
         printTextScreen(10, 40, sSongTest, 16777215);

when it creashes this doesn't show anything including the SONG: so it gives probebly an error that is not noticed by something cause then i guees it gives "" to load and then load crashes with the memory thing

however it should give SONG: anyway right? so how can i do something about this?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Blue



Joined: 25 Feb 2006
Posts: 5

PostPosted: Mon Jun 05, 2006 2:41 am    Post subject: Reply with quote

Are you guys aware that you are copying the whole mp3 tot memory? And that the size of the PSP's mem is actually limited? If your stack size is set to like 10mb and you load an mp3 file larger than that it will crash on the malloc function because it just runs out of memory.

You should implement streaming if you need to play larger mp3 files, meaning that small parts of the mp3 file are read and played back and not the whole mp3 file is read into memory and then played back.
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Mon Jun 05, 2006 3:59 am    Post subject: Reply with quote

Blue wrote:
Are you guys aware that you are copying the whole mp3 tot memory? And that the size of the PSP's mem is actually limited? If your stack size is set to like 10mb and you load an mp3 file larger than that it will crash on the malloc function because it just runs out of memory.

You should implement streaming if you need to play larger mp3 files, meaning that small parts of the mp3 file are read and played back and not the whole mp3 file is read into memory and then played back.


I'm aware of that at least, but I'll be honest and say that I have no knowledge of how to do that. However that is not the issue here. He's having problems building the string to send to the function. I don't think there's anymore of an issue with his code.

I'm not sure how much you can get in the PSP's memory, but I've had no issues so far with this method. If you can explain a simple tutorial where we could stream the mp3 and play it, I'd be very happy 'cause it'd knock the loading times of my program a long way! :D
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Jun 05, 2006 5:15 am    Post subject: Reply with quote

Quote:
However that is not the issue here.
Sure it is.
Code:

      ptr = (unsigned char *) malloc(size + 8);
      memset(ptr, 0, size + 8);
      printTextScreen(10, 80, "LOAD: na memset", 16777215);
      flipScreen();
         if (ptr != 0) {      // Read file in
            sceIoRead(fd, ptr, size);
         } else {
            printf("Error allocing\n");
            sceIoClose(fd);
            return 0;
         }

should be
Code:

      ptr = (unsigned char *) malloc(size + 8);
      if (ptr != 0) {      // Read file in
            memset(ptr, 0, size + 8);
            printTextScreen(10, 80, "LOAD: na memset", 16777215);
            flipScreen();
            sceIoRead(fd, ptr, size);
      } else {
            printf("Error allocing\n");
            sceIoClose(fd);
            return 0;
      }
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Mon Jun 05, 2006 5:39 am    Post subject: Reply with quote

jimparis wrote:
Quote:
However that is not the issue here.
Sure it is.
Code:

      ptr = (unsigned char *) malloc(size + 8);
      memset(ptr, 0, size + 8);
      printTextScreen(10, 80, "LOAD: na memset", 16777215);
      flipScreen();
         if (ptr != 0) {      // Read file in
            sceIoRead(fd, ptr, size);
         } else {
            printf("Error allocing\n");
            sceIoClose(fd);
            return 0;
         }

should be
Code:

      ptr = (unsigned char *) malloc(size + 8);
      if (ptr != 0) {      // Read file in
            memset(ptr, 0, size + 8);
            printTextScreen(10, 80, "LOAD: na memset", 16777215);
            flipScreen();
            sceIoRead(fd, ptr, size);
      } else {
            printf("Error allocing\n");
            sceIoClose(fd);
            return 0;
      }


Well that's error in code that a lot of people are using... and I very much doubt that this is the error that he was experiencing, when he's not passing a correct string to the function.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Jun 05, 2006 7:08 am    Post subject: Reply with quote

Energy wrote:
Well that's error in code that a lot of people are using... and I very much doubt that this is the error that he was experiencing

His problem:
Ghoti wrote:

the '
Code:
ptr = (unsigned char *) malloc(size + 8);
      memset(ptr, 0, size + 8);

cuases the crash

is exactly what you would expect when the malloc() fails and returns NULL due to a lack of memory, and the memset() then operates on a NULL pointer.
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Mon Jun 05, 2006 7:22 am    Post subject: Reply with quote

Fair enough.
Anyone got an alternative on how to make the mp3player.c stream mp3's other than laod it all into memory? Or anywhere where there'd be a good example?
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Jun 05, 2006 8:05 am    Post subject: Reply with quote

Hi folks,

thanks for all the replies, The string that is send is correct so it is indeed the problem jimparis said (found it out just now, was displaying the wrong charstring :S sorry about that) so i will try his solution but i have a few remarks:

1. It is not a specific music file it crashes on, sometimes it crashes on the mp3 and the other it runs just fine with the same mp3, so i doubt it is length of the mp3 because one song of 13mb always runs correctly and has bitrate 320

2. it never crashes right away there is always a few songs that have played before it crashes (a probable memoryleak?)

3. Like energy said it is strange that my error resides in a piece of code that a lot of people use to play mp3 but then again now i think of it maybe those people only use smaller then 4mb files and with bitrate 128 but that i do not know but still it is strange if that is the problem

anyway i will first try the solution given
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Mon Jun 05, 2006 8:40 am    Post subject: Reply with quote

Energy wrote:
Fair enough.
Anyone got an alternative on how to make the mp3player.c stream mp3's other than laod it all into memory? Or anywhere where there'd be a good example?


http://forums.ps2dev.org/viewtopic.php?t=5089
Back to top
View user's profile Send private message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Mon Jun 05, 2006 9:17 am    Post subject: Reply with quote

Insert_witty_name wrote:
Energy wrote:
Fair enough.
Anyone got an alternative on how to make the mp3player.c stream mp3's other than laod it all into memory? Or anywhere where there'd be a good example?


http://forums.ps2dev.org/viewtopic.php?t=5089


Thanks for that :)
May see if it works as an alternative. Tho slightly scared about the idea of 25% CPU usage... :/

Instead of creating another thread, anyone have advice on what's a good way of playing short sound effects. Is libmad a good start?
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Jun 05, 2006 5:40 pm    Post subject: Reply with quote

Hi folks,

it seems that the solution you gave was correct i haven't had a crash anymore on the count of my mp3player :) thanks alot everyone for helping

greets ghoti
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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
Page 1 of 1

 
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