Home | History | Annotate | Download | only in lib_src
      1 /*----------------------------------------------------------------------------
      2  *
      3  * File:
      4  * eas_pan.c
      5  *
      6  * Contents and purpose:
      7  * Calculates left and right gain multipliers based on a pan value from -63 to +63
      8  *
      9  * NOTES:
     10  * The _CMX_PARSER and _MFI_PARSER preprocessor symbols determine
     11  * whether the parser works for those particular file formats.
     12  *
     13  * Copyright Sonic Network Inc. 2005
     14 
     15  * Licensed under the Apache License, Version 2.0 (the "License");
     16  * you may not use this file except in compliance with the License.
     17  * You may obtain a copy of the License at
     18  *
     19  *      http://www.apache.org/licenses/LICENSE-2.0
     20  *
     21  * Unless required by applicable law or agreed to in writing, software
     22  * distributed under the License is distributed on an "AS IS" BASIS,
     23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     24  * See the License for the specific language governing permissions and
     25  * limitations under the License.
     26  *
     27  *----------------------------------------------------------------------------
     28  * Revision Control:
     29  *   $Revision: 82 $
     30  *   $Date: 2006-07-10 11:45:19 -0700 (Mon, 10 Jul 2006) $
     31  *----------------------------------------------------------------------------
     32 */
     33 
     34 #include "eas_pan.h"
     35 #include "eas_math.h"
     36 
     37 /*----------------------------------------------------------------------------
     38  * EAS_CalcPanControl()
     39  *----------------------------------------------------------------------------
     40  * Purpose:
     41  * Assign the left and right gain values corresponding to the given pan value.
     42  *
     43  * This routine uses sin/cos approximations for an equal power curve:
     44  *
     45  * sin(x) = (2-4*c)*x^2 + c + x
     46  * cos(x) = (2-4*c)*x^2 + c - x
     47  *
     48  * where  c = 1/sqrt(2)
     49  * using the a0 + x*(a1 + x*a2) approach
     50  *
     51  * Inputs:
     52  * pan          - pan value (-63 to + 63)
     53  *
     54  * Outputs:
     55  * pGainLeft    linear gain multiplier for left channel (15-bit fraction)
     56  * pGainRight   linear gain multiplier for left channel (15-bit fraction)
     57  *
     58  * Side Effects:
     59  *----------------------------------------------------------------------------
     60 */
     61 void EAS_CalcPanControl (EAS_INT pan, EAS_I16 *pGainLeft, EAS_I16 *pGainRight)
     62 {
     63     EAS_INT temp;
     64     EAS_INT netAngle;
     65 
     66     /* impose hard limit */
     67     if (pan < -63)
     68         netAngle = -63;
     69     else if (pan > 63)
     70         netAngle = 63;
     71     else
     72         netAngle = pan;
     73 
     74     /*lint -e{701} <avoid multiply for performance reasons>*/
     75     netAngle = netAngle << 8;
     76 
     77     /* calculate sin */
     78     temp = EG1_ONE + FMUL_15x15(COEFF_PAN_G2, netAngle);
     79     temp = COEFF_PAN_G0 + FMUL_15x15(temp, netAngle);
     80 
     81     if (temp > SYNTH_FULL_SCALE_EG1_GAIN)
     82         temp = SYNTH_FULL_SCALE_EG1_GAIN;
     83     else if (temp < 0)
     84         temp = 0;
     85 
     86     *pGainRight = (EAS_I16) temp;
     87 
     88     /* calculate cos */
     89     temp = -EG1_ONE + FMUL_15x15(COEFF_PAN_G2, netAngle);
     90     temp = COEFF_PAN_G0 + FMUL_15x15(temp, netAngle);
     91     if (temp > SYNTH_FULL_SCALE_EG1_GAIN)
     92         temp = SYNTH_FULL_SCALE_EG1_GAIN;
     93     else if (temp < 0)
     94         temp = 0;
     95 
     96     *pGainLeft = (EAS_I16) temp;
     97 }
     98 
     99