<div dir="ltr"><div>Hi Alexandre,</div><div><br></div>You can also look at this thread on the <a href="http://forum.pdpatchrepo.info">forum.pdpatchrepo.info</a>: <a href="https://forum.pdpatchrepo.info/topic/10466/matrices-and-reallocating-memory">https://forum.pdpatchrepo.info/topic/10466/matrices-and-reallocating-memory</a>.<div>And to this code : <a href="https://github.com/pierreguillot/pd.dummies/blob/master/src/leeloo_tilde.c">https://github.com/pierreguillot/pd.dummies/blob/master/src/leeloo_tilde.c</a></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-02-22 18:41 GMT+01:00 Miller Puckette <span dir="ltr"><<a href="mailto:msp@ucsd.edu" target="_blank">msp@ucsd.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Check that the input addresses are different from the output ones - usually<br>
in a case like that Pd will re-use the memory from the inputs for the outputs,<br>
so your object needs to be able to operate in-place.<br>
<br>
(hint: allocate a bunch of temporary signals on teh stack using alloca(), and<br>
put the outputs in them irst; then when you're through using the intputs for<br>
anything, you can copy the temporary outputs to the real ones.)<br>
<br>
cheers<br>
Miller<br>
<div><div class="h5"><br>
On Thu, Feb 22, 2018 at 02:38:24PM -0300, Alexandre Torres Porres wrote:<br>
> Hi folks, I need help on an external. I wanna perform a task on an array of<br>
> signal inputs. It's a multichannel object, and I define the number of<br>
> channels with an argument.<br>
><br>
> Here's just the core of it, as an object named "mtx~", where I map the<br>
> input to the output. And this is what happens.<br>
><br>
> [image: Imagem inline 1]<br>
><br>
> So you see I get a weird mirrored output, instead of something like "1 2 3<br>
> 4 5 6".<br>
><br>
> The perform method in the code is just<br>
><br>
> static t_int *mtx_perform(t_int *w){<br>
><br>
>     t_mtx *x = (t_mtx *)(w[1]);<br>
><br>
>     int nblock = (int)(w[2]);<br>
><br>
>     t_float **in_vectors = x->x_in_vectors;<br>
><br>
>     t_float **out_vectors = x->x_out_vectors;<br>
><br>
>     t_int i;<br>
><br>
>     for(i = 0; i < x->x_ch; i++){<br>
><br>
>         t_float *in = in_vectors[i];<br>
><br>
>         t_float *out = out_vectors[i];<br>
><br>
>         t_int n = nblock;<br>
><br>
>         while(n--)<br>
><br>
>             *out++ = *in++;<br>
><br>
>     }<br>
><br>
>     return (w + 3);<br>
><br>
> }<br>
><br>
> What am I doing wrong? How should this go? See attached the help test<br>
> example and code.<br>
><br>
> Thanks<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div></div>> #include "m_pd.h"<br>
><br>
> typedef struct  _mtx{<br>
>       t_object    x_obj;<br>
>     t_int       x_ch;<br>
>     t_float   **x_in_vectors;<br>
>     t_float   **x_out_vectors;<br>
> }t_mtx;<br>
><br>
> static t_class *mtx_class;<br>
<span class="">><br>
> static t_int *mtx_perform(t_int *w){<br>
>     t_mtx *x = (t_mtx *)(w[1]);<br>
>     int nblock = (int)(w[2]);<br>
>     t_float **in_vectors = x->x_in_vectors;<br>
>     t_float **out_vectors = x->x_out_vectors;<br>
>     t_int i;<br>
>     for(i = 0; i < x->x_ch; i++){<br>
>         t_float *in = in_vectors[i];<br>
>         t_float *out = out_vectors[i];<br>
>         t_int n = nblock;<br>
>         while(n--)<br>
>             *out++ = *in++;<br>
>     }<br>
>     return (w + 3);<br>
> }<br>
><br>
</span>> static void mtx_dsp(t_mtx *x, t_signal **sp){<br>
>     t_int i, nblock = sp[0]->s_n;<br>
>     t_signal **sigp = sp;<br>
>     t_float **vecp = x->x_in_vectors;<br>
<span class="">>     for(i = 0; i < x->x_ch; i++)<br>
</span>>               *vecp++ = (*sigp++)->s_vec; // input vectors<br>
>     vecp = x->x_out_vectors;<br>
<span class="">>     for(i = 0; i < x->x_ch; i++)<br>
</span>>               *vecp++ = (*sigp++)->s_vec; // output vectors<br>
>     dsp_add(mtx_perform, 2, x, nblock);<br>
> }<br>
><br>
> static void *mtx_free(t_mtx *x){<br>
>     freebytes(x->x_in_vectors, x->x_ch * sizeof(*x->x_in_vectors));<br>
>     freebytes(x->x_out_vectors, x->x_ch * sizeof(*x->x_out_vectors));<br>
>       return(void *)x;<br>
> }<br>
><br>
> static void *mtx_new(t_floatarg f){<br>
>       t_mtx *x = (t_mtx *)pd_new(mtx_class);<br>
>     x->x_ch = (int)f < 1 ? 1 : (int)f > 64 ? 64 : (int)f;<br>
>       x->x_in_vectors = getbytes(x->x_ch * sizeof(*x->x_in_vectors));<br>
>     x->x_out_vectors = getbytes(x->x_ch * sizeof(*x->x_out_vectors));<br>
<span class="">>     t_int i;<br>
>     for(i = 0; i < x->x_ch; i++)<br>
</span>>         inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);<br>
<span class="">>       for(i = 0; i < x->x_ch; i++)<br>
</span>>               outlet_new(&x->x_obj, gensym("signal"));<br>
>       return(x);<br>
> }<br>
><br>
> void mtx_tilde_setup(void){<br>
>     mtx_class = class_new(gensym("mtx~"), (t_newmethod)mtx_new, (t_method)mtx_free,<br>
>                            sizeof(t_mtx), CLASS_NOINLET, A_DEFFLOAT, 0);<br>
>     class_addmethod(mtx_class, (t_method)mtx_dsp, gensym("dsp"), A_CANT, 0);<br>
> }<br>
<br>
> ______________________________<wbr>_________________<br>
> Pd-dev mailing list<br>
> <a href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a><br>
> <a href="https://lists.puredata.info/listinfo/pd-dev" rel="noreferrer" target="_blank">https://lists.puredata.info/<wbr>listinfo/pd-dev</a><br>
<br>
<br>
______________________________<wbr>_________________<br>
Pd-dev mailing list<br>
<a href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a><br>
<a href="https://lists.puredata.info/listinfo/pd-dev" rel="noreferrer" target="_blank">https://lists.puredata.info/<wbr>listinfo/pd-dev</a><br>
</blockquote></div><br></div>