formula - logic gates ?

I am trying to implement logic gates, like : y = A and B, y = A or B etc.

It does not work, can we have logic gates please (this would obviously work only with square waves) ?

I know that I could encode this using volume instead, and have decoders, but having straight logic operators would be amazing.

Can we have logic gates please?

I do not understand what you are trying to achieve. You mean a volume gate - the formula device is just a meta device, and you are supposed to code your logic & link it to a gainer or gate device to modify sound volume (and gate the volume)? Or are you just after programming techniques to use “gate logics” in your custom formula code?

The formula tool lacks any library other than math, also the bit operations that rns lua tools can use, but has “the full basic lua” inside otherwise. There are always ways to translate logical operations to floating point and/or boolean/conditional operations. If you give a concrete (please not too complex) example of what you wish one or a few formula devices in interaction should do - I might demonstate such techniques to you.

Sorry for not being clear - I proposed that let say your A is clock (from lfo spitting out a square wave) and B is your clock, both with different period, you want your output to be high if and only if if both of them are high .

It seems that such thing is not possible now

Mind you I do not know Lua language and I am complete noob when it comes to DSP, but I do know VHDL - but that is a bit different, the manual is rather not helpful when describing this meta device and it seems that basic AND, NOT, OR

operators are not available.

What I have said that you could have A at 25% of max possible gain and B at 25% of gain, and just assume that 50% of gain is equal to a logic 1 - same effect but rather not robust.

So I would be grateful to know how one would realize an AND gate and a NOT gate using the formula meta device ? So :

1)A and B gives 1 on the output only when both A and B are high

  1. NOT would be inverting whatever is being fed let say on input A

So the output signal Y would be then used to switch stuff on or off in the project.

Any help will be much appreciated - still time to read ona Lua I guess.

edit: ok I am being silly: 1st would be done A*B and 2nd (-1)*A

This topic can be deleted, thanks anyway :]

Hi!

Good you found your first solutions yourself!

Yes, lua has no bitops (which include gate/binary operations), only values (floating point) or bools (which can do logics as well, and maybe even be converted, but…hehe). As I said, the renoise tool interface has bitops, but formula device not, well, one can code simple gates oneself with float or bools.

I’ve coded some building blocks for you in the float way, as I think it fits the input/output format best. You can just put them into the user field to use the functions in there or in the formula field.

Click to view contents

–[[ uncomment if using in lua environment for tests, and not in formula device
local floor = math.floor
local ceil = math.ceil
local abs = math.abs
–]]

– discretize value x range 0.0…1.0 - make it either 0.0 or 1.0 if it is above thres
function gdisc(x, thres)
thres = thres or 0.5
return floor(x+1.0-thres)
end

–these functions only work with either 0.0 or 1.0 as input(s), use disc() first
– x AND y
function gand(x,y)
return x*y
end

– x OR y
function gor(x,y)
return ceil((x+y)*0.5)
end

– NOT x
function gnot(x)
return 1.0 - x
end

– x XOR y
function gxor(x,y)
– return (x+y) - floor((x+y)*0.5)*2.0 – LOL I shouldn’t do this at night

return abs(x-y)
end

all the functions should be self explaining, and with exception of the first they need each input value be exactly either 1.0 or 0.0 to work correctly. this is why the first function “gdisc()” is there, you can make a value between 0.0 and 1.0 be exactly either of them, depending on it being above or below the second parameter, if you give only one parameter this threshold is considered to be 0.5. It is useful for doing these logics with input from stuff like the signal follower. sorry for the “g” in front of these functions, but “and”, “not” and “or” are reserved names I think.

The results will be either 0.0 or 1.0, too (if not abused…), so you can happily multiply other values with them to make them jump between whatever they are and zero.

For example you could do a “formula” with this like “gnot( gxor( gdisc(A), gdisc( B) ) )” which will be “NOT ( A XOR B )”, and you can leave out the “gdisc” commands if you use LFOs in point mode with only exactly 0.0 or 1.0 value points.

Have fun, I only tested this vaguely…

EDIT: I replaced the messy XOR function with something more straightforward

You say ‘this would obviously work only with square waves’, which makes me think you are talking about getting digital output from analog logic. What is the difference between analog logic and min/max function in the formula device? I am only asking, not suggesting a solution.

Sorry I was away.

Thanks a lot for your input OopsFly, much appreciated!

@oneunkind : I am wrong, my bad, it could work with any wave.

Conceptually you could do logic with min/max or with any other function - depends how you encode/decode your information - this is arbitrary. The question is how much you have to fiddle with it to get the result you want.

So with Min/Max you get the minimum or maximum output - these are comparators and one output is being chosen accordingly for the output.

What I was after is to send a high signal when 2 or 3 inputs are high at the same time, and leave the output 0 in any other case.

So with eg. Max, you would just get the copy of the max signal, ignoring what has happened to the other two - a false logic 1 - but again you could be creative and encode it in some way.