I'm generating a sine wave and I want the second half of the signal to be in a different frequency. How do I find the phase shift I can apply to the second half so that the joining between the halves at a certain point in time is smooth?
More specifically, I'm generating sound and want to avoid the clicking sound when frequency changes.
Desired result joins smoothly (please ignore the poor image editing):

time:
t0 t1
The result I currently has a gap at t1:

And that happens because the 2nd part of the wave, when generated with the same phase (see it starts at 0° at t0), had a different Y axis value at t1:

If you look back at the 1st image, the 2nd part had to be shifted a bit to the left (i.e. it's phase starts at something > 0°) in order to smoothly connect with the 1st part (i.e. to have the same Y axis value at the time of frequency change)

