Converting a pitch bend (MIDI) value to a "normal" pitch value I am trying an offline LPC analysis and synthesis using the rt_lpc (real-time LPC) implementation as given here. There are some functions within the program that can be used for an offline LPC analysis and synthesis program. The rt_lpc code is mostly meant for composers etc., which means that it uses a MIDI or glottal pulse input. There is some code in the program that converts a pitch value (obtained from auto-correlation) to the bend value. The relation is given as follows:  

    pitch = (int)( Stk::sampleRate() / midi2pitch[ananya.data[1]] ) /
                            pow( 1.0653f, bend/64.0f*11.0f );
                    power *= ananya.data[2] / 64.0f;
bend = ge.data[1] / 128.0f + ge.data[2] - 64;


Some points:
a. ananya is an object of type MidiMsg that seems to be populated on the fly.
b. ge is also an object of type MidiMsg that also seems to be populated on the fly.
c. These two objects are created when the program is run in real-time (mine is an offline version that runs selective parts of it in a main.cpp of my own.

My question(s):
1. What is pitch bend?
2. How do I convert a pitch value into a bend value? What are the mapping relations?  

I have googled for solutions but found no clear answer.
At the core of MIDI is a representation of music as discrete note events, each of those having a static pitch. This is perfect for representing music as played on keyboard instruments. You can convert any frequency corresponding to a note on the tempered scale into a MIDI note number, using:

$69 + 12 \times \log_2 \frac{frequency}{440}$

Under the assumption that the MIDI receiver is calibrated for A4 = 440 Hz.

This representation is alright for piano music, but the problem is how to represent pitches which are not mapped to the tempered scale (non-western music, non musical sounds), and how to represent pitch variations over the duration of a note (glissando, vibrato).

This is done in MIDI by using "pitch bend messages" which instruct the synthesizer to shift the pitch of the currently played note by a small interval. Most synthesizers are calibrated by default for +/- 2 semitones over the course of the pitch bend message range (0 .. 16383). 8192 corresponds to no pitch bending - the emitted pitch is exactly that of the note value. The mapping between the pitch bend value and the frequency shifting ratio is given by:

$\frac{f_{emitted\_note}}{f_{note\_message}} = 2 ^ {\frac{pitchbend - 8192}{4096 \times 12}}$

You can thus get the frequency of a note played by a syntheszier from the following formula:

$440 \times 2^{\frac{note - 69}{12.0} + \frac{pitchbend - 8192}{4096 \times 12}}$

Where note is the 7-bits MIDI note number of the last received Note On message ; and pitchbend is the 14-bits value of the last received Pitch bend message. A synthesizer starts with its pitch bend register set to 8192, and this value is also reset during the reception of a "Reset all controllers" message.

Let us take the following example. You want to express a flute trill with the following frequency trajectory: 500 Hz, 510 Hz, 500 Hz, as MIDI messages.

The base note number is:

$round(69 + 12 \times \log_2(500 / 440)) = 71$.

So you send a "note on" message with note# equal to 71. This is equivalent to a pitch of:

$440 \times 2 ^ {(71 - 69) / 12} = 493.88$

Which is the nearest pitch on the tempered scale. You need to send a pitch bend message to raise the pitch by a factor of:

$\frac{500}{493.88} = 1.0124$

And get your 500 Hz. The corresponding pitch bend value is:

$round(8192 + 4096 \times 12 \times log_2 1.0124) = 9065$

To get your 510 Hz, the pitch bend value would be:

$round(8192 + 4096 \times 12 \times log_2 \frac{510}{493.88}) = 10469$

So your sequence of MIDI messages for 500, 510, 500 Hz would be:


NOTE 71
PITCH BEND 9065
...
PITCH BEND 10469
...
PITCH BEND 9065


You can think of the MIDI note number as the "integral" part of the pitch ; and the pitch bend as a redundant "fractional" part of the pitch.