[PD-dev] help with some new multichannel tools
Alexandre Torres Porres
porres at gmail.com
Sat Jul 22 20:52:11 CEST 2023
Hi, I'm creating new fun objects that are tools to deal with multichannel
signals to include in the next update of ELSE.
I have a working "pick~" object that picks a single channel from a
multichannel connection. Of course you can set which channel with a message.
I'm now expanding this concept to remap or reorder a multichannel signal,
much like how you can reorder a list message in Pd with dollar symbols ($1,
$2, etc). It is called "remap~" for now and takes floats or lists. A "0"
means "none", so no channel is picked and we get zeros. With a float input
or argument it is just like "pick~".
It is working well depending on the list I am sending, but somehow it
doesn't work for other lists.
here's the "dsp" code.
*static* *void* remap_dsp(t_remap *x, t_signal **sp){
signal_setmultiout(&sp[1], x->x_n);
*int* length = sp[0]->s_length;
*for*(*int* i = 0; i < x->x_n; i++){
*int* ch = x->x_vec[i].a_w.w_float;
*if*(ch > sp[0]->s_nchans)
ch = sp[0]->s_nchans;
*if*(ch >= 0)
dsp_add_copy(sp[0]->s_vec + ch*length, sp[1]->s_vec + i*length,
length);
*else*
dsp_add_zero(sp[1]->s_vec + i*length, length);
}
}
If I print the "ch" values and ch*length or i_lenght I get the expected
values, so I can't understand what goes wrong.
For instance, if I have a 4 channel connection input with values "1 2 3 4"
and send it the list "1 2 3 2 1" I get the correct expected output of "1 2
3 2 1". If I send it "2 1", output is the same! Single float values also
work as mentioned, now for some bugged outputs...
"3 2 1" gives me "3 2 *3*"
"1 1 2" gives me "1 1 *1*"
"1 2 2 3" gives me "1 2 2 *2*"
funny enough, something like "1 2 2 2 3" gives me the same correct output.
I can't see a pattern here. I need help from the wizards to please save me.
Test patch attached. Code lives here
https://github.com/porres/pd-else/blob/master/Code_source/Compiled/signal/remap~.c
thanks
ps. While we're at it, I don't get why we have both sp[0]->s_length
and sp[0]->s_n, aren't both the same?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20230722/9388f156/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pd
Type: application/octet-stream
Size: 1976 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20230722/9388f156/attachment.obj>
More information about the Pd-dev
mailing list