MultiIn MultiOut Ugen
[email protected] Fri, 23 Oct 2020 21:18:37 +0200
| Newsgroups | gmane.comp.audio.supercollider.devel |
|---|---|
| Message-ID | <[email protected]> |
--=-ZW3gqG8mwTwAsAVcuthN
Content-Type: text/plain; charset=us-ascii; format=flowed
Dear List,
I can see that you are busy with a lot of meetings and I don't want to
bother you, but I'd like to hear your opinion about my project.
I'm trying to program a MultiOutUgen which is at the same time a sort
of "MultiIn" Ugen.
This is the class:
NewOne : MultiOutUGen {
*ar {
arg in, mul = 1.0, add = 0.0;
^this.multiNewList(['audio']++ in.asArray)
}
init { arg ... theInputs;
inputs = theInputs;
^this.initOutputs(inputs.size, rate);
}
}
The number of outputs is always equal to the number of inputs.
In C++ the NewOne_next function defines:
int n = unit->mNumInputs;
out = OUT(0);
float a[n]; // prepare an empty array for processing
// fill the array with the values of each input
for (int ch = 0; ch < n; ch++) {
in = IN(ch);
a[ch] = *in;
}
"a" is now an array of length "n" (equals to the number of inputs, and
I'm ready to manipulate it).
To process the array I'm calling the function "process) which returns
an array of the same size:
float *result = process(a, n); // returns an array of floats
the function "process" works perfectly (I mean: it does what I need).
Now the only thing that is missing is sending each index of the array
to the appropriate output. I'm trying to do it with a classic for loop:
// output loop
for(int i=0; i<inNumSamples; i++){
out = &result[i];
}
but unfortunately the order of the elements of the arrays is wrong.
Let me give you an example:
a = [1,0,1,0];
result = [1,1,0,0];
but in SC if I poll the output of the Ugen the result is:
UGen Array [0]: 1 // correct
UGen Array [1]: 0 // should be 1
UGen Array [2]: 1 // should be 0
UGen Array [3]: 0 // correct
I'm learning cpp through coding so, there might be inconsistencies in
what I presented you, but for what I managed to debug, I think that the
problem lies in the "output for loop". If I print result[i] inside the
"output loop" the order is correct.
Could you help me? Do you need more informations, or more code?
thank you
Davide
--=-ZW3gqG8mwTwAsAVcuthN
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
<body><div dir=3D"ltr"><span style=3D"background-color: rgb(255, 255, 255);=
">Dear List,</span><br><div style=3D"background-color: rgb(255, 255, 255);"=
><br></div><div style=3D"background-color: rgb(255, 255, 255);">I can see t=
hat you are busy with a lot of meetings and I don't want to bother you, but=
I'd like to hear your opinion about my project.</div><div style=3D"backgro=
und-color: rgb(255, 255, 255);">I'm trying to program a MultiOutUgen which =
is at the same time a sort of "MultiIn" Ugen.</div><div style=3D"background=
-color: rgb(255, 255, 255);">This is the class:</div><div style=3D"backgrou=
nd-color: rgb(255, 255, 255);"><br></div><div style=3D"background-color: rg=
b(255, 255, 255);"><div>NewOne : MultiOutUGen {</div><div><span class=3D"Ap=
ple-tab-span" style=3D"white-space: pre;"> </span>*ar {</div><div><span cla=
ss=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>arg in, mul =3D =
1.0, add =3D 0.0;</div><div><span class=3D"Apple-tab-span" style=3D"white-s=
pace: pre;"> </span>^this.multiNewList(['audio']++ in.asArray)</div><div><=
span class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>}</div><d=
iv><span class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>init =
{ arg ... theInputs;</div><div><span class=3D"Apple-tab-span" style=3D"whit=
e-space: pre;"> </span>inputs =3D theInputs;</div><div><span class=3D"Appl=
e-tab-span" style=3D"white-space: pre;"> </span>^this.initOutputs(inputs.s=
ize, rate);</div><div><span class=3D"Apple-tab-span" style=3D"white-space: =
pre;"> </span>}</div><div>}</div></div><div style=3D"background-color: rgb(=
255, 255, 255);"><br></div><div style=3D"background-color: rgb(255, 255, 25=
5);">The number of outputs is always equal to the number of inputs.</div><d=
iv style=3D"background-color: rgb(255, 255, 255);">In C++ the NewOne_next f=
unction defines:</div><div style=3D"background-color: rgb(255, 255, 255);">=
<div>int n =3D unit->mNumInputs;</div><div>out =3D OUT(0);</div><div>flo=
at a[n]; // prepare an empty array for processing</div><div>// fill the arr=
ay with the values of each input</div><div> for (int ch =3D 0; ch <=
n; ch++) {</div><div> in =3D IN(ch);</div><div> a[=
ch] =3D *in;</div><div> }</div></div><div style=3D"background-color: r=
gb(255, 255, 255);"><br></div><div style=3D"background-color: rgb(255, 255,=
255);">"a" is now an array of length "n" (equals to the number of inputs, =
and I'm ready to manipulate it).</div><div style=3D"background-color: rgb(2=
55, 255, 255);">To process the array I'm calling the function "process) whi=
ch returns an array of the same size:</div><div style=3D"background-color: =
rgb(255, 255, 255);"><br></div><div style=3D"background-color: rgb(255, 255=
, 255);">float *result =3D process(a, n); // returns an array of floats</di=
v><div style=3D"background-color: rgb(255, 255, 255);"><br></div><div style=
=3D"background-color: rgb(255, 255, 255);">the function "process" works per=
fectly (I mean: it does what I need).</div><div style=3D"background-color: =
rgb(255, 255, 255);">Now the only thing that is missing is sending each ind=
ex of the array to the appropriate output. I'm trying to do it with a class=
ic for loop:</div><div style=3D"background-color: rgb(255, 255, 255);"><br>=
</div><div style=3D"background-color: rgb(255, 255, 255);">// output loop</=
div><div style=3D"background-color: rgb(255, 255, 255);">for(int i=3D0; i&l=
t;inNumSamples; i++){</div><div style=3D"background-color: rgb(255, 255, 25=
5);"><div> out =3D &result[i];</div><div> }</div></d=
iv><div style=3D"background-color: rgb(255, 255, 255);"><br></div><div styl=
e=3D"background-color: rgb(255, 255, 255);">but unfortunately the order of =
the elements of the arrays is wrong.</div><div style=3D"background-color: r=
gb(255, 255, 255);">Let me give you an example:</div><div style=3D"backgrou=
nd-color: rgb(255, 255, 255);"><br></div><div style=3D"background-color: rg=
b(255, 255, 255);">a =3D [1,0,1,0];</div><div style=3D"background-color: rg=
b(255, 255, 255);">result =3D [1,1,0,0];</div><div style=3D"background-colo=
r: rgb(255, 255, 255);"><br></div><div style=3D"background-color: rgb(255, =
255, 255);">but in SC if I poll the output of the Ugen the result is:</div>=
<div style=3D"background-color: rgb(255, 255, 255);"><div>UGen Array [0]: 1=
// correct</div><div>UGen Array [1]: 0 // should be 1</div><div>UGen Array=
[2]: 1 // should be 0</div><div>UGen Array [3]: 0 // correct</div></div><d=
iv style=3D"background-color: rgb(255, 255, 255);"><br></div><div style=3D"=
background-color: rgb(255, 255, 255);">I'm learning cpp through coding so, =
there might be inconsistencies in what I presented you, but for what I mana=
ged to debug, I think that the problem lies in the "output for loop". If I =
print result[i] inside the "output loop" the order is correct.</div><div st=
yle=3D"background-color: rgb(255, 255, 255);">Could you help me? Do you nee=
d more informations, or more code? </div><div style=3D"background-colo=
r: rgb(255, 255, 255);"><br></div><div style=3D"background-color: rgb(255, =
255, 255);">thank you</div><div style=3D"background-color: rgb(255, 255, 25=
5);"><br></div><div style=3D"background-color: rgb(255, 255, 255);">Davide<=
/div><br><div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmail=
_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div></div></div></div><=
/div></div></div>
</body>
--=-ZW3gqG8mwTwAsAVcuthN--
_______________________________________________
sc-dev mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/