Question about memory stick access and threads

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Shapyi
Posts: 95
Joined: Mon Apr 25, 2005 9:31 am

Question about memory stick access and threads

Post by Shapyi »

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.
a_noob
Posts: 97
Joined: Sun Sep 17, 2006 8:33 am
Location: _start: jr 0xDEADBEEF

Post by a_noob »

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: Select all

.øOº'ºOø.
'ºOo.oOº'
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

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).
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

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.
Viper8896
Posts: 110
Joined: Thu Jan 26, 2006 6:20 pm

Post by Viper8896 »

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.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Also, the count must be a multiple of 64. Many people make the buffer 64 byte aligned as well, but that isn't required.
SilverSpring
Posts: 110
Joined: Tue Feb 27, 2007 9:43 pm
Contact:

Post by SilverSpring »

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

Code: Select all

0x38553111  sceAudioSRCChReserve
0x5c37c0ae  sceAudioSRCChRelease
0xe0727056  sceAudioSRCOutputBlocking
Prototypes are different to the the sceAudioChReserve/sceAudioChRelease/sceAudioOutputBlocking, something like this:

Code: Select all

int sceAudioSRCChReserve(int samplecount, int freq, int format);
int sceAudioSRCChRelease(void);
int sceAudioSRCOutputBlocking(int vol, void *buf);
That should complete the audio lib now.
Shapyi
Posts: 95
Joined: Mon Apr 25, 2005 9:31 am

Post by Shapyi »

Thanks for all the comments. Everything seems to be working fine.
Viper8896
Posts: 110
Joined: Thu Jan 26, 2006 6:20 pm

Post by Viper8896 »

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?
SilverSpring
Posts: 110
Joined: Tue Feb 27, 2007 9:43 pm
Contact:

Post by SilverSpring »

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.
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

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
SilverSpring
Posts: 110
Joined: Tue Feb 27, 2007 9:43 pm
Contact:

Post by SilverSpring »

Oh ok, wow over 8 months ago too.

Well at least we have the proper names now so the post wasnt completely redundant :)
Post Reply