Help with shift function in an object


#1

Hey :wink:

I am working on an object that I am having a few issues with a shift function on an amount knob in a bipolar to unipolar converted signal.

Goal is: a bipolar to unipolar converter with switch for biploar/unipolar signal & with an amount knob and on/off switch.

I got most of it working but I am having a hard time getting the amount knob working in the unipolar signal chain. I tried shifting the amount knob with <<4 but that only set the range of half of what it should. When the it should be 31.54 the value is 15.77, like on the picture. So I tried <<5 but that doesnt work at all.

Dunno where to go from here......

Could a helpful soul point me in the direction of a solution for this problem?

See patch&picture:
BI2UNIAMOO for com.axp (5.3 KB)

Thanks!


#2

shift the left side of the_SMMUL by 1


#3

Ha!

Thank you @Sputnki :wink:

This worked:
outlet_o= __SMMUL(((inleti>>1)+(1<<26)<<1),param_am<<4);

WIll put it in com lib soon.


#4

Hey @Sputnki

I am wondering if you would mind giving another advice on the object?

I am still working on the object and got most of it woriking now. Next thing is to add an invert function. I am having a bit of problems with that. I can patch it with factory objects, buthaving a few issues with coding it. I need to explain a little bit first:

Basicly the object has got 3 functions:

0 = Clean mode:
The input it not converted.
Unipolar input = unipolar output.
Bipolar input = Bipolar output.
Amount knob sets how much of the signal is let through.

1 = Unipolar to bipolar mode:
The input will be converted from unipolar to bipolar.
Amount knob sets how much of the signal is let through.

2 = Bipolar to unipolar mode:
The input will be converted from bipolar to unipolar.
Amount knob sets how much of the signal is let through

And now I'd like to add an invert function for all 3. The first one "clean" I got working. The second, unipolar to bipolar, I can patch with factory objects like this:

.... Basicly just a 64+ offset, added to the inverted signal. But when I do this in the object, it doesnt give the same result. I know it is wrong, the way I do it, but I just dont understand how to get it right. I added the +64 to TRY to do the same as the picture above

outlet_o= __SMMUL(-inleti+64<<1,param_Am<<4);

But it outputs a pretty random number. I cant really figure out how much it is offset wrongly. Usually you can see it pretty easily, but I cant figure this out.

First I need to get this right and then go on to the final one bipolar to unipolar.

Any suggestion on how I can get it right appreciated :wink:

Thanks


#5

fractional 64 corresponds to integer 2^27 (1<<27)
As for the bipolar2unipolar: remember that it's not just an offset, but also a scaling (input must be divided by 2 and then added to fractional 32, which is integer 2^26 (1<<26) )


#6

ahh yes, ups I pasted the wrong code into the object.

This is the original code, converting from unipolar to bipolar, NO invert, WORKS:

outlet_o= __SMMUL(((inleti-(1<<26))<<2),param_Am<<4);

This is my edited version with invert:

outlet_o= __SMMUL(((-inleti-(1<<26))<<2),param_Am<<4);

Only added a - before inlet.. I tried to change to 1<<27, but that didnt work... Could you give a specific suggestion?

Thanks :wink:


#7

Hmmm, i think you should put the - sign before the__SMMUL function, not before the inleti variable.

I'd reccomend you to reason on the math you're doing before putting your hands into the code.
As you surely will recognize - (a+b)c it's not equal to (-a +b)c


#8

Yes you are right, I probably should. But the code I have used, is taken from factory objects, so it should be okay. I took from from bipolar to unipolar object and from unipolar to bipolar object and then looked in the ivert object to find out how to add invert. Anyhow, I'll leave it for a bit and get back to it.

Thanks again!


#9

Yeah, if you take the code from existing objects it will probably be alright. However you'll have to adapt it to your needs. You can do this only if you comprehend what the object does, otherwise it's better to start coding from 0.
Since you're dealing with simple math, i think it's more instructive to do the latter.


#10

As mentioned unipolar to bipolar works and bipolar to unipolar both works, so that is not the issue. Those works perfectly and the offset is 26 not 27. I got this part down perfectly.

But when I try to add the invert function, which I can easily do with factory objects it doesnt work. I guess this is the part that needs to be adapted.

Yeah, I know some of the code but not all. Still very much a beginner.

Anyway, I gave up for now.

Thanks