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.