Help with algorithm for modulating oscillator pitch using LFO I am developing a software emulation of an analog synthesizer.  I am trying to modulate the pitch of an oscillator using an LFO.  For each sample fed to the computer's sound system, I am calculating the frequency to be input into the main oscillator like this (pseudocode):

osc_frequency = note_frequency * (1 + tuning) * (1 + lfo_y * lfo_mod_depth)


The variables in this statement are described as follows:


note_frequency = frequency of note to be played in Hz
tuning = oscillator fine-tuning in percent of played pitch (ex: -0.02 = detune by 2%)
lfo_y = current y value of lfo waveform (ranges from -1 to 1)
lfo_mod_depth = depth/intensity of effect to apply to oscillator in percent


However, this computation does not yield the desired result.  I expect to hear the pitch modulate up and down, locked around the center frequency (note being played).  What I am getting is a modulation effect that causes the pitch to "run away";  I can't tell exactly what is happening, but it sounds like one of these:


The modulation intensity increases over time (the high/low frequency mark reached by the modulation grows higher/lower the longer the note is held)
While the modulation intensity remains constant over time, the center frequency increases while the modulation oscillates around it


Am I using the correct approach or not?  If not, what should the correct approach be?  Any help with this is much appreciated.
As said by Jason, this might simply be that you are not implementing your oscillator correctly - for example by multiplying the frequency by time instead of integrating it.

Note also - and this is unrelated to your topic but really worth observing - that your formula for frequency modulation implements a behavior very different to that of most synthesizers, and will sound uncanny to a musician.

For example, if lfo_y oscillates between -1 and 1 ; lfo_mod_depth is 0.5 ; and if note_frequency is equal to 220 Hz, osc_frequency will sweep between 110 and 330 - that is to say between -1 octave and +1 fifth around the note. So the pitch modulation will appear to be centered in the hertz scale, but will not be centered in the perceptual musical scale.

The correct behaviour is to have something like:

osc_frequency = note_frequency * 2 ** (tuning / 1200.0 + lfo_y * lfo_mod_depth)


Then:


tuning is expressed in cents, a musically relevant unit (100
cents = 1 semitone).
your pitch modulation is "musically centered",
and lfo_mod_depth is expressed in octaves.


This is called "exponential FM", and this is the norm on synthesizers. On analog synthesizers, this is implemented by summing the LFO signal to the CV that hits the exponential converter of the VCO. On digital synthesizers, this is implemented by applying the modulations on a high-resolution internal representation of pitch which is still on a musical scale - before converting to a frequency or a phase increment.