Skip to content

Commit

Permalink
performance improvements to o.slip.decode. this commit minimizes the …
Browse files Browse the repository at this point in the history
…use of critical_enter/exit and brings its performance in line with slipOSC
  • Loading branch information
maccallum committed Dec 1, 2021
1 parent 1a43a8f commit c17d7ff
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/o.slip.decode/o.slip.decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ void oslip_sendData(t_oslip *x, short size, char *data);
#define ESC_END 0334 // ESC ESC_END means END data byte
#define ESC_ESC 0335 // ESC ESC_ESC means ESC data byte


int oslip_decode(t_oslip *x, unsigned char c)
{
critical_enter(x->lock);
int t;
switch(x->istate)
{
Expand Down Expand Up @@ -123,19 +121,14 @@ int oslip_decode(t_oslip *x, unsigned char c)
t = x->icount;
x->icount = 0;
x->istate = 0;

if((t % 4) == 0){
char buf[t];
char buf[MAXSLIPBUF];
memcpy(buf, x->slipibuf, t);
critical_exit(x->lock);
critical_exit(x->lock);
omax_util_outletOSC(x->outlet, t, buf);
OSC_MEM_INVALIDATE(buf);
//oslip_sendData(x, t, x->slipibuf);
return 0;
}else{
critical_exit(x->lock);
//object_error((t_object *)x, "bad packet: not a multiple of 4 length");
return 0;
}
}
x->istate = 0;
Expand Down Expand Up @@ -186,8 +179,6 @@ int oslip_decode(t_oslip *x, unsigned char c)
break;

}

critical_exit(x->lock);
return 1;
}

Expand Down Expand Up @@ -218,12 +209,21 @@ void sliplist(t_oslip *x, t_symbol *s, int argc, t_atom *argv)
return;
}
}
critical_enter(x->lock);
for(i=0;i<argc;++i) {
#ifdef OMAX_PD_VERSION
int e = atom_getlong(argv + i);
#else
int e = argv[i].a_w.w_long;
#endif
if(e < 256){
oslip_decode(x, e);
if(!oslip_decode(x, e))
{
critical_enter(x->lock);
}
}
}
critical_exit(x->lock);
}

void oslip_doc(t_oslip *x)
Expand Down Expand Up @@ -300,6 +300,8 @@ int main (void)

class_addmethod(c, (method)oslip_printcontents, "printcontents", 0);

ps_FullPacket = gensym("FullPacket");

finder_addclass("Devices","slipOSC");

class_register(CLASS_BOX, c);
Expand Down

0 comments on commit c17d7ff

Please sign in to comment.