0

Ok, my math is a bit rusty and I feel like this should be an easy problem, but yet I am here.

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!

Community
  • 1
  • 1
Jason Pawlak
  • 792
  • 1
  • 6
  • 20

1 Answers1

0

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;
}
Steve Wellens
  • 20,506
  • 2
  • 28
  • 69