### Phase Generator

Posted:

**Wed Aug 03, 2011 11:05 am**I had an algorithm in mind for the basic phase generator. This is the part which takes the F-NUM and the BLOCK values and somehow generates the correct frequency waveform. It basically needs to cycle through a 10-bit output that feeds into the wave lookup table. The cycle is modified by the Feedback, the FM synthesis and the vibrator LFO, but leaving those modifiers aside, it simply has to cycle from 0 - 1023 at the correct rate.

I had a simple algorithm in mind, that simply adds the F-NUM value into a 20-bit counter, and the uses the BLOCK value to shift a 10-bit window in that counter to output. But it then occured to me that there was an alternative algorithm, wherein the 10-bit window is fixed and the F-NUM value is shifted before it is added to the counter. I wasn't sure which was correct. If the F-NUM and BLOCK values are fixed, then the results of the two algorithms are identical. But I realised that if the BLOCK value changes during the lifetime of a note, then there are subtle differences.

I experimented last night, and discovered that the second algorithm is correct. Which should have been obvious from the start, the first algorithm can result in step-changes to the phase when the BLOCK changes, and this would add noise to the signal. The second algorithm avoids this problem altogether.

Here is an example using the first, moveable window algorithm. We start with certain values for F-NUM and BLOCK. F-NUM is added to the counter each sample and then after a certain number of samples we change the value of BLOCK. The resulting output for the wave phase is given in the right-hand column

In the second algorith, the window is fixed, and when the BLOCK value changes, we use it to shift the value of F-NUM which is added to the counter.

I had a simple algorithm in mind, that simply adds the F-NUM value into a 20-bit counter, and the uses the BLOCK value to shift a 10-bit window in that counter to output. But it then occured to me that there was an alternative algorithm, wherein the 10-bit window is fixed and the F-NUM value is shifted before it is added to the counter. I wasn't sure which was correct. If the F-NUM and BLOCK values are fixed, then the results of the two algorithms are identical. But I realised that if the BLOCK value changes during the lifetime of a note, then there are subtle differences.

I experimented last night, and discovered that the second algorithm is correct. Which should have been obvious from the start, the first algorithm can result in step-changes to the phase when the BLOCK changes, and this would add noise to the signal. The second algorithm avoids this problem altogether.

Here is an example using the first, moveable window algorithm. We start with certain values for F-NUM and BLOCK. F-NUM is added to the counter each sample and then after a certain number of samples we change the value of BLOCK. The resulting output for the wave phase is given in the right-hand column

In the second algorith, the window is fixed, and when the BLOCK value changes, we use it to shift the value of F-NUM which is added to the counter.