[Solved] Convert Notes to Hertz (iOS)


You can use a function based on this formula:

The basic formula for the frequencies of the notes of the equal
tempered scale is given by

fn = f0 * (a)n

where

f0 = the frequency of one fixed note which must be defined. A common choice is setting the A above middle C (A4) at f0 = 440 Hz.

n = the number of half steps away from the fixed note you are. If you are at a higher note, n is positive. If you are on a lower note, n is negative.

fn = the frequency of the note n half steps away. a = (2)1/12 = the twelth root of 2 = the number which when multiplied by itself 12 times equals 2 = 1.059463094359…

http://www.phy.mtu.edu/~suits/NoteFreqCalcs.html

In Objective-C, this would be:

+ (double)frequencyForNote:(Note)note withModifier:(Modifier)modifier inOctave:(int)octave {
    int halfStepsFromA4 = note - A;
    halfStepsFromA4 += 12 * (octave - 4);
    halfStepsFromA4 += modifier;

    double frequencyOfA4 = 440.0;
    double a = 1.059463094359;

    return frequencyOfA4 * pow(a, halfStepsFromA4);
}

With the following enums defined:

typedef enum : int {
    C = 0,
    D = 2,
    E = 4,
    F = 5,
    G = 7,
    A = 9,
    B = 11,
} Note;

typedef enum : int {
    None = 0,
    Sharp = 1,
    Flat = -1,
} Modifier;

https://gist.github.com/NickEntin/32c37e3d31724b229696

2

solved Convert Notes to Hertz (iOS)