Types, conversion, bit shifting and friends


#1

When coding objects, the only part that I don't get is how numbers, types, values and stuff like that behave. Instead of the broad picture, let's taka an example (reading joystick from the axocontrol board):

outlet_joyy = adcvalues[0]<<15;

Then I attach a "disp/dial b" to the outlet from my object (outlet defined with type frac32.bipolar). The dial shows values from 0-64. Ok, I'd like to have it centered around 0, so first step:

outlet_joyy = (adcvalues[0]<<15) - 32;

Still goes from 0-64, what's the explanation and how to I make the outlet centered around 0?


Manually writing specific voltages to a raw file to be read as a table
Basic Table Help Request
#2

I guess you need it to be done at object level, right?

If you can do with using an object, try connect a conv/unipolar2bipolar after the gpio. This works.


#3

My main mission here is to understand and handle the object code. Generally I could use external conversion, but I want to understand the code...


#4

Ok, so this centers round 0, but why 2048?

outlet_joyy = (adcvalues[0]-2048)<<15;


#5

2048 = 2^11
I guess the adc does a 12 bit conversion with range [0,2^12], so if you want to make it bipolar you have to subtract 2^12 / 2 = 2^11 = 2048

2^27 in "axoloti units" corresponds to 64 , if you shift left something by 15 bits it's like multiplying that number by 2^15

You're multiplying a signal which goes from -2^11 to 2^11 by 2^15, so you get a signal which goes from -2^26 to 2^26. The range between these two values is 2^27 -> you have a bipolar signal with 2^27 peak-peak amplitude and centered in 0


#6

I think the main stumble block here is "axoloti units", what are they, and where can I read all about them?

The rest is clear to me...


#7

What i mean by axoloti units is the numbers you read on dials (-64 , 64)


#8

I know, but that's not the real number, at least not the one I'm performing calculations on in the object code. How, when and why is this "conversion" taking place?


#9

as far as i understood it does not actually take place in the code, but only in the ui. (the java code, that runs on the pc) -64 to 64 is a representation, that fits nicely with midi control, since all integer numbers are then correctly displayed in the ui. it comes from the nord modular.

please @johannes or @thetechnobear correct me if i'm wrong here!!


#10

I'm admittedly very new to axoloti, but I don't really see why it should be handy to present the user for another version of a value (or in fact another value all together) than the actual one. Clearly something I'm missing here...


#11

Because 0x07FFFFFF doesn't fit under dials very neatly :slight_smile:

Connect a disp/hex to a dial, hold Ctrl+Shift while you play with the dial, it should make sense why they are not used for UI purposes.