Hello Math Nerds!
I am trying to write a bit of code in Lua to will help me achieve a certain type of curve (see below - ‘Constant Power’). I purchased some Grid controllers and I am wanting to setup one of the faders to do an constant power (equal power) crossfade between two values. Grid uses Lua for programming. Using some functions that the developer created, I can easily do a linear crossfade between two values with a simple bit of code. My next step is to do a constant power crossfade.
I’m stuck though I don’t know how to express growth or decay to represent the constant power curve below. I only to work it out for one direction as I can invert the results to produce the other curve (at least I think I can):
My problem is that I only ‘technically’ have a Grade 9 education. I never got to algebra. I understand what I want to do but I don’t know how to frame my questions as a Google search so I can try and find the answers myself.
Could anyone assist with this? I would need to know a formula to express the growth and decay of those curves. The range for this particular element would be 0-127. I could make the adjustments for 14-bit controllers if I needed to. I just need some help with the math bits.
This doesn’t need to be Lua-specific either. It just so happens that I am working in Lua.
Big, big thanks in advance!
Edit: I’m also not a programmer. I’ve done some basic Python, PHP, Perl, BASH tutorials so I know some very basic fundamentals. However, if some of my replies seem a little…obtuse, it’s because I don’t have a programming or mathematics background.
The code (copied from Grid editor):
local num, min, max, v1, v2 = self:element_index(), self:potmeter_min(0), self:potmeter_max(127), self:potmeter_value(), self:potmeter_max() - self:potmeter_value()
local val_1, val_2 = v1 code for curve, v2 code for inverse <= code bits that I want to manipulate v1 and v2 to output growth/decay at a specific rate and assign to val_1 and val_2 to be transmitted with the midi() function
midi_send(11, 176, 74, val_1)
midi_send(11, 176, 73, val_2)
With that one line of code, it works perfectly as a linear crossfade. But linear does me no good for ‘transition trick’ style crossfades. Hence the need to figure out how to do those curves.
The second ‘local’ declaration is because I can’t reference variables that I am, at the same time, declaring. I’ve tested this. I need the second declaration to manipulate the variables in the first declaration. Just explaining the logic.