I'm attempting to implement an FM synthesis operator with feedback using a phase accumulator in C. In Tomisawa's original patent, the phase accumulator going into the adder counts over both negative and positive indices, from -2^(n-1} at a sine wave phase of -pi to 2^(n-1) at a phase of pi. For simplicity's sake, I'd like to use a phase accumulator that counts only over positive values, using the top bytes of an unsinged 32 bit integer as an index into a sine table lookup.
I have experimented with this and unfortunately I can't seem to get the algorithm to produce the expected results when using feedback. Adding the sine wave output to the phase accumulator should produce a sawtooth like waveform, but I can't figure out how to properly add the output sine wave (which is a 16 bit signed int) to the unsigned phase accumulator to produce this. Any suggestions would be appreciated.
Edit:
Some clarification is probably in order. Here are some diagrams from Tomisawa's original patent:
When both the phase accumulator and the sine wave output are signed, the algorithm is straightforward enough to implement. The phase accumulator starts at -1 and runs to 1, and the sine wave output is also between -1 and 1. In Python, the algorithm looks sort of like this to generate 1000 samples:
table = []
feedback = 0.25
accumulator = -1
for i in xrange(1000):
output = math.sin(math.pi*(accumulator + feedback*output)
table[i] = output
accumulator += 0.005
if accumulator > 1:
accumulator = -1
Which produces an ouput that looks as follows:
I am trying to adapt this algorithm to C. In C, for purposes of computational efficiency, I would like the phase accumulator to be a 32 bit unsigned integer rather than a signed integer. That way, I can use the first two bits of the high byte of the accumulator as a quadrant index, and the second high byte as an index into an array of 256 16 bit sine values, for a 1024 value sine table. Like:
XXXXXXQQ.IIIIIIII.XXXXXXXX.XXXXXXXX
^^ ^^^^^^^^
quadrant index
My problem is that I am having difficulty adapting the FM algorithm as given to an unsigned phase accumulator. If the phase accumulator is an unsigned 32 bit int, and the sine wave table output is a (signed or unsigned) 16 bit integer, how can I adapt the algorithm as shown in the patent and the Python code above to work with this format, and produce the same output?