4-in 4-out MSP external problem (SDK 5.1.1)

May 19, 2010 at 10:15pm

4-in 4-out MSP external problem (SDK 5.1.1)

Hi, Forum,

I’m trying to write a dummy 4-in 4-out MSP external, and ran into some weird observations.

Basically I’m trying to open 4 signal inlets and outlets, add some gains to each incoming signal, and pass through inlet 1 signal to outlet 1, inlet 2 to outlet 2, and so on. After loaded, only outlet 1 gets audio and others are silent. I also tried letting inlet 1 talk to all 4 outlets, and it works. Just when having multiple input signals, things start acting funky.

Could you help take a look what’s wrong in this external? I have attached the file. Thanks a bunch!

Attachments:
  1. quadfoo~.c
#50462
May 20, 2010 at 4:00am

Hi there,

Both t_pxobject and t_pxbox contain a field called z_misc;
by default it is 0 meaning that all of the following settings are disabled:

#define Z_NO_INPLACE 1
#define Z_PUT_LAST 2
#define Z_PUT_FIRST 4

If you set the Z_NO_INPLACE bit in z_misc, the compiler will guarantee that all the signal vectors passed to your object will be unique. It is common that one or more of the output vectors your object will use in its perform method will be the same as one or more of its input vectors. Some objects are unable to handle this restriction; typically, this occurs when an object has pairs of inputs and outputs and writes an entire output on the basis of a single input before moving on to another input- output pair.

So in your specific case you have two options:

1 – Use the Z_NO_INPLACE flag, which you have to set in your new method
2- Change your perform loop to the following:

while (n--) {
    t_float sig1 = *in1++ * 0.1;
    t_float sig2 = *in2++ * 0.1;
    t_float sig3 = *in3++ * 0.1;
    t_float sig4 = *in4++ * 0.1;
    *out1++ = sig1;
    *out2++ = sig2;
    *out3++ = sig3;
    *out4++ = sig4;
}

Please, read the SDK docs and check out the MSP .h files. It is all in there…

Hope this helps you.

- Luigi

#181046
May 20, 2010 at 10:52am

I’d be interested to have confirmed changing your code as Luigi suggests works – If so this implies that any input may be the same as any output (not necessarily of the same index number) – this would be good to know for definite, as looking at your code I would have assumed it would work. Lugi’s code is definitely safer and should work – if it doesn’t then you have some other problem.

Cheers

Alex

#181047
May 20, 2010 at 4:27pm

I tried with the 2nd way to rewrite the perform loop, and it works!
Thanks a lot Luigi/Alex.

#181048
May 21, 2010 at 3:48pm

Yup — Luigi’s way is correct. Without the Z_NO_INPLACE flag, MSP will perform an optimization where it re-uses signal vectors as it sees fit. This includes re-using an input vector for an output vector in your perform routine.

Cheers

#181049

You must be logged in to reply to this topic.