12c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent/*
22c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Copyright (C) 2004-2010 NXP Software
32c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Copyright (C) 2010 The Android Open Source Project
42c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *
52c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
62c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * you may not use this file except in compliance with the License.
72c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * You may obtain a copy of the License at
82c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *
92c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
102c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent *
112c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * Unless required by applicable law or agreed to in writing, software
122c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
132c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * See the License for the specific language governing permissions and
152c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent * limitations under the License.
162c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent */
172c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
182c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent#include "BIQUAD.h"
192c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent#include "BQ_1I_D16F16Css_TRC_WRA_01_Private.h"
202c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent#include "LVM_Macros.h"
212c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
222c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent/**************************************************************************
232c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent ASSUMPTIONS:
242c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent COEFS-
252c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1
262c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2
272c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->coefs[4] is -B1, these are in Q15 format
282c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
292c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent DELAYS-
302c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[0] is x(n-1)L in Q0 format
312c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[1] is x(n-2)L in Q0 format
322c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[2] is y(n-1)L in Q0 format
332c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[3] is y(n-2)L in Q0 format
342c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent***************************************************************************/
352c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
362c87e9c923b0362fabf8c97ff63997542394c428Eric Laurentvoid BQ_1I_D16F16C15_TRC_WRA_01 ( Biquad_Instance_t       *pInstance,
372c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                  LVM_INT16               *pDataIn,
382c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                  LVM_INT16               *pDataOut,
392c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                  LVM_INT16               NrSamples)
402c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    {
412c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        LVM_INT32  ynL;
422c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        LVM_INT16 ii;
432c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        PFilter_State pBiquadState = (PFilter_State) pInstance;
442c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
452c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent         for (ii = NrSamples; ii != 0; ii--)
462c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent         {
472c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
482c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
492c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
502c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            PROCESSING OF THE LEFT CHANNEL
512c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
522c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL=A2 (Q15) * x(n-2)L (Q0) in Q15
532c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[1];
542c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
552c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+=A1 (Q15) * x(n-1)L (Q0) in Q15
562c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0];
572c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
582c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+=A0 (Q15) * x(n)L (Q0) in Q15
592c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn);
602c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
612c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+=  (-B2 (Q15) * y(n-2)L (Q0) ) in Q15
622c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[3]*pBiquadState->pDelays[3];
632c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
642c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+= (-B1 (Q15) * y(n-1)L (Q0) ) in Q15
652c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[4]*pBiquadState->pDelays[2];
662c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
672c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL=ynL>>15; // ynL in Q0 format
682c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
692c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            UPDATING THE DELAYS
702c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
712c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[3]=pBiquadState->pDelays[2]; // y(n-2)L=y(n-1)L
722c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[1]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L
732c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[2]=ynL; // Update y(n-1)L in Q0
742c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0
752c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
762c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
772c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            WRITING THE OUTPUT
782c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
792c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *pDataOut++=(LVM_INT16)ynL; // Write Left output in Q0
802c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
812c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
822c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        }
832c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
842c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    }
852c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
86