0

I'm new to C++ and I'm trying to understand the SineWave class from the Synthesis Toolkit. The description says:

This class computes and saves a static sine "table" that can be shared by multiple instances. It has an interface similar to the WaveLoop class but inherits from the Generator class. Output values are computed using linear interpolation.

So I guess it doesn't calculate a sine at all? If it's using linear interpolation between the high and low points on a sine wave, isn't that just a triangle wave? Can someone explain what the calculation does?

John Thompson
  • 1,674
  • 1
  • 20
  • 35

1 Answers1

0

If you take a look at the implementation, you'll see that the constructor calculates sin on the range 0.0 to 1.0 in steps of 1.0 / TABLE_SIZE, where TABLE_SIZE is 2048 by default. The linear interpolation is then done between these values. This closely approximates the sine function.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • BTW, one more thing, why is the tick function implemented in the header file instead of the cpp file? – John Thompson Mar 22 '13 at 15:36
  • 1
    @JohnPeterThompsonGarcés Because it is `inline`. For a function to be inlined in a particular translation unit, its implementation must be visible. The easiest way to do this is to just implement it in the header file. – Joseph Mansfield Mar 22 '13 at 15:37