[PD] problem making an audio-thread-safe external

Hans-Christoph Steiner hans at at.or.at
Sun Oct 18 23:04:02 CEST 2009


I think a thread is likely just going to add complication here.  The  
HID stuff is all without threads and works well.  If cwiid is already  
threaded, then chances are you should be able to get data from its  
threads using non-blocking calls.  If it already buffers the data,  
then you don't need your own thread, just get the data from cwiid's  
buffer in a non-blocking way.

This is how the Linux input API works, IIRC.

.hc

On Oct 17, 2009, at 10:33 PM, Ivica Ico Bukvic wrote:

> Hi all,
>
> I am currently working on a threaded implementation of a wiimote
> external. The reason I was hoping threaded design would help is to  
> avoid
> dropped samples when issuing commands to wiimote (e.g. rumble/led  
> status
> change). So far, it seems that reading from wiimote, no matter how  
> fast,
> has no impact on the audio thread. However, writing even when such
> action is generated through a separate thread seems to cause drop-outs
> in the audio thread. The external (which was not originally built by  
> me)
> uses cwiid to communicate with wiimotes and my understanding is that
> cwiid is heavily threaded in and of itself. An example of a threaded
> code is below:
>
> void *cwiid_pthread2_setRumble(void *ptr)
> {
> 	
> 	threadedFunctionParams *rPars = (threadedFunctionParams*)ptr;
> 	t_wiimote *x = rPars->wiimote;
> 	t_floatarg f = rPars->f;
>
> 	if (x->connected)
> 	{
> 		if (cwiid_command(x->wiimote, CWIID_CMD_RUMBLE, f)) post("wiiremote
> error: problem setting rumble.");
> 	}
> }
>
> void cwiid_pthread_setRumble(t_wiimote *x, t_floatarg f)
> {
> 	threadedFunctionParams rPars;
> 	rPars.wiimote = x;
> 	rPars.f = f;
> 	
> 	pthread_t thread;
> 	int iret1;
>
> 	iret1 = pthread_create( &thread, NULL, cwiid_pthread2_setRumble,
> (void*) &rPars);
> 	pthread_join(thread, NULL);
> }
>
> So, cwiid_pthread_setRumble is called from Pd and then it in turn
> creates a thread that sends info to cwiid library against which the
> external is linked. I am confused as to why the new thread once it has
> been created still affects the Pd's audio thread. Any ideas?
>
> Best wishes,
>
> Ico
>
>
>
>
> _______________________________________________
> Pd-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list



----------------------------------------------------------------------------

"[W]e have invented the technology to eliminate scarcity, but we are  
deliberately throwing it away to benefit those who profit from  
scarcity."        -John Gilmore






More information about the Pd-list mailing list