【问题标题】:How does stk::SineWave calculate a sine?stk::SineWave 如何计算正弦?
【发布时间】:2013-03-22 15:21:47
【问题描述】:

我是 C++ 新手,我正在尝试理解 SineWave class from the Synthesis Toolkitdescription 说:

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.

所以我猜它根本不计算正弦?如果它在正弦波的高点和低点之间使用线性插值,那不就是三角波吗?有人能解释一下这个计算是做什么的吗?

【问题讨论】:

  • 是什么让您认为它们在最大值和最小值之间线性插值?
  • 我认为这取决于他们在表格中填充了多少点。如果他们使用了足够多的点,这应该是一个合理的近似值。
  • @sftrabbit 我根本不知道他们在做什么。我不明白计算,因为我看不到它们使用任何三角函数或多项式展开。我想知道是否有人可以解释一下。
  • @JohnPeterThompsonGarcés 那是因为您只查看头文件。 The implementation 使用 sin
  • 哦,谢谢。我是个菜鸟。

标签: c++ sound-synthesis


【解决方案1】:

如果您查看the implementation,您会看到构造函数在0.01.0 的范围内以1.0 / TABLE_SIZE 的步长计算sin,其中TABLE_SIZE2048默认。然后在这些值之间进行线性插值。这非常接近正弦函数。

【讨论】:

  • BTW,还有一件事,为什么tick函数是在头文件而不是cpp文件中实现的?
  • @JohnPeterThompsonGarcés 因为它是inline。对于要在特定翻译单元中内联的函数,它的实现必须是可见的。最简单的方法就是在头文件中实现它。
猜你喜欢
  • 2016-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
  • 1970-01-01
  • 2016-06-19
相关资源
最近更新 更多