## Stereo Sounds

Until now we have considered only monaural sounds, however the very same principles apply to stereophonic sounds. The advantage of stereo sound is that it allows a sound to be “positioned” from left to right. The human ear determines the position of a sound, in part, by the relative intensities of the sound in the left and right ears. Stereo sounds have two independent channels, one for each ear.

The positioning of a sound in stereo is known as “panning” (the audio counterpart to the cinematographic term). Pan can be static, or it can change in different ways. Listen carefully to one of your favorite rock songs (it's easier using headphones). You will notice that, even if it was recorded in a studio, the pan is laid out as if it were on stage. You will likely hear the lead singer front and center (equal in both channels), a guitar moved to one side a bit and another guitar or bass moved in the other direction, or some similar stage configuration. The drumset is an interesting case, as individual drums may even have different pans. Pan is also put to artistic use in some songs. Sounds can sweep back and forth, or sounds that respond to each other can be placed on opposite sides. A famous example of the latter is the opera section of Queen's Bohemian Rhapsody .

It's tempting to think that we can move a sound by simply scaling each channel linearly. That is, if we want a sound that appears to be shifted to the left by 1/4 we can multilply the input sequency by 3/4 for the left channel and 1/4 for the right channel. However, this is not the case. The human ear doesn't perceive the amplitude directly, but rather the intensity (which is related to the square of the amplitude). In order to find a proper scaling, the sum of the squares of both sides must remain constant. Conveniently, we know the identity that:

sin^2(t) + cos^2(t) = 1

We consider t in the range [0,pi/2]. In this interval, sin(t) increases from 0 to 1 and cos(t) decrease from 1 to 0. Thus we can use one factor to scale each channel. Also, for simplification let us consider:

sin^2(u*pi/2) + cos^2(u*pi/2) = 1

In this form, we can simply work with u in the range [0,1]. Intuitively, we let 0 mean “all the way to the left”, 1 mean “all the way to the right”, and everything else is a floating point value inbetween determining how the sound is scaled in each channel. The sound in the left channel is scaled by cos(u*pi/2) and the right channel by sin(u*pi/2). Thus, to achieve the above example of moving a sound 1/4 to the left, we can use u = .25. The left channel contains the sound scaled by cos(.25*pi/2) = 0.9239, and the right channel by sin(.25*pi/2) = 0.3827.

Of course, to achieve truly real-sounding stereo effects, there are other factors to consider like change in delay times caused by moving the source, or changes in acoustical properties of the room based on the position of the sound. We will not consider such factors, but it is important to know of their existence. Students should take special note that the input of the pan calculation if a mono sequence, and that the operation transforms the mono signal into a stereo signal. This means that such a routine should return a new array, rather than modifying the source array.