When the currentFrequency reaches 1/2 of the startFrequency, I notice that the sound wave flips (not sure what the correct term for this is). It doesn't seem like this is correct. Could someone help me understand what is going on.

Here is a screenshot of Audacity

For this image, startFrequency is 3380 Hz, endFrequency = 1380 Hz, duration is 0.512 s, and the amplitude is constant from start to finish. I have calculated that at 0.43264 s, the currentFrequency is exactly 1/2 of the startFrequency. In the picture you can see the "flip" happen at about 0.43 seconds.

2 Answers
2

Think of frequency in this context more in terms of angular velocity. If that velocity is constant, nothing changes from the usual picture. However, if the frequency changes, it is more correct to compute the actual angle that is input into the trig functions as an anti-derivative of the frequency function.

$\begingroup$Lutz hit it well. instantaneous frequency is the derivative of phase. the reason that the instantaneous (angular) frequency of $\cos(\omega t)$ is $\omega$ is because you take the argument of the sinusoid and <i>differentiate</i> it, <b>not</b> divide it by $t$. it's a common mistake, even done by university professors publishing papers. (i have, more than a decade ago, corrected a published paper in the Journal of the AES regarding this.)$\endgroup$
– robert bristow-johnsonJan 2 '14 at 21:41

$\begingroup$Note that for the general case (a different frequency transition curve for example), it is easier to use a phase accumulator as explained in this answer: dsp.stackexchange.com/questions/971/…$\endgroup$
– pichenettesJan 4 '14 at 0:42

$\begingroup$This sounds like numerical integration with the Euler method, $\phi(t+h)=\phi(t)+2\pi f(t)h$ for $0\le h\le \Delta t$. If I understand the options, one can use a fixed $\Delta t$ or adjust for $f(t)\Delta t$ to be an integer?$\endgroup$
– LutzLJan 4 '14 at 7:21

$\begingroup$If you zoom in, the graph is much smoother. It makes a nice non-distorted sound, but I believe I need to implement the formula LutzL posted for it to be correct.$\endgroup$
– NeilMondayJan 2 '14 at 16:31