Math - Changing the frequency of a sine wave in real-time

I need an algorithm that can output a sine wave of varying frequency, with this frequency being changed dynamically. I started with this:

		public void Update()
		{
			time += Time.deltaTime;
			float sine = Mathf.Sin(time * frequency);
		}

The problem occurs when the frequency is changed. Normally as the time variable increases, the sine wave is advanced by that amount, and multiplied by the frequency variable. But when the frequency is reduced while the sine wave is being generated, the wave is temporarily “brought back in time” because the time variable is being multiplied by a smaller number.

So is there an algorithm that can change the frequency of a sine wave in real-time?

I made an assumption on how you were going to use this function, but as I read, there is no specification. So here is a bit of code that demonstrates how you can modify the phase to keep the sine in-sync. Create an game object at the origin and attach the following script. While the script is running, change the frequency in the inspector. The game object will move back and forth. When the frequency is changed, the game object will not jump.

using UnityEngine;
using System.Collections;

public class SinePhase : MonoBehaviour {
	
	public float amplitude = 2.0f;
	public float frequency = 0.5f;
	private float _frequency;
	private float phase = 0.0f;
	private Transform trans;

	void Start () {
		_frequency = frequency;	
		trans = transform;
	}
	
	void Update () {
		if (frequency != _frequency) 
			CalcNewFreq();
		
		Vector3 v3 = trans.position;
		v3.x = Mathf.Sin (Time.time * _frequency + phase) * amplitude;
		trans.position = v3;
	}
	
	void CalcNewFreq() {
		float curr = (Time.time * _frequency + phase) % (2.0f * Mathf.PI);
		float next = (Time.time * frequency) % (2.0f * Mathf.PI);
		phase = curr - next;
		_frequency = frequency;
	}
}