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 

Question about memory stick access and threads

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



Joined: 25 Apr 2005
Posts: 95

PostPosted: Fri Apr 18, 2008 12:31 pm    Post subject: Question about memory stick access and threads Reply with quote

I searched the forums and couldn't find a direct answer. I am writing a program for PSP that uses a thread to stream MP3s as background music using cooleye's example. Now the thread is reading the memory stick every time it needs a new frame in the mp3. The main program is also reading the memory stick fairly often. Do I need to worry about that? Does the kernel handle it alright or do I need to lock anything?

Thanks.
Back to top
View user's profile Send private message
a_noob



Joined: 17 Sep 2006
Posts: 97
Location: _start: jr 0xDEADBEEF

PostPosted: Fri Apr 18, 2008 2:30 pm    Post subject: Reply with quote

You shouldnt need to worry about it, but I would optimise the mp3 player to take larger chunks than just the next frame, I would advise taking in multiple frames, and using slightly more memory, This will also have less reading from the ms. Just my two cents ;)
_________________
Code:
.øOº'ºOø.
'ºOo.oOº'
Back to top
View user's profile Send private message AIM Address MSN Messenger
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Fri Apr 18, 2008 5:10 pm    Post subject: Reply with quote

Some tips: make the read buffer aligned to 64 bytes. There is actually a noticeable difference in reading speed when the buffer is aligned to 64 bytes.

Read always a quantity multiple of 512, the bigger the better (the file position should be also at a multiple of 512).
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Fri Apr 18, 2008 7:24 pm    Post subject: Reply with quote

I used a similar method to your initially, but it caused lagging when other file io was present (only from the save dialog).

To circumvent this I made larger reads (64 frames at a time), triple buffered and used async reading.

Moonlight's tips also give a decent boost.
Back to top
View user's profile Send private message
Viper8896



Joined: 26 Jan 2006
Posts: 110

PostPosted: Sun Apr 20, 2008 4:57 pm    Post subject: Reply with quote

some tips:

sceAudioOutput and sceAudioOutputBlocking are two functions that do the ouput. One starts the output and then executes the next bit of code. The other starts the output then waits before going to the next line of code. The trick is to have the sceAudioOutputBlocking in a different thread because when it executes this line of code it is really just waiting the thread so then you have you're decoding thread automatically get control and make sure the cpu has allways got something to do.

also if you're not sure of the sample size when you call:
sceAudioChReserve(int channel, int samplecount, int format);

the other way is to use:
sceAudioSetChannelDataLen(int channel, int samplecount);

before every output.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun Apr 20, 2008 7:15 pm    Post subject: Reply with quote

Also, the count must be a multiple of 64. Many people make the buffer 64 byte aligned as well, but that isn't required.
Back to top
View user's profile Send private message AIM Address
SilverSpring



Joined: 27 Feb 2007
Posts: 115

PostPosted: Sun Apr 20, 2008 9:18 pm    Post subject: Reply with quote

If anyone's interested, found a little while ago:

Code:
0x38553111  sceAudioSRCChReserve
0x5c37c0ae  sceAudioSRCChRelease
0xe0727056  sceAudioSRCOutputBlocking


Prototypes are different to the the sceAudioChReserve/sceAudioChRelease/sceAudioOutputBlocking, something like this:

Code:
int sceAudioSRCChReserve(int samplecount, int freq, int format);
int sceAudioSRCChRelease(void);
int sceAudioSRCOutputBlocking(int vol, void *buf);

That should complete the audio lib now.
Back to top
View user's profile Send private message Visit poster's website
Shapyi



Joined: 25 Apr 2005
Posts: 95

PostPosted: Mon Apr 21, 2008 9:56 am    Post subject: Reply with quote

Thanks for all the comments. Everything seems to be working fine.
Back to top
View user's profile Send private message
Viper8896



Joined: 26 Jan 2006
Posts: 110

PostPosted: Mon Apr 21, 2008 12:31 pm    Post subject: Reply with quote

SilverSpring wrote:
If anyone's interested, found a little while ago:.....


have you tried that, found out what it does and do you know what SRC means?
Back to top
View user's profile Send private message
SilverSpring



Joined: 27 Feb 2007
Posts: 115

PostPosted: Mon Apr 21, 2008 7:47 pm    Post subject: Reply with quote

Viper8896 wrote:
SilverSpring wrote:
If anyone's interested, found a little while ago:.....


have you tried that, found out what it does and do you know what SRC means?


Well those nids I was finding for cswindle so I'm guessing he might have a sample on the proper usage.
Back to top
View user's profile Send private message Visit poster's website
crazyc



Joined: 17 Jun 2005
Posts: 410

PostPosted: Thu Apr 24, 2008 6:49 am    Post subject: Reply with quote

SilverSpring wrote:
Viper8896 wrote:
SilverSpring wrote:
If anyone's interested, found a little while ago:.....


have you tried that, found out what it does and do you know what SRC means?


Well those nids I was finding for cswindle so I'm guessing he might have a sample on the proper usage.
http://forums.ps2dev.org/viewtopic.php?t=8742
Back to top
View user's profile Send private message
SilverSpring



Joined: 27 Feb 2007
Posts: 115

PostPosted: Thu Apr 24, 2008 8:20 am    Post subject: Reply with quote

crazyc wrote:
http://forums.ps2dev.org/viewtopic.php?t=8742


Oh ok, wow over 8 months ago too.

Well at least we have the proper names now so the post wasnt completely redundant :)
Back to top
View user's profile Send private message Visit poster's website
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