Page 1 of 1

fopen() freezes the DS while concurrent access to the card

Posted: Sat Aug 01, 2009 10:45 am
by LeF
Hi,

I successfully used libfat to read and display images on my DS.
My concern is that when I use ASLib to stream a MP3 at the same time (using AS_MP3StreamPlay() function), it sometimes freezes the DS.

I think it may be caused by a concurrent access going wrong.
I made a "stress test loop" which load 2 jpgs files every second to diagnose. Here is the status:
- Loading + MP3 streaming : Freeze somewhere between a few seconds and 11 minutes (best results)
- Loading only : Didn't freeze after 9 hours
- MP3 only : Didn't freeze after 1 hour

Using extensive highly elaborated trace system (a.k.a. "printf" :o) ), freeze always happens during the fopen.

Is it a way to check that the libfat is ready before trying to open a file? (I don't mind waiting a few ms to open the file)

Thanks for reading my question,
Eric

Re: fopen() freezes the DS while concurrent access to the card

Posted: Sat Aug 01, 2009 12:28 pm
by vuurrobin
it is known that ASlib takes a heavy tol on the ds, leaving little time left for your program. I also believe that opening a file while streaming a mp3 isn't possible, because ASlib needs constant acces to the mp3 file.


and ASlib probably isn't supported by devkitPro.

Re: fopen() freezes the DS while concurrent access to the card

Posted: Sat Aug 01, 2009 3:03 pm
by LeF
Thanks for your reply vuurobin!

I was thinking that ASLib was using the ARM7, leaving most of the ARM9 resources for your program... but I may be wrong here since I didn't actually check the code source.

I've read on this very forum that libfat was thread safe, and I still cannot understand how it would be possible than the lib can be placed in a situation where no file could be opened (except for exhausting the max number of handlers, which is probably not the case here (I checked the numerical value of the fd, and it stayed stable)).

ASLib is just using libfat here. This freeze is probably libfat related and could probably be reproduced without ASLib.

I could probably work-around the problem by preloading all my files before starting the music, but I am really curious about the source of the issue (you always learn a lot by understanding why things doesn't work how they're supposed to ;o) ).

Eric

Re: fopen() freezes the DS while concurrent access to the card

Posted: Sun Aug 02, 2009 11:47 pm
by WinterMute
devkitARM does not support threading on the DS.

ASLib is an unsupported 3rd party library.

Re: fopen() freezes the DS while concurrent access to the card

Posted: Mon Aug 03, 2009 1:26 pm
by vuurrobin
@WinterMute, maybe he meant threading more like this, where you said that libfat is thread safe.

@LeF, ASlib uses the ARM7 to play the file, but it uses ARM9 to stream the file from the flashcard. because it does this every vblank, it leaves little to no time to access any other file on the flashcard (flashcards aren't exactly fast when it comes to accessing files).

Re: fopen() freezes the DS while concurrent access to the card

Posted: Mon Aug 03, 2009 2:10 pm
by elhobbs
you could try removing the aslib vblank handler and calling it directly in you main loop. provided that you main loop does not run too slow then it should work.

also, make sure you are NOT calling irqInit() as this is being called for you in startup code in the newer libnds versions.

Re: fopen() freezes the DS while concurrent access to the card

Posted: Tue Aug 04, 2009 12:08 am
by WinterMute
vuurrobin wrote:@WinterMute, maybe he meant threading more like this, where you said that libfat is thread safe.
Yeah but libfat is only thread safe in a threaded environment like cube/wii. Currently devkitARM does not support threading and there aren't really any current plans to change that.
@LeF, ASlib uses the ARM7 to play the file, but it uses ARM9 to stream the file from the flashcard. because it does this every vblank, it leaves little to no time to access any other file on the flashcard (flashcards aren't exactly fast when it comes to accessing files).
This is one of the reasons why streaming audio on the DS isn't the best of ideas. Generally I'd use tracker formats for in game music unless you're doing something like a standalone mp3 player.