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 

audio system collapse? (was: problem with threads/gu)

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



Joined: 22 Sep 2005
Posts: 351

PostPosted: Wed May 24, 2006 6:06 pm    Post subject: audio system collapse? (was: problem with threads/gu) Reply with quote

i'm encountering a strange problem.


basically i have 2 threads:


TH_A:
the first thread produce frames in a ring buffer (in memory).
it also uses the gu to get some work done in parallel with the cpu

TH_B:
the second thread output frames at the correct timing (with a simple sceDisplaySetFrameBuf)


the situation is something like:


TH_A:

loop:
{
wait the "i can put in the ring buffer" semaphore

generate a frame in the buffer

signal the "i can get from the ring buffer" semaphore
}


TH_B:

loop:
{
wait the "i can get from the ring buffer" semaphore

sceDisplaySetFrameBuf

signal the "i can put in the ring buffer" semaphore
(not done for the very first frame since the buffer is really reusable only from the second loop iteration)
}


TH_A priority is lower than TH_B priority.


and now the problem:

randomly TH_B seems to freeze.
some things i've noticed:

- seems to not happen when the cpu is at 333mhz
- seems to not happen if i eliminate the gu in the process
- seems to not happen if i give TH_A the same priority of TH_B


i really don't have idea of what happen (i could move the gu code in TH_B but this require a lot of tweaks and will be a suboptimal solution)


Last edited by jonny on Wed Jul 05, 2006 4:46 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
jonny



Joined: 22 Sep 2005
Posts: 351

PostPosted: Wed Jul 05, 2006 4:43 am    Post subject: Reply with quote

some progress:

TH_B also output audio with sceAudioOutputBlocking
this seems the function that freeze
if i change it to sceAudioOutput, i start getting silence (where previously i had the freeze - sceAudioOutput return 0x80260002)
so ... seems a sort of collapse of the psp audio system ...


another interesting thing:

TH_A uses the GU, during the process i use sceGuCopyImage to copy data from vram to system memory
if i comment this sceGuCopyImage, all seems to work correctly


someone see a relation in the 2 operations?

if someone want to check, i can post the code.
Back to top
View user's profile Send private message Visit poster's website
ReKleSS



Joined: 18 Jun 2005
Posts: 73
Location: Melbourne, Australia

PostPosted: Wed Jul 05, 2006 6:20 pm    Post subject: Reply with quote

There's one thing that comes to mind here, looking at your code - do you realize that the psp uses cooperative multithreading, and are you accounting for it? If yes, you can ignore the rest of what I have to say.

The psp won't take control away from your threads - you have to give it up. There are a few GU functions that will do so, so that your other threads can do stuff while the GU does whatever you told it to. sceKernelDelayThread(0) should make a thread yield; sceKernelSleepThread() may do the same thing, but I'm not sure.
Back to top
View user's profile Send private message
jonny



Joined: 22 Sep 2005
Posts: 351

PostPosted: Wed Jul 05, 2006 7:13 pm    Post subject: Reply with quote

Quote:

There's one thing that comes to mind here, looking at your code - do you realize that the psp uses cooperative multithreading, and are you accounting for it?

at the start, i was thinking about a similar problem, i have filled the code with many sceKernelDelayThread in both threads (even if the initial code should be already ok)
but this haven't solved


after a deep look, sceAudioOutputBlocking is the function that freeze the thread
the app runs normally for a bit, with correct audio and video output, but after some time it freeze (always at the same point)

- commenting sceAudioOutputBlocking eliminate the freeze
- changing sceAudioOutputBlocking to sceAudioOutput no more freeze the app (but i get silence after i surpass the point where i previously had the freeze)

so, seems that something in the audio system gets ruined
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