Generating LFOs with lua + trigonometry

Hey y’all. Trying to build a script that’s kinda an advanced take on the “send an LFO to a quantizer” modular land technique.

Was recommended to use a clock structure (like lattice) to increment values and then poll them when needed. Looking for variable control of ratio between “attack” and “decay” (like a looping envelope), unipolar.

I’ve done a fair deal of trigonometry in another life, but it was never really with reference to the physical objects — they were just kinda algebraic annoyances on calculus exams. Not really clear what the lua trig functions are doing, or how doing different kinds of math to them would impact the resulting shapes (or even how to get something simple going so I can poke it with a stick and figure all this out).

1 Like

Do you mean like a function generator?

You can do a lot of interesting stuff w/ trig when it comes to periodic functions. Shifting phase, modifying amplitude, taking derivatives, funky triangle stuff, etc.

But why exactly are you thinking of using trig here?

Apart from implementation recommendations, what is the design you want? Clarifying that in plainspeak can have a way of making the other stuff fall into place.

An aside: I was reading a very catty history of mathematics from the '40’s in which the author praised the Ancient Greeks for contributing the concept of proof to the discipline, by way of geometry.

In contrast, he denigrated the Egyptians as nothing more than “rope stetchers,” referring to their use of rope triangles and ratios when building. His criticism was that they were aware of the applications, but had contributed nothing to understanding geometry more deeply, and nothing notable to mathematics at large.

The writer had his dander all up in a lather about it. I thought that was kind of hilarious.

But also…cautionary tale! :stuck_out_tongue:

show me to the greek pyramids :stuck_out_tongue:

actually was reading geometry of musical rhythm last night and learned about the rope thing for the first time (12 equally spaced knots etc) apparently there were just manuals with the stamp of the pharaoh and everyone went along with it…

I want to create functions and then periodically poll their value (in time with a gate sequence) to generate pitches. Pretty sure I understand how to like… increment in radians at a variable rate, take math.sin, make the value useful… but not sure how to get different relationships between the rise and fall of the LFO… vary the incrementation of the radians based on their current value? like

if [radians] <= 3.14 then
[radians] = [radians] + .01
[radians] = [radians] + .02

and then that gives me a function with a rise twice as long as its fall?

1 Like

this sounds like a really fun project. few thoughts that come to mind:

  1. questions of resolution. how low-res can one go and still tell me, in good faith, it is a sine?
  2. questions of identity. consider the signature of the sine, when placed next to a triangle. at a sufficiently low resolution, say 3 per cycle, these will be identical: peak, zero, valley.
  3. questions of minimalism. how few waves and how low-res can one get away with?
  4. questions of use. is this a standalone instrument? an academic exercise? a component of a larger contraption?
  5. questions of “work.” these values will be quantized. a sine signature could be calculated and stored ahead of time. maybe a table of 20 values is good enough? maybe 10 is good enough? or maybe the value needs to be generated and sampled in real time.
  1. Could defo go triangle — would probably be easier to get variable relationship between rise and fall this way (which is Very Important For The Mission).
  2. see 1
  3. I think four waves total — two waves ANDed together, two more ANDed together, and then those results ORed together.
  4. I’m building three/four small sequencers that will all live together, each designed to give a very different type of output and play well as a team. This is the soloist.
  5. The primary interface will be faders controlling the wave rates, shapes (fall/rise ratio), attenuation — so real-time is the move.

Wait — can’t I just set up a clock that switches between two operations whenever it his its max or min value? So clock says “every tick, add x to this value until you hit y summit, then subtract z from this value, until you hit r trough.” And then sample that? Like… that’s a data-domain LFO and I get full control over the resolution, right?

1 Like

Triangle LFOs are definitely easier to generate than sine waves, and I would argue that you can barely tell the different in most applications. You should probably go with generating a triangle if you can get away with it.

That said, if you are interested in creating a sine LFO, I wrote up a method for doing so in Teletype without using any trigonometric functions that you might be able to adapt. Hopefully that post is mostly self-contained by way of explanation: Teletype haiku - #119 by mreid

1 Like

that sounds like a great way to approach it. make a spike!

1 Like
function pseudo_lfo()
  if are_we_descending == 0 and where_we_are_now + increment_the_rise_by >= 1760 then
    are_we_descending = 1
  if are_we_descending == 1 and where_we_are_now - increment_the_fall_by < 0 then
    are_we_descending = 0
  if are_we_descending == 0 then
    where_we_are_now = where_we_are_now + increment_the_rise_by
  if are_we_descending == 1 then
    where_we_are_now = where_we_are_now - increment_the_fall_by


<3 <3 <3