Forums > Dev

msp object, variable number of signal outlets – methods to avoid a nested loop?

Mar 23 2013 | 1:45 pm

I making an MSP object that instantiates as many signals outlets as indicated by the user through an argument. So, I do not know how many signal vectors I am dealing with until after the object got creted.

Doing some tests with this I notice that my object eats a more processing power and causes MaxMSP to fail delivering the audio much faster (when duplicating the object successively with ~ >50 outlets) as compared to objects that have variable signal outlets (like gate~ for example).

Now, as far as I can understand, I need a loop to go through each signal vector (i.e. each outlet) and advance the pointer on every sample (e.g. *(out[i])++ = 0.0;)

Because I know that my object only two outlets maximum playing any signal at once, I managed to distill my nested while-loop to set all outlets on the current sample to 0.0 and change the two outlets in question to their respective values:

t_float **out = x->outlets; // with x->outlets = (t_float**) calloc(nOutlets, sizeof(t_float*)); on initialization!
t_float *p1, *p2;
long outs = x->l_outs; // total number of outlets in object

p1 = out[top_sample];
p2 = out[bottom_sample];

o = outs;
while (o–) {
*(out[o])++ = 0.0;

*p1 = value1;
*p2 = value2;

Now, this improved performance a bit, but it is still that case that I need less objects of my own object above to force MaxMSP into its knees than compared to out-of-the-box objects.

QUESTION: I am wondering if there is a way to remove the nested loop by advancing the pointers for each outlet without it? I am hoping to increase processing speed if there is a better way.

Also, does anyone have some advice how to tackle this problem of having multiple, variable number outlets?

The problem might also lie somewhere else. I also have four reading from a buffer~ for interpolating (linearly) the two output values. If someone suspects something, perhaps I can post other bits of the code. Cheers!

Viewing 1 post (of 1 total)

Forums > Dev