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

Post Reply
LeF
Posts: 4
Joined: Tue Jul 14, 2009 10:44 pm

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

Post by LeF » Sat Aug 01, 2009 10:45 am

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

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

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

Post by vuurrobin » Sat Aug 01, 2009 12:28 pm

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.

LeF
Posts: 4
Joined: Tue Jul 14, 2009 10:44 pm

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

Post by LeF » Sat Aug 01, 2009 3:03 pm

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

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

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

Post by WinterMute » Sun Aug 02, 2009 11:47 pm

devkitARM does not support threading on the DS.

ASLib is an unsupported 3rd party library.
Help keep devkitPro toolchains free, Donate today

Personal Blog

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

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

Post by vuurrobin » Mon Aug 03, 2009 1:26 pm

@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).

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

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

Post by elhobbs » Mon Aug 03, 2009 2:10 pm

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.

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

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

Post by WinterMute » Tue Aug 04, 2009 12:08 am

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.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests