PK_2I_D32F32C14G11_TRC_WRA_01.c revision 2c8e5cab3faa6d360e222b7a6c40a80083d021ac
1/* 2 * Copyright (C) 2004-2010 NXP Software 3 * Copyright (C) 2010 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/************************************************************************/ 19/* */ 20/* Project:: */ 21/* $Author: beq07716 $*/ 22/* $Revision: 1000 $*/ 23/* $Date: 2010-06-28 13:08:20 +0200 (Mon, 28 Jun 2010) $*/ 24/* */ 25/************************************************************************/ 26 27#include "BIQUAD.h" 28#include "PK_2I_D32F32CssGss_TRC_WRA_01_Private.h" 29#include "LVM_Macros.h" 30 31/************************************************************************** 32 ASSUMPTIONS: 33 COEFS- 34 pBiquadState->coefs[0] is A0, 35 pBiquadState->coefs[1] is -B2, 36 pBiquadState->coefs[2] is -B1, these are in Q14 format 37 pBiquadState->coefs[3] is Gain, in Q11 format 38 39 40 DELAYS- 41 pBiquadState->pDelays[0] is x(n-1)L in Q0 format 42 pBiquadState->pDelays[1] is x(n-1)R in Q0 format 43 pBiquadState->pDelays[2] is x(n-2)L in Q0 format 44 pBiquadState->pDelays[3] is x(n-2)R in Q0 format 45 pBiquadState->pDelays[4] is y(n-1)L in Q0 format 46 pBiquadState->pDelays[5] is y(n-1)R in Q0 format 47 pBiquadState->pDelays[6] is y(n-2)L in Q0 format 48 pBiquadState->pDelays[7] is y(n-2)R in Q0 format 49***************************************************************************/ 50void PK_2I_D32F32C14G11_TRC_WRA_01 ( Biquad_Instance_t *pInstance, 51 LVM_INT32 *pDataIn, 52 LVM_INT32 *pDataOut, 53 LVM_INT16 NrSamples) 54 { 55 LVM_INT32 ynL,ynR,ynLO,ynRO,templ; 56 LVM_INT16 ii; 57 PFilter_State pBiquadState = (PFilter_State) pInstance; 58 59 for (ii = NrSamples; ii != 0; ii--) 60 { 61 62 63 /************************************************************************** 64 PROCESSING OF THE LEFT CHANNEL 65 ***************************************************************************/ 66 /* ynL= (A0 (Q14) * (x(n)L (Q0) - x(n-2)L (Q0) ) >>14) in Q0*/ 67 templ=(*pDataIn)-pBiquadState->pDelays[2]; 68 MUL32x16INTO32(templ,pBiquadState->coefs[0],ynL,14) 69 70 /* ynL+= ((-B2 (Q14) * y(n-2)L (Q0) ) >>14) in Q0*/ 71 MUL32x16INTO32(pBiquadState->pDelays[6],pBiquadState->coefs[1],templ,14) 72 ynL+=templ; 73 74 /* ynL+= ((-B1 (Q14) * y(n-1)L (Q0) ) >>14) in Q0 */ 75 MUL32x16INTO32(pBiquadState->pDelays[4],pBiquadState->coefs[2],templ,14) 76 ynL+=templ; 77 78 /* ynLO= ((Gain (Q11) * ynL (Q0))>>11) in Q0*/ 79 MUL32x16INTO32(ynL,pBiquadState->coefs[3],ynLO,11) 80 81 /* ynLO=( ynLO(Q0) + x(n)L (Q0) ) in Q0*/ 82 ynLO+= (*pDataIn); 83 84 /************************************************************************** 85 PROCESSING OF THE RIGHT CHANNEL 86 ***************************************************************************/ 87 /* ynR= (A0 (Q14) * (x(n)R (Q0) - x(n-2)R (Q0) ) >>14) in Q0*/ 88 templ=(*(pDataIn+1))-pBiquadState->pDelays[3]; 89 MUL32x16INTO32(templ,pBiquadState->coefs[0],ynR,14) 90 91 /* ynR+= ((-B2 (Q14) * y(n-2)R (Q0) ) >>14) in Q0*/ 92 MUL32x16INTO32(pBiquadState->pDelays[7],pBiquadState->coefs[1],templ,14) 93 ynR+=templ; 94 95 /* ynR+= ((-B1 (Q14) * y(n-1)R (Q0) ) >>14) in Q0 */ 96 MUL32x16INTO32(pBiquadState->pDelays[5],pBiquadState->coefs[2],templ,14) 97 ynR+=templ; 98 99 /* ynRO= ((Gain (Q11) * ynR (Q0))>>11) in Q0*/ 100 MUL32x16INTO32(ynR,pBiquadState->coefs[3],ynRO,11) 101 102 /* ynRO=( ynRO(Q0) + x(n)R (Q0) ) in Q0*/ 103 ynRO+= (*(pDataIn+1)); 104 105 /************************************************************************** 106 UPDATING THE DELAYS 107 ***************************************************************************/ 108 pBiquadState->pDelays[7]=pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/ 109 pBiquadState->pDelays[6]=pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/ 110 pBiquadState->pDelays[3]=pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/ 111 pBiquadState->pDelays[2]=pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/ 112 pBiquadState->pDelays[5]=ynR; /* Update y(n-1)R in Q0*/ 113 pBiquadState->pDelays[4]=ynL; /* Update y(n-1)L in Q0*/ 114 pBiquadState->pDelays[0]=(*pDataIn); /* Update x(n-1)L in Q0*/ 115 pDataIn++; 116 pBiquadState->pDelays[1]=(*pDataIn); /* Update x(n-1)R in Q0*/ 117 pDataIn++; 118 119 /************************************************************************** 120 WRITING THE OUTPUT 121 ***************************************************************************/ 122 *pDataOut=ynLO; /* Write Left output in Q0*/ 123 pDataOut++; 124 *pDataOut=ynRO; /* Write Right ouput in Q0*/ 125 pDataOut++; 126 127 } 128 129 } 130 131