Algorithm to pan audio
The basic technique to place a mono source in stereo is called constant power panning.

If you want to place a mono source at angle $\theta$ you can just use $A_\mathrm{amp}$ and $B_\mathrm{amp}$ as amplitudes for your channels:

$A_\mathrm{amp} = \frac{\sqrt{2}}{2} (\cos{\theta} + \sin{\theta})$

$B_\mathrm{amp} = \frac{\sqrt{2}}{2} (\cos{\theta} - \sin{\theta})$

Typically $\theta$ ranges from $-45^{\circ}$ to $45^{\circ}$ with $0^{\circ}$ being the center.

Hope, that helps.

Reference: Roads, Curtis (1996). The Computer Music Tutorial. Cambridge: The MIT Press, pp. 457–461.

In addition:

You can put it in code directly. E.g. if you use Python and you have mono audio in a numpy array, you can convert it into stereo by a given angle like this:

def panner(x, angle):
    """
    pan a mono audio source into stereo
    x is a numpy array, angle is the angle in radiants
    """
    left = np.sqrt(2)/2.0 * (np.cos(angle) - np.sin(angle)) * x
    right = np.sqrt(2)/2.0 * (np.cos(angle) + np.sin(angle)) * x
    return np.dstack((left,right))[0]


You can use it like panner(np.array([1,2,3]), np.radians(20)). (Of course [1,2,3] is a quite pointless audiobuffer.)