Page 1 of 1

frequency modulation in code

Posted: Fri Jun 08, 2007 6:57 am
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?

Posted: Fri Jun 08, 2007 8:43 am
by valis
If you don't find illumination here, try #musicdsp on EFnet (use mirc, trillian or http://kief.net/irc/ and /join #musicdsp)