frequency modulation in code

Please remember the terms of your membership agreement.

Moderators: valis, garyb

Post Reply
User avatar
kensuguro
Posts: 4434
Joined: Sun Jul 08, 2001 4:00 pm
Location: BPM 60 to somewhere around 150
Contact:

frequency modulation in code

Post by kensuguro »

hey, I'm writing some actionscript code to do a simple sine wave based animation, with an LFO modulating the wavelength. I thought it'd be better to ask here than a random "programming" board.

basically, I have a counter that is updates per frame, or whatever "tick" event. I use this as the phase.
curTick++;
if( curTick > cycle){
curTick = 0;
}
curPos = amp * sin( (initPhase + 2 * curTick / cycle) * PI) + offset

Is the basic equation I'm using. Pretty standard stuff I think. So now I modulate the cycle with another sin wave. Only problem is, that messes up the phase because when the LFO value is heading down, it triggers the if statement (curTick > cycle) prematurely.. Anyhow, something doesn't seem to be right about this if the cycle changes.

It would be easy if I used a non-looping counter and just did a modulo on it, but it seems dumb to count enfinitely.. is there a known way to get this done?
User avatar
valis
Posts: 7681
Joined: Sun Sep 23, 2001 4:00 pm
Location: West Coast USA
Contact:

Post by valis »

If you don't find illumination here, try #musicdsp on EFnet (use mirc, trillian or http://kief.net/irc/ and /join #musicdsp)
Post Reply