需要等式来找到SimpleAudioEngine中的半步值

时间:2011-07-15 03:49:15

标签: math cocos2d-iphone simpleaudioengine

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

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

  

1.0是原始音高

     

0.5是一个八度(12个半步)低。

     

2.0是一个八度(12个半步)更高

所以,如果我需要:

  

输入:0输出:1

     

输入:-12输出:0.5

     

输入:12输出:2

等式必须是:

  

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

但我不记得如何解决这样的方程式。谢谢!

1 个答案:

答案 0 :(得分:0)

查找表会更快,但这是一个等式(在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;
}
相关问题