So I've been playing around a bit with music synthesizing and I've got a fundamental issue I'd like to get feedback on.
Assume we're only working with sine waves. To generate music all we do is add up a bunch of sines evaluated at the current playtime, so far so good. Now comes the problem, I'd like to be able to gradually change the pitch of a wave. Just lerping between the pitches will cause artifacts during the entirety of the lerp. Example 440hz to 660hz one second in is 220 periods apart. Lerping during one sec will then temporarily increase the pitch 220hz to 440hz during the lerp. At later playtimes this will number will be bigger and all we'll hear is clicking.
One obvious solution, is that we'll just save down a current phase and then add an appropriate amount at each sample. Which works just fine if we've got just one wave. However we get a problem when we're generating harmonics, especially with distances of one octave. for example 440hz & 880hz. The thing is, if we're adding a bit of phase shift each sample we quickly get errors that accumulate. And so the frequency won't really be 440 and 880 but say 438 and 883 at which point we get really noticeable tremolo effects.
I'd like to be able to play harmonics while changing the pitch so we can't just swap between the two.
Does anybody have any good ideas or know how this is usually done?