[Csnd] Receiving array blob via OSC in Python
Date | 2021-03-24 07:16 |
From | Andreas Bergsland |
Subject | [Csnd] Receiving array blob via OSC in Python |
Hi I am trying to send an array blob from Csound to Python (osc4py3). The blob gets received, but I can’t figure out the format/type. In osc4py3 the blob comes through as a memoryview object. When I try to access its elements, I only get numbers which are nothing like what I sent, and I am guessing it is some type issue. I was trying to look into the source code for OSCsend for /array/blob, and int32_t and char are the types I can identify. Can anyone point me in the right direction for how to approach this? Best, Andreas |
Date | 2021-03-24 08:42 |
From | Eduardo Moguillansky |
Subject | Re: [Csnd] Receiving array blob via OSC in Python |
An osc blob is just a char buffer. It's up to the receiver to convert it to usable data. The format is "documented" in the source code of OSCsend: ar = (ARRAYDAT *) p->arg[i]; size = 0; for(j=0; j < ar->dimensions; j++) { size += (int32_t)ar->sizes[j]*sizeof(MYFLT); } if(buffersize + size + 12 > bsize) { aux_realloc(csound, buffersize + size + 128, &p->aux); out = (char *) p->aux.auxp; bsize = p->aux.size; } data = size + 8; byteswap((char *)&data,4); memcpy(out+buffersize,&data,4); buffersize += 4; memcpy(out+buffersize,&(ar->dimensions),4); buffersize += 4; memcpy(out+buffersize,&ar->sizes[0],ar->dimensions*4); buffersize += ar->dimensions*4; memcpy(out+buffersize,ar->data,size); buffersize += size; break; From there, the format seems to be: * Total byte size of the data (int32) cheers, On 24.03.21 08:16, Andreas Bergsland
wrote:
|
Date | 2021-03-24 10:00 |
From | Andreas Bergsland |
Subject | Re: [Csnd] Receiving array blob via OSC in Python |
Thanks for this Eduardo. At the receiving end it looks like 96 chars, which seem to be the same no matter the number of dimensions and size of array I send. Which is strange if the blob should be able to contain arrays of different sizes and dimensions. I will ask the guy developing the library if he can explain it to me. Best, Andreas
From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Eduardo Moguillansky <eduardo.moguillansky@GMAIL.COM>
An osc blob is just a char buffer. It's up to the receiver to convert it to usable data. The format is "documented" in the source code of OSCsend: ar = (ARRAYDAT *) p->arg[i]; size = 0; for(j=0; j < ar->dimensions; j++) { size += (int32_t)ar->sizes[j]*sizeof(MYFLT); } if(buffersize + size + 12 > bsize) { aux_realloc(csound, buffersize + size + 128, &p->aux); out = (char *) p->aux.auxp; bsize = p->aux.size; } data = size + 8; byteswap((char *)&data,4); memcpy(out+buffersize,&data,4); buffersize += 4; memcpy(out+buffersize,&(ar->dimensions),4); buffersize += 4; memcpy(out+buffersize,&ar->sizes[0],ar->dimensions*4); buffersize += ar->dimensions*4; memcpy(out+buffersize,ar->data,size); buffersize += size; break; From there, the format seems to be: * Total byte size of the data (int32) cheers, On 24.03.21 08:16, Andreas Bergsland wrote:
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |