Problems with sceKernelStartThread

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

Moderators: cheriff, TyRaNiD

Post Reply
Snatcher
Posts: 9
Joined: Tue Jul 19, 2005 2:31 am

Problems with sceKernelStartThread

Post by Snatcher »

Hello, I am trying to "port" fMSX to the PSP SDK, and have completed almost everything succesfully. The only problem I have right now is with the Audio threads, since the thing hangs when calling sceKernelStartThread after a successful sceKernelCreateThread.

Here is the code:

Code: Select all

strcpy(str,"pgasnd0");
	for &#40;i=0; i<PGA_CHANNELS; i++&#41; &#123;
		str&#91;6&#93;='0'+i;
		pga_threadhandle&#91;i&#93;=sceKernelCreateThread&#40;str,&pga_channel_thread,0x12,0x10000,0,NULL&#41;;
		if &#40;pga_threadhandle&#91;i&#93;<0&#41; &#123;
			pga_threadhandle&#91;i&#93;=-1;
			failed=1;
			break;
		&#125;
		ret=sceKernelStartThread&#40;pga_threadhandle&#91;i&#93;,sizeof&#40;i&#41;,&i&#41;;
		if &#40;ret!=0&#41; &#123;
			failed=1;
			break;
		&#125;
	&#125;
the thread callback is:

Code: Select all

static int pga_channel_thread&#40;SceSize args, void *argp&#41;
&#123;
	volatile int bufidx=0;
	int channel=*&#40;int *&#41;argp;
	
	while &#40;pga_terminate==0&#41; &#123;
		void *bufptr=&pga_sndbuf&#91;channel&#93;&#91;bufidx&#93;;
		void &#40;*callback&#41;&#40;void *buf, unsigned long reqn&#41;;
		callback=pga_channel_callback&#91;channel&#93;;
		if &#40;callback&#41; &#123;
			callback&#40;bufptr,PGA_SAMPLES&#41;;
		&#125; else &#123;
			unsigned long *ptr=bufptr;
			int i;
			for &#40;i=0; i<PGA_SAMPLES; ++i&#41; *&#40;ptr++&#41;=0;
		&#125;
		pgaOutBlocking&#40;channel,0x8000,0x8000,bufptr&#41;;
		bufidx=&#40;bufidx?0&#58;1&#41;;
	&#125;
	
	sceKernelExitThread&#40;0&#41;;
	return 0;
&#125;



void pga_channel_thread_callback&#40;int channel, void *buf, unsigned long reqn&#41;
&#123;
	void &#40;*callback&#41;&#40;void *buf, unsigned long reqn&#41;;
	callback=pga_channel_callback&#91;channel&#93;;
&#125;
Any ideas? I am using the following:

Code: Select all


PSP_MODULE_INFO&#40;"fMSX 0.62", 0, 6, 2&#41;; 

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU&#41;;
matkeupon
Posts: 26
Joined: Sat Jul 02, 2005 10:58 pm

Post by matkeupon »

This looks like the sdk's libpspaudio... So I guess you should just include it, it works fine, and without glitches. I also tried to adapt this initialisation for my game (using mono samples, and only one hardware channel), it won't hang, but it looks like the thread is not triggered when it should, so I switched back to libpspaudio.

Little hint there: libpspaudio always uses 8 hardware channels, even if you need only one. So put your callback threads on the channels you need, for the others just set up a callback function that does nothing, this will avoid having the psp filling 7 buffers with zeros all the time...
Snatcher
Posts: 9
Joined: Tue Jul 19, 2005 2:31 am

Post by Snatcher »

Thanks man, I found the real problem though, thanks to aprevious post of yours (http://forums.ps2dev.org/viewtopic.php? ... highlight=)

The solution was changing it to:

Code: Select all



#define PGA_CHANNELS 3
#define PGA_SAMPLES PSP_AUDIO_SAMPLE_ALIGN&#40;256&#41;
#define MAXVOLUME PSP_AUDIO_VOLUME_MAX


int pgaOutBlocking&#40;unsigned long channel,unsigned long vol1,unsigned long vol2,void *buf&#41;
&#123;
	if &#40;!pga_ready&#41; return -1;
	if &#40;channel>=PGA_CHANNELS&#41; return -1;
	if &#40;vol1>MAXVOLUME&#41; vol1=MAXVOLUME;
	if &#40;vol2>MAXVOLUME&#41; vol2=MAXVOLUME;
	return sceAudioOutputPannedBlocking&#40;pga_handle&#91;channel&#93;,vol1,vol2,buf&#41;;
&#125;
I was using the non Blocking version

and:

Code: Select all

strcpy&#40;str,"pgasnd0"&#41;;
	for &#40;i=0; i<PGA_CHANNELS; i++&#41; &#123;
		str&#91;6&#93;='0'+i;
		pga_threadhandle&#91;i&#93;=sceKernelCreateThread&#40;str,&pga_channel_thread,0x12,0x10000,0,NULL&#41;;
		if &#40;pga_threadhandle&#91;i&#93;<0&#41; &#123;
			pga_threadhandle&#91;i&#93;=-1;
			failed=1;
			break;
		&#125;
		ret=sceKernelStartThread&#40;pga_threadhandle&#91;i&#93;,sizeof&#40;i&#41;,&i&#41;;
		if &#40;ret!=0&#41; &#123;
			failed=1;
			break;
		&#125;
	&#125;
Post Reply