需要在SimpleAudioEngine中找到半阶跃值的方程



好吧,我的数学有点生疏,我觉得这应该是一个简单的问题,但我还是在这里。

对于Cocos2d中的SimpleAudioEngine,有一个pitch参数。定义如下:

1.0为原始音高

0.5是低一个八度(12个半阶)

2.0高一个八度(12个半音阶)

如果我需要:

输入:0输出:1

输入:-12输出:0.5

输入:12输出:2

等式必须是这样的:

f(x) = f(x-1) * 2

但是我不记得怎么解那样的方程了。谢谢!

查找表会更快,但这里有一个公式(在c#中):

public double NormalizeScaleStep(int Input)
{
    double Note = 1.0;
    if (Input == 0)
        return Note;
    if (Input > 0)
    {
        for (int Index = 0; Index < Input; Index++)
        {
            Note = Note * 1.059463094;
        }
    }
    else
    {
        for (int Index = Input; Index < 0; Index++)
        {
            Note = Note / 1.059463094;
        }
    }
    return Note;
}

最新更新