Page 1 of 2
EDIT:SOLVED changing speed in a LFO without big mess
Posted: 06 Jan 2012 02:02
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
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!
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 07 Jan 2012 15:14
by lucasparis
up!
really any help would be appreciated!
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 15:21
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
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!
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 18:33
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
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 18:35
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.
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 18:36
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
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 19:10
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
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 19:22
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..
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 19:31
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! : )
Re: help DSPgurus! bad phase modulation changing speed in a
Posted: 08 Jan 2012 19:43
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