Need equation to find half step value in SimpleAudioEngine
Ok, my math is a bit rusty and I feel like this should be an easy problem, but yet I am her开发者_运维知识库e.
For SimpleAudioEngine in Cocos2d, there is a pitch argument. It is defined as follows:
1.0 is original pitch
0.5 is one octave (12 half steps) lower
2.0 is one octave (12 half steps) higher
So if I need:
input: 0 output: 1
input:-12 output: 0.5
input:12 output: 2
The equation has to be something like:
f(x) = f(x-1) * 2
But I don't remember how to solve equations like that. Thanks!
A look-up table would be faster but here's an equation (in 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;
}
精彩评论