Csound Csound-dev Csound-tekno Search About

How to write a user-defined format of data?

Date2017-01-15 21:48
FromGleb
SubjectHow to write a user-defined format of data?
Hi everybody,

I have a question on writing binary dumps with user-defined format. 

For instance I would like to write some quantized k-values. I decide to
leave only 3 bits.
So instead of 0010101001010010 I have to write 001 and so on. They should be
stick together to form a byte series etc.

What is the most optimal and less painful (in a sense of creating some new
opcodes) way to achieve it?
We have ftsave, so I theoretically could fill some ftable with 0's and 1's
and then write it all as bits (after some modification of initial function).
But in that case, first I have to turn each value into a set of 0's and 1's,
i.e. an array of max length 16. 

Please, any ideas are very welcome... 



-----
Gleb Rogozinsky, PhD
Associated Professor
Interactive Arts Department
Saint-Petersburg University of Film and Television

Deputy Director of Medialab
Saint-Petersburg University of Telecommunications
--
View this message in context: http://csound.1045644.n5.nabble.com/Csnd-How-to-write-a-user-defined-format-of-data-tp5753972.html
Sent from the Csound - General mailing list archive at Nabble.com.

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

Date2017-01-18 22:06
FromSteven Yi
SubjectRe: How to write a user-defined format of data?
Hi Gleb,

I don't think there's an easy way to do this besides writing C opcodes
to read/write the bits from/to disk. It's not a use case that's really
come up before (or, at least, I haven't seen anyone ask for something
like this).

All best!
steven

On Sun, Jan 15, 2017 at 4:48 PM, Gleb  wrote:
> Hi everybody,
>
> I have a question on writing binary dumps with user-defined format.
>
> For instance I would like to write some quantized k-values. I decide to
> leave only 3 bits.
> So instead of 0010101001010010 I have to write 001 and so on. They should be
> stick together to form a byte series etc.
>
> What is the most optimal and less painful (in a sense of creating some new
> opcodes) way to achieve it?
> We have ftsave, so I theoretically could fill some ftable with 0's and 1's
> and then write it all as bits (after some modification of initial function).
> But in that case, first I have to turn each value into a set of 0's and 1's,
> i.e. an array of max length 16.
>
> Please, any ideas are very welcome...
>
>
>
> -----
> Gleb Rogozinsky, PhD
> Associated Professor
> Interactive Arts Department
> Saint-Petersburg University of Film and Television
>
> Deputy Director of Medialab
> Saint-Petersburg University of Telecommunications
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Csnd-How-to-write-a-user-defined-format-of-data-tp5753972.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
> 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

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

Date2017-01-18 23:20
FromGuillermo Senna
SubjectRe: How to write a user-defined format of data?
Hi,

Recently, I came across something that might help. I was trying to send
an array to Csound through OSC. The problem was that the first two
values (dimensions and size) were ints and the rest MYFLTs (the proper
values). I still haven't found a solution and actually I think the OSC
implementation in Csound should be changed to use all MYFLTs, but at
least for testing I ended up doing something like this in C++:

std::vector vec; // the vector to send
unsigned long ui = qvlist.size(); // the size of the array
ui <<= 32; // shift it 32 bits to the left
ui |= 1; // the dimensions of the array
vec.push_back (*(double*)&ui); // take the address of ui, cast is as a
double* and then dereference the pointer.

As awful as it looks, this encapsulates two ints in a double. The
resulting double is garbage, of course, but it contains the right bits.
Maybe you can create a new opcode (just for in-house use I'd assume)
that fills a table with up to 21 triplets of bits at each index
position. You'll need another one to read that, of course. After that
just use ftsave/ftload. Beware that MYFLT could be double or float!

Cheers.

On 18/01/17 19:06, Steven Yi wrote:
> Hi Gleb,
>
> I don't think there's an easy way to do this besides writing C opcodes
> to read/write the bits from/to disk. It's not a use case that's really
> come up before (or, at least, I haven't seen anyone ask for something
> like this).
>
> All best!
> steven
>
> On Sun, Jan 15, 2017 at 4:48 PM, Gleb  wrote:
>> Hi everybody,
>>
>> I have a question on writing binary dumps with user-defined format.
>>
>> For instance I would like to write some quantized k-values. I decide to
>> leave only 3 bits.
>> So instead of 0010101001010010 I have to write 001 and so on. They should be
>> stick together to form a byte series etc.
>>
>> What is the most optimal and less painful (in a sense of creating some new
>> opcodes) way to achieve it?
>> We have ftsave, so I theoretically could fill some ftable with 0's and 1's
>> and then write it all as bits (after some modification of initial function).
>> But in that case, first I have to turn each value into a set of 0's and 1's,
>> i.e. an array of max length 16.
>>
>> Please, any ideas are very welcome...
>>
>>
>>
>> -----
>> Gleb Rogozinsky, PhD
>> Associated Professor
>> Interactive Arts Department
>> Saint-Petersburg University of Film and Television
>>
>> Deputy Director of Medialab
>> Saint-Petersburg University of Telecommunications
>> --
>> View this message in context: http://csound.1045644.n5.nabble.com/Csnd-How-to-write-a-user-defined-format-of-data-tp5753972.html
>> Sent from the Csound - General mailing list archive at Nabble.com.
>>
>> 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
> 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

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

Date2017-01-19 07:12
FromGleb
SubjectRe: How to write a user-defined format of data?
Thanks for the answers!

I think I have a nice idea about it. First one should scale the value to
signed int. Then if one needs say 3 bits, he or she makes bitshift (16-3)
times.  Then the loop begins with one shift per iteration. The result (0 or
1) on each iteration should be recorded in ftable. After everything has been
requantised, one should read values (0s and 1s) from that ftable and group
them byte by byte (ie read 8 values and calculate the corresponding 8bit
int). Those new values are recorded in another table and then ftsave makes
it.

But anyway I suppose it should be an update of ftsave or maybe ftsave2.





-----
Gleb Rogozinsky, PhD
Associated Professor
Interactive Arts Department
Saint-Petersburg University of Film and Television

Deputy Director of Medialab
Saint-Petersburg University of Telecommunications
--
View this message in context: http://csound.1045644.n5.nabble.com/Csnd-How-to-write-a-user-defined-format-of-data-tp5753972p5754041.html
Sent from the Csound - General mailing list archive at Nabble.com.

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