eas_pan.c revision 56c99cd2c2c1e6ab038dac5fced5b92ccf11ff6c
19c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes/*---------------------------------------------------------------------------- 29c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * 39c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * File: 49c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * eas_pan.c 59c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * 69c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * Contents and purpose: 79c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * Calculates left and right gain multipliers based on a pan value from -63 to +63 89c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * 99c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * NOTES: 109c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * The _CMX_PARSER and _MFI_PARSER preprocessor symbols determine 119c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * whether the parser works for those particular file formats. 129c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * 139c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * Copyright Sonic Network Inc. 2005 149c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes 159c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 169c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * you may not use this file except in compliance with the License. 179c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * You may obtain a copy of the License at 189c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * 199c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 209c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * 219c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * Unless required by applicable law or agreed to in writing, software 229c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 239c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 249c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * See the License for the specific language governing permissions and 259c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * limitations under the License. 269c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * 279c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes *---------------------------------------------------------------------------- 289c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * Revision Control: 299c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * $Revision: 82 $ 309c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes * $Date: 2006-07-10 11:45:19 -0700 (Mon, 10 Jul 2006) $ 319c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes *---------------------------------------------------------------------------- 329c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes*/ 339c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes 349c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes#include "eas_pan.h" 359c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes#include "eas_math.h" 369c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes 379c8130231a0e1c2a5ded68e99f782427bb5326faElliott Hughes/*---------------------------------------------------------------------------- 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*/ 61void 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