EDIT:SOLVED changing speed in a LFO without big mess

Discuss Lemur and share techniques.
lucasparis
Newbie
Posts: 30
Joined: 23 Dec 2011 20:15

EDIT:SOLVED changing speed in a LFO without big mess

Post by lucasparis »

wow long title!

So here's something that's annoying and I think I've also noticed in the past with the eso wave template.

I'm building an LFO with the lemur's time variable, and I want to change the speed of the LFO with a slider.
But as I'm changing the speed the signalscope representing my lfo goes crazy.
here's the expression for the LFO

Code: Select all

sin(time*speed.x)*0.5+0.5
same basic example than in the manual

I believe this is a dsp problem, it reminds me of what happens to a wave with phase modulation. I need to put some math in there to smoothly change the period of the lfo without affecting the phase. I'll try digging deeper but If a DSP guru is around any hints would be great thanks!
Last edited by lucasparis on 08 Jan 2012 20:36, edited 1 time in total.
lucasparis
Newbie
Posts: 30
Joined: 23 Dec 2011 20:15

Re: help DSPgurus! bad phase modulation changing speed in a

Post by lucasparis »

up!
really any help would be appreciated!
analog604
Regular
Posts: 262
Joined: 29 Dec 2011 15:40
Location: north east, usa

Re: help DSPgurus! bad phase modulation changing speed in a

Post by analog604 »

same thing happens in the LFOs that I am developing! arrrrggg.
So I'm also interested in the answer to this..
The current time used in the computation will need to be altered in the correct amount of the last frequency/amount change with the new or current frequency (make some global variables to track change).
I don't know how to calculate this, but I've been trying to find some LFO C code around that
might help reveal the ratio.
So far I've found ZynAddSubFX's LFO.cpp and am attempting to derive the right balance in Lemur.

-J
lucasparis wrote:wow long title!

So here's something that's annoying and I think I've also noticed in the past with the eso wave template.

I'm building an LFO with the lemur's time variable, and I want to change the speed of the LFO with a slider.
But as I'm changing the speed the signalscope representing my lfo goes crazy.
here's the expression for the LFO

Code: Select all

sin(time*speed.x)*0.5+0.5
same basic example than in the manual

I believe this is a dsp problem, it reminds me of what happens to a wave with phase modulation. I need to put some math in there to smoothly change the period of the lfo without affecting the phase. I'll try digging deeper but If a DSP guru is around any hints would be great thanks!
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
lucasparis
Newbie
Posts: 30
Joined: 23 Dec 2011 20:15

Re: help DSPgurus! bad phase modulation changing speed in a

Post by lucasparis »

Hey nice to see I'm not the only one that has a problem with this! You actually gave me an idea
The current time used in the computation will need to be altered in the correct amount of the last frequency/amount change with the new or current frequency (make some global variables to track change).
I've been hard at work experimenting on this for about an hour and I believe I found a solution. Let me implement it neatly to see if it works and I should be posting it in a hour or so. I hope I got this right, fingers crossed
analog604
Regular
Posts: 262
Joined: 29 Dec 2011 15:40
Location: north east, usa

Re: help DSPgurus! bad phase modulation changing speed in a

Post by analog604 »

After thinking about this some more, I came up with two novice solutions which may be incorrect. : )

1) Ignore. The scope getting wacked out for a fraction of a second may not matter at all when the next value is
sent to the ultimate destination of the LFO. We're not using the LFO as a sound oscillator.
The scopes are slow to update smoothy from what I've seen so far.

2) Scripting. Calculate the tangent between old LFO freq and proposed new.
Where will the current LFO frequency intersect with the new frequency in time?
Put that value in a var along with a var indicating there is a pending frequency change.
Continue to calculate and display the LFO until the tangent point occurs or approximately occurs in time, plot that point and then begin plotting the new frequency thereafter.

3) We calculate a zero crossing tangent, or max LFO precision (127 for midi) tangent and use that as the next start point.. again waiting with current frequency plotting until that point in time occurs in order to begin the new frequency.

I've been attempting the second one for several hours today, but my scope is dead flat so I am now debugging my code logic.
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
analog604
Regular
Posts: 262
Joined: 29 Dec 2011 15:40
Location: north east, usa

Re: help DSPgurus! bad phase modulation changing speed in a

Post by analog604 »

Nice man! We were typing replies at the same time.
lucasparis wrote:Hey nice to see I'm not the only one that has a problem with this! You actually gave me an idea
The current time used in the computation will need to be altered in the correct amount of the last frequency/amount change with the new or current frequency (make some global variables to track change).
I've been hard at work experimenting on this for about an hour and I believe I found a solution. Let me implement it neatly to see if it works and I should be posting it in a hour or so. I hope I got this right, fingers crossed
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
lucasparis
Newbie
Posts: 30
Joined: 23 Dec 2011 20:15

Re: help DSPgurus! bad phase modulation changing speed in a

Post by lucasparis »

Hey there are some good ideas there, food for thought.

So I've tried putting it together with my technique and it's still not working correctly need to tweak it some more.

Here's the aproach I'm attempting:
I start with the equation for a sin wave which is y=sin(2*pi*frequency*time-startphase)
I'm constantly calculating the time since the frequency fader was last changed and also calculating the current phase of the lfo

every time the fader moves I run a script that resets the time back to zero and sets the startphase with the phase that was being calculated. that's the main concept.

here are some things that might help you
to create a pi variable pi=2*asin(1)
currentphase=((timer*lfospeed.x)%1)*360*(pi/180)
timer=time%lasttime
lastime is updated with the current time in a script when the fader moves

Here's where i'm at, I need to update current phase when tempo slider moves.



Let's do this man we'll get them :D
Attachments
neetlfo.jzml.zip
(1.09 KiB) Downloaded 140 times
analog604
Regular
Posts: 262
Joined: 29 Dec 2011 15:40
Location: north east, usa

Re: help DSPgurus! bad phase modulation changing speed in a

Post by analog604 »

Cool thanks for the ideas and formulas. I had been using pi=3.14159 in globals, saves the computing cycles for other Lemur goodness. : )

Checking out your jzml..
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
analog604
Regular
Posts: 262
Joined: 29 Dec 2011 15:40
Location: north east, usa

Re: help DSPgurus! bad phase modulation changing speed in a

Post by analog604 »

Yes that is much closer than I've got it yet. Nice work on phasemonitor

Here's an idea that I was also working out that may help here because what I'm seeing is the scope bug out
while the fader moves but everything is good thereafter when it resets the val and timerlast.

So how about the use of a settle time technique.
In the LFO code, save the last freq.
When the freq is different from last, start a timer that waits for 1/2 to 1 second and note the new freq in var, but
don't plot it. Continue.
Once the fader stops moving for settletime, then take the latest change as new freq var and use it.

This shouldn't take long now! : )
Last edited by analog604 on 08 Jan 2012 20:09, edited 1 time in total.
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
lucasparis
Newbie
Posts: 30
Joined: 23 Dec 2011 20:15

Re: help DSPgurus! bad phase modulation changing speed in a

Post by lucasparis »

Good idea, I think i was also thinking about the same thing, great minds think alike right ^^:
I put the script of the fader that updates everything on expression z going down, that way all gets updated when you release the fader
Post Reply