Welcome! Log In Create A New Profile

Advanced

external mp3 size limits?

Posted by mdbrim 
external mp3 size limits?
October 10, 2009 02:29AM
Used Arikado's blog to get external mp3 playing to work... works great.

Had some more discussion about it here.

All worked well.

Then i started throwing dif mp3 files in there and noticed that some would crash when it attempted to load and others wouldn't, and it seems to be based on the file size...

I haven't nailed down the exact cutoff point yet, but the biggest file i've gotten to work is 3625KB and the smallest one that still crashes is 4609KBs.

The cutoff is somewhere between those two, but i'm guessing it isn't an exact number, but based on mem available? I dunno.

Any ideas how to make bigger files work?

code:

FILE *BGM = 0;
long lSize;
char * mbuffer;
size_t mresult;

and

					BGM = fopen("test.mp3", "rb");
					fseek (BGM , 0 , SEEK_END);
					lSize = ftell (BGM);
					rewind (BGM);
					mbuffer = (char*) malloc (sizeof(char)*lSize);
					mresult = fread (mbuffer,1,lSize,BGM);
					fclose(BGM);
					MP3Player_PlayBuffer(mbuffer, lSize, NULL);
Re: external mp3 size limits?
October 10, 2009 04:27AM
in mp3player.c -

struct _rambuffer
{
	const void *buf_addr;
	s32 len,pos;
} rambuffer;

len is what you've passed in MP3Player_PlayBuffer(mbuffer, len, NULL);. See the problem ? s32 = 32bit signed integer which is 32767 I think :P


With WiiRadio I created a circular buffer to overcome this issue. Take a look at the SVN it may help you.
Re: external mp3 size limits?
October 10, 2009 05:27AM
cool ok, that makes sense... any way you can describe how you fixed that... i'm browsing your wiiradio source right now to see if i can figure it out. Does the SVN version of mp3player fix this and a simple update to that would help? Not to up to date on SVN builds and how to install them. (still a newb in some areas....)
Re: external mp3 size limits?
October 10, 2009 05:32AM
Actually looking over the mp3player source I don't think the len param in MP3Player_PlayBuffer() is the total size. I'm thinking it's a buffer size to read. I think libmad itself knows when it's reached the end of a stream. try MP3Player_PlayBuffer(mbuffer, 32767 , NULL); and see if it's as simple as that.

The mp3player.c in the SVN is basically the same I just added a callback to get the raw sample data so I could do an FFT on it.
Re: external mp3 size limits?
October 10, 2009 05:38AM
actually, it doesn't crash on the playbuffer part...

it crashes while trying to load the song on this part:

	BGM = fopen("sd:/apps/testing/music/blackjack.mp3", "rb");
	if(BGM==NULL) nosong=1;
	if(BGM!=NULL) {
		fseek (BGM , 0 , SEEK_END);
		lSize = ftell (BGM);
		rewind (BGM);
		mbuffer = (char*) malloc (sizeof(char)*lSize);
		mresult = fread (mbuffer,1,lSize,BGM);
		fclose(BGM);

so should i just edit the lSize=ftell(BGM) to lSize = 32767;



Edited 1 time(s). Last edit at 10/10/2009 05:39AM by mdbrim.
Re: external mp3 size limits?
October 10, 2009 05:41AM
lSize = 32767; prevented it from crashing, but it only played the first 1 second of the mp3

so the ftell(BGM) is the part it seems to be choking on.



Edited 1 time(s). Last edit at 10/10/2009 05:42AM by mdbrim.
Re: external mp3 size limits?
October 10, 2009 05:42AM
On the File IO or the alloc...

try :-
mbuffer = 0;
mbuffer = (char*) malloc (sizeof(char)*lSize);
if (!mbuffer) exit(0);

If you're app exit's your out of mem or lSize is not what you think it is.
Re: external mp3 size limits?
October 10, 2009 05:44AM
it exited

	BGM = fopen("sd:/apps/testing/music/blackjack.mp3", "rb");
		fseek (BGM , 0 , SEEK_END);
		lSize = 32767;
		lSize = ftell (BGM);
		rewind (BGM);
		mbuffer = 0;
		mbuffer = (char*) malloc (sizeof(char)*lSize);
		if(!mbuffer) exit(0);
		mresult = fread (mbuffer,1,lSize,BGM);
		fclose(BGM);

so was mresult = fread (mbuffer,1,lSize,BGM); where it was crashing?



Edited 1 time(s). Last edit at 10/10/2009 05:46AM by mdbrim.
Re: external mp3 size limits?
October 10, 2009 05:52AM
mbuffer is not being allocated so fread is crashing the app.

What is lSize ? I would recommend an unsigned long. Maybe it's not the the value you expect.
Re: external mp3 size limits?
October 10, 2009 05:56AM
long lSize;


i tried unsigned long lSize;
and
long long lSize;

both give same crash upon load attempt.
Re: external mp3 size limits?
October 10, 2009 06:04AM
lSize is showing 0 for the instances it crashes... lSize = ftell(BGM); makes lSize 0 for big files?
Re: external mp3 size limits?
October 10, 2009 06:06AM
Do you have a way to printf the value of lSize to make sure it's what you think it is. Also you maybe running out of memory. You may look into using MP3Player_PlayFile() as you've got more control with a callback. I know there are issues with this function though.

Something like so (probably needs testing/rough code :) ):

s32 reader_callback(void *usr_data,void *cb,s32 len)
{
    return fread(mbuffer,1,len,BGM)
}


BGM = fopen("sd:/apps/testing/music/blackjack.mp3", "rb");
mbuffer = 0;
mbuffer = (char*) malloc (32767);
if(!mbuffer) exit(0);
MP3Player_PlayFile(mbuffer, reader_callback, 0);

while(MP3Player_IsPlaying());

free(mbuffer);

Re: external mp3 size limits?
October 10, 2009 06:21AM
Quote
mdbrim
lSize is showing 0 for the instances it crashes... lSize = ftell(BGM); makes lSize 0 for big files?

Sure that fopen is opening the file?
Re: external mp3 size limits?
October 10, 2009 06:23AM
I'm pretty sure it is.... it works when i have smaller mp3s, and then it crashes with the bigger ones... it works with the bigger ones if i manually define lSize (instead of let ftell (BGM): do it. WHen i manually define lSize, it plays the mp3, but i can't get lSize big enough to play the whole mp3.



Edited 1 time(s). Last edit at 10/10/2009 06:24AM by mdbrim.
Re: external mp3 size limits?
October 10, 2009 06:33AM
ftell() maybe failing because it's taking too long to reach the end of the file ... I'm guessing here.

But having said that loading a 4MB mp3 into memory is probably not a good idea. The snippet I put above that uses a callback, this is probably a better way to play bigger files as you're only ever using a small piece of memory and dynamically reading the data from the file.
Re: external mp3 size limits?
October 10, 2009 06:35AM
ok sounds good... but your snippet also caused an exit... anyway you can clean up your example? I'm having a hard time grasping what you are doing... is there a loop that should be in there to keep the buffer updated?

Thanks again for all your help man...

worst case scenario, i'll just have it tell you "your mp3 is too big sucka, pick a new one" if i cna't get your method to work!



Edited 1 time(s). Last edit at 10/10/2009 06:38AM by mdbrim.
Re: external mp3 size limits?
October 10, 2009 07:00AM
ha, i broke it... now it isn't loading any mp3 files... wth!
Re: external mp3 size limits?
October 10, 2009 07:05AM
ok it didn't break, it just appears that my allowable size has gotten smaller...

ug

Yeah, right now i've got a statement that pops up saying too big if the lSize part borks...

it seems that somehow in this, the max file size i could play has gone down, so hopefully you can help me with your playfile example... :D



Edited 1 time(s). Last edit at 10/10/2009 07:09AM by mdbrim.
Re: external mp3 size limits?
October 10, 2009 08:20PM
UPDATE:

yeah, it appears to be an "out of mem" issue... if i start removing larger images and sound files, it starts to play the larger mp3s... i'll have to start looking into you buffer a little at a time method...
Sorry, only registered users may post in this forum.

Click here to login