# Differences

This shows you the differences between two versions of the page.

 cs190c:stereo09 [2009/02/05 08:42]seh created cs190c:stereo09 [2009/02/10 11:31] (current)jvalko 2009/02/10 11:31 jvalko 2009/02/05 08:42 seh created 2009/02/10 11:31 jvalko 2009/02/05 08:42 seh created Line 10: Line 10: 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), 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, 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 + 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 - Rhapsody//​. ​ + //[[ http://​www.youtube.com/​watch?​v=irp8CNj9qBI&​fmt=18#​t=3m4s | Bohemian Rhapsody ​]]//. - [Add about calculating pan]. + 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.