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_D16F32Css_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 Q14 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 Q16 format
332c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[3] is y(n-2)L in Q16 format
342c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent***************************************************************************/
352c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
362c87e9c923b0362fabf8c97ff63997542394c428Eric Laurentvoid BQ_1I_D16F32C14_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,templ;
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 (Q14) * x(n-2)L (Q0) in Q14
532c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL=(LVM_INT32)pBiquadState->coefs[0]* pBiquadState->pDelays[1];
542c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
552c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+=A1 (Q14) * x(n-1)L (Q0) in Q14
562c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[1]* pBiquadState->pDelays[0];
572c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
582c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+=A0 (Q14) * x(n)L (Q0) in Q14
592c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[2]* (*pDataIn);
602c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
612c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+= ( (-B2 (Q14) * y(n-2)L (Q16) )>>16) in Q14
622c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            MUL32x16INTO32(pBiquadState->pDelays[3],pBiquadState->coefs[3],templ,16)
632c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=templ;
642c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
652c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+= ( (-B1 (Q14) * y(n-1)L (Q16) )>>16) in Q14
662c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            MUL32x16INTO32(pBiquadState->pDelays[2],pBiquadState->coefs[4],templ,16)
672c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=templ;
682c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
692c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
702c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            UPDATING THE DELAYS
712c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
722c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[3]=pBiquadState->pDelays[2];  // y(n-2)L=y(n-1)L
732c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[1]=pBiquadState->pDelays[0];  // x(n-2)L=x(n-1)L
742c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[2]=ynL<<2;                    // Update y(n-1)L in Q16
752c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[0]=(*pDataIn++);              // Update x(n-1)L in Q0
762c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
772c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
782c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            WRITING THE OUTPUT
792c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
802c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *pDataOut++=(LVM_INT16)(ynL>>14); // Write Left output in Q0
812c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
822c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        }
832c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    }
842c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
85