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 "BP_1I_D16F16Css_TRC_WRA_01_Private.h"
202c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent#include "LVM_Macros.h"
212c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
222c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
232c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent/**************************************************************************
242c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent ASSUMPTIONS:
252c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent COEFS-
262c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->coefs[0] is A0,
272c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->coefs[1] is -B2,
282c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->coefs[2] is -B1, these are in Q14 format
292c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
302c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent DELAYS-
312c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[0] is x(n-1)L in Q0 format
322c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[1] is x(n-2)L in Q0 format
332c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[2] is y(n-1)L in Q0 format
342c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent pBiquadState->pDelays[3] is y(n-2)L in Q0 format
352c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent***************************************************************************/
362c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
372c87e9c923b0362fabf8c97ff63997542394c428Eric Laurentvoid BP_1I_D16F16C14_TRC_WRA_01 ( Biquad_Instance_t       *pInstance,
382c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                  LVM_INT16               *pDataIn,
392c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                  LVM_INT16               *pDataOut,
402c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                                  LVM_INT16               NrSamples)
412c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
422c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
432c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    {
442c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        LVM_INT32 ynL;
452c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        LVM_INT16 ii;
462c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        PFilter_State pBiquadState = (PFilter_State) pInstance;
472c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
482c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent         for (ii = NrSamples; ii != 0; ii--)
492c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent         {
502c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
512c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
522c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
532c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            PROCESSING OF THE LEFT CHANNEL
542c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
552c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL= (A0 (Q14) * (x(n)L (Q0) - x(n-2)L (Q0) ) )  in Q14
562c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL=(LVM_INT32)pBiquadState->coefs[0]* ((*pDataIn)-pBiquadState->pDelays[1]);
572c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
582c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+= ((-B2 (Q14) * y(n-2)L (Q0) ) ) in Q14
592c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[1]*pBiquadState->pDelays[3];
602c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
612c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            // ynL+= ((-B1 (Q30) * y(n-1)L (Q0) ) ) in Q14
622c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL+=(LVM_INT32)pBiquadState->coefs[2]*pBiquadState->pDelays[2];
632c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
642c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ynL=(LVM_INT16)(ynL>>14); // ynL in Q0
652c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
662c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            UPDATING THE DELAYS
672c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
682c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[3]=pBiquadState->pDelays[2]; // y(n-2)L=y(n-1)L
692c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[1]=pBiquadState->pDelays[0]; // x(n-2)L=x(n-1)L
702c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[2]=ynL; // Update y(n-1)L in Q0
712c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            pBiquadState->pDelays[0]=(*pDataIn++); // Update x(n-1)L in Q0
722c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
732c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            /**************************************************************************
742c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent                            WRITING THE OUTPUT
752c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            ***************************************************************************/
762c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent            *pDataOut++=(LVM_INT16)ynL; // Write Left output in Q0
772c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
782c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent        }
792c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
802c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent    }
812c87e9c923b0362fabf8c97ff63997542394c428Eric Laurent
82