LFO sync to Ableton Live

Rasael's icon

Hi, I am trying to make an LFO that is synced to ableton live tempo.

In my approach I use a plugsync~ to phase modulate my generators. So with no magic I have a 1/4 sync out of the 4th outlet.
Now I want to be able to change my sync rate and since the value I receive is 0..1 that's tricky.

Currently I am using modulo approach:

1/4, 1;
1/8, 0.5;
1/16, 0.25;
etc..

Since the modulo will lower my values I will then multiply by the invert of the divider to get back a phase into range 0..1

So basically my phase is: ( [CurrentTicksInBeat] % [FloatDivider] ) * (1. / [FloatDivider])

As you can see, I can go deeper with the divider with "no problem" as I always get a valid result. Problem is that I want to also get the higher values, such as 2bar etc.

So I use an accumulator to do modulo over higher number too (only when divider > 1). This will lead to an overflow at a certain point (or go negative).
To avoid this I can manually reset the accumulator but im afraid this will lead into sync problems.

A simple and safe approach is to reset the accumulator when live transport goes off, this is easy enough and safe from errors.
But still can lead into overflow, therefore I wanted to reset the accumulator every 64bars.

To do so I need a second accumulator (or save bar count at transport start and continuously calculate the modulo), counting the beat count from plugsync~. This means [plugsync~ out3]->[==1]->[change]->[t b i]->[accum]. (it works as count is always equal to plugsync~ barcount if transport start from zero).

Now, the problem is:
1) I doubt the accumulator will give me integers values such as 1.0, 2.0.. :) Since the modulo works with floats i should be fine but this will lead into some errors too, probably perceivable after longer playbacks? I could try to round the value coming out of the accum, its ok as in that case I only need to do modulo over integer number but im afraid modulo will have a higher false-positive rate (Also since after the round I lose data I need to apply the rounded modulo to the unrounded data, just unhelpful complexity)

2) When the phase accumulator is reset im afraid I will lose one value from ableton. This is a problem as my modulo would be timeshifting of one sample, (this would be "perceivable" only when the divider is >1., otherwise I switch to non-accum for higher precision)

Any advice on the approach or how to solve those problems are welcome. I know I can use transport~ but I didn't manage to get the values in the 0..1 PPQ and im afraid of the metro timing, plugsync~ just does the job right.

I know there is M4L LFO device to inspect and learn from but its complex and this way its just "linear" to my mind :) I don't really understand the @lock and all that stuff in the LFO device..

double_UG's icon
Max Patch
Copy patch and select New From Clipboard in Max.

look at phasor~ help file. With @lock 1 phasor~ is alwas in sync with live.

double_UG's icon
Max Patch
Copy patch and select New From Clipboard in Max.
Rasael's icon

ahaha thank you for your reply ;) I checked out the reference instead of the help and @lock wasn't giving me a clue on what to do. Just by using it didn't work properly, now I just saw I can input maxtime tempo. thankss

Wonder why such an easy answer never came out in my searches.

Lol, in the meantime with some logic I realized that PPQ + BeatCount will give me 1bar resolution to sync to (just divide by 4). Therefore I created a bar counter that goes up to 64 bars by accumulating everytime the plugsync~ beatcount changes.. all for nothing now that I can lock :)

Christopher Dobrian's icon
Rasael's icon

Thank you for your answers. I had to take a break yesterday cause I had to abandon all the work I previously did for synchronizing to live without properly documenting how. at least was educative :-)

Today I didn't find the phasor help until when I realized there is a tab with multiple help examples, I've missed so many of those! :-(

However now im using @lock 1 and setting time with ticks works perfectly to me as I can have all the sync rates I'd like (even too many eheh).

Still have few questions:
1) I see in the m4l LFO device that there is a LFO retriggering circuit. Basically setting the phase to 0. This makes me wonder if I need such too or if @lock is enough. Maybe when live transport goes on I need to retrigger it?

2) My LFO circuit generates a signal where I need a number. Therefore I use a [snapshot~ 1 ticks]. This means the snapshot is in sync with ableton live transport right?