Creating an Debounce Object + global variables


#1

Hey there,
i am trying to write a debounce object similar to debouncing button input on a microcontroller .
My starting point is the object logic/change speedlim
This is its code
<![CDATA[
if ((pval != inlet_in)&(!ptrig)) {
outlet_trig = 1;
pval = inlet_in;
ptrig = 1 << 27;
} else {
if (ptrig>0) {
ptrig -= param_d >> 7;
} else ptrig = 0;

        outlet_trig = 0;
    }
]]>

Can someone explain what these bitshift operations have to do with a time interval? (param_d is the control knob on the objects gui and it sets a time)

My aim is to write something like this.
- the first time the boolean input goes to 1 the output goes to 1 and stays on until the input was off a certain time intervall. so that a flickering input doenst interrupt the on state at the output.

In Addition to that im wondering if there is a possiblity to use global variables to store settings for the patch.
Is there anything like the f object in pd?

regards,
Flub


#2

Where can i read the defintion of what fixed point types are used considering the position of the fractional point and negative numbers?


#3

I think "timer/pulselength" is closer to what you need.

fractional : -0x08000000 to 0x07FFFFFF corresponds to -64.0 .. 64.0
disp/hex allows you to peek at the native value.

You mean like the "v" object in pd? ("f" is not a global)
No, there is nothing for global variable storage yet. Perhaps a table?


#4

thanks, then this means ptrig = -64 in decimal numbers.
and what does this mean? what kind of value is param_d ?
ptrig -= param_d >> 7;


#5

ptrig is a downwards counter, starting at 1<It is decremented by param_d at control rate (3kHz) until it reaches zero.
Param_d uses a parameter function (frac32.u.map.klineartime.reverse) that converts the parameter scaling from the (exponential) time scaling to the corresponding amount to decrement.