[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] MultiIn MultiOut Ugen



Some more comments:

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;
 }
Also, here you basically just copy the first sample of each input channel into a temporary array. I'm not sure this is what you want... But again, I have to see the actual code.

To process the array I'm calling the function "process) which returns an array of the same size:
It's unusual for a function to *return* an array. Where/how did you allocate the storage for this array? Either you process in place (so the array input parameter for your "process" function also serves as the output parameter), or you pass another array where the result should be written.

It seems like you then want to assign the results to the outputs. But there is a problem, because you only have a single value per channel, but the outputs are audio rate.

So either your UGen is really meant to be control rate, or you need to process the whole audio block (instead of just taking the first sample).

Christof

On 24.10.2020 14:52, christof.ressi@xxxxxx wrote:

Hi,

can you post some actual code? It's hard to see what you're actually trying to do.

// output loop
for(int i=0; i<inNumSamples; i++){
    out = &result[i];
  }
Here you are consecutively assigning different *pointer* values to a single (pointer?) variable, which is a basically a no-op...

I'm trying to program a MultiOutUgen which is at the same time a sort of "MultiIn" Ugen.
That's quite common actually. You just have to be aware that signal buffers can alias each other, so you must read *all* inputs before writing to any output (at the same sample index). This means that depending on the actual code you might have to buffer the input.

However, the safest and easiest way is disable buffer aliasing alltogether by registering your UGen with the "kUnitDef_CantAliasInputsToOutputs" flag (e.g. by using the "DefineSimpleCantAliasUnit" macro).

Christof

On 23.10.2020 21:18, davigega@xxxxxxxxx wrote:
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