I still think my earlier suggestion is ~~the best one~~ worth not forgetting.

If you want the solution to be completely exact, you need somebody who is good in calculus. Otherwise you’re just stabbing randomly in the dark, and you will not accidentally find the solution that way.

Schottstaedt states “… there is no essential difference between frequency and phase modulation.”

Yes, because phase is the integral of frequency (and frequency is the derivative of phase). In classic FM, when you adding a sinusoid to a constant frequency, then the phase is the integral of these two terms.

- a = integral of constant frequency = f * t – a line (ramp).
- b = integral of sinusoid = phase-shifted sinusoid. (Integral of cosine = sine.)
- FM’ed phase = a + b

And you can go the other way (PM synthesis). If you start with a linear ramp for phase, and add a sinusoid, the effect on frequency is:

- a = derivative of linear ramp = constant frequency.
- b = derivative of sinusoid = phase-shifted sinusoid.
- Add those together, and it’s FM.

The catch is – and what often happens in FM – is that the modulator might have its own DC offset. (This happens easily, say, in a three-operator chain: A → B → C. A → B is likely to have DC offset.) Then the frequency is a (constant frequency) + b (modulator without DC offset) + c (modulator’s DC offset, constant value) = sum of two constant values (shifts the whole frequency!) + modulator b = *not* the frequency you started with.

In this case, you might think everything is keying off the same basic frequency, but you don’t get the nice clean tone color.

But PM, in the same situation, doesn’t have this effect, because the DC offset in the modulator only phase-shifts the wave in time, but does *not* skew frequency. This is why (I think) most FM synthesizers are really PM synthesizers.

@dietcv, your `fmod`

*does* have a negative DC offset, skewing frequency downward. This might be the reason why it isn’t getting all the way back to 0 by the end of the grain. If I’m right, then your FM approach would have to control for DC offset. (If you’re not sure how to do that… again… take a mathematician out for a beer – or accept that PM handles DC offset better than FM and just use PM.)

hjh