Problems with mp3player
Problems with mp3player
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?
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Re: Problems with mp3player
how large are your files?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?
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.
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 ?? )
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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.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 ?? )
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.
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
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Could you through some code up, and give a description of when it crashes.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
Hi here is the code from the mp3player.c :
the '
cuases the crash
(checked that with the printtextscreen functions)
Code: Select all
//////////////////////////////////////////////////////////////////////
// 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;
}
Code: Select all
ptr = (unsigned char *) malloc(size + 8);
memset(ptr, 0, size + 8);
(checked that with the printtextscreen functions)
My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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...
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.
Code: Select all
// 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();
If you can, post your code that runs the mp3 and I'll test it on my machine.
Code: Select all
//--------------------------------------
//
// 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 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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
i use this:
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?
Code: Select all
sprintf(sSongTest, "SONG: %s%s",cCurrentPath, dirEntryMusic->d_name);
printTextScreen(10, 40, sSongTest, 16777215);
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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.
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.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 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
Sure it is.However that is not the issue here.
Code: Select all
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;
}
Code: Select all
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.jimparis wrote:Sure it is.However that is not the issue here.should beCode: Select all
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; }
Code: Select all
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; }
His problem: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
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.Ghoti wrote: the 'cuases the crashCode: Select all
ptr = (unsigned char *) malloc(size + 8); memset(ptr, 0, size + 8);
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
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
-
- Posts: 376
- Joined: Wed May 10, 2006 11:31 pm
http://forums.ps2dev.org/viewtopic.php?t=5089Energy 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?
Thanks for that :)Insert_witty_name wrote:http://forums.ps2dev.org/viewtopic.php?t=5089Energy 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?
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?
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
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php