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 #include "BIQUAD.h" 19 #include "DC_2I_D16_TRC_WRA_01_Private.h" 20 #include "LVM_Macros.h" 21 #ifdef BUILD_FLOAT 22 void DC_2I_D16_TRC_WRA_01( Biquad_FLOAT_Instance_t *pInstance, 23 LVM_FLOAT *pDataIn, 24 LVM_FLOAT *pDataOut, 25 LVM_INT16 NrSamples) 26 { 27 LVM_FLOAT LeftDC,RightDC; 28 LVM_FLOAT Diff; 29 LVM_INT32 j; 30 PFilter_FLOAT_State pBiquadState = (PFilter_FLOAT_State) pInstance; 31 32 LeftDC = pBiquadState->LeftDC; 33 RightDC = pBiquadState->RightDC; 34 for(j = NrSamples-1; j >= 0; j--) 35 { 36 /* Subtract DC an saturate */ 37 Diff =* (pDataIn++) - (LeftDC); 38 if (Diff > 1.0f) { 39 Diff = 1.0f; } 40 else if (Diff < -1.0f) { 41 Diff = -1.0f; } 42 *(pDataOut++) = (LVM_FLOAT)Diff; 43 if (Diff < 0) { 44 LeftDC -= DC_FLOAT_STEP; } 45 else { 46 LeftDC += DC_FLOAT_STEP; } 47 48 49 /* Subtract DC an saturate */ 50 Diff =* (pDataIn++) - (RightDC); 51 if (Diff > 1.0f) { 52 Diff = 1.0f; } 53 else if (Diff < -1.0f) { 54 Diff = -1.0f; } 55 *(pDataOut++) = (LVM_FLOAT)Diff; 56 if (Diff < 0) { 57 RightDC -= DC_FLOAT_STEP; } 58 else { 59 RightDC += DC_FLOAT_STEP; } 60 61 } 62 pBiquadState->LeftDC = LeftDC; 63 pBiquadState->RightDC = RightDC; 64 65 66 } 67 #else 68 void DC_2I_D16_TRC_WRA_01( Biquad_Instance_t *pInstance, 69 LVM_INT16 *pDataIn, 70 LVM_INT16 *pDataOut, 71 LVM_INT16 NrSamples) 72 { 73 LVM_INT32 LeftDC,RightDC; 74 LVM_INT32 Diff; 75 LVM_INT32 j; 76 PFilter_State pBiquadState = (PFilter_State) pInstance; 77 78 LeftDC = pBiquadState->LeftDC; 79 RightDC = pBiquadState->RightDC; 80 for(j=NrSamples-1;j>=0;j--) 81 { 82 /* Subtract DC an saturate */ 83 Diff=*(pDataIn++)-(LeftDC>>16); 84 if (Diff > 32767) { 85 Diff = 32767; } 86 else if (Diff < -32768) { 87 Diff = -32768; } 88 *(pDataOut++)=(LVM_INT16)Diff; 89 if (Diff < 0) { 90 LeftDC -= DC_D16_STEP; } 91 else { 92 LeftDC += DC_D16_STEP; } 93 94 95 /* Subtract DC an saturate */ 96 Diff=*(pDataIn++)-(RightDC>>16); 97 if (Diff > 32767) { 98 Diff = 32767; } 99 else if (Diff < -32768) { 100 Diff = -32768; } 101 *(pDataOut++)=(LVM_INT16)Diff; 102 if (Diff < 0) { 103 RightDC -= DC_D16_STEP; } 104 else { 105 RightDC += DC_D16_STEP; } 106 107 } 108 pBiquadState->LeftDC = LeftDC; 109 pBiquadState->RightDC = RightDC; 110 111 112 } 113 #endif 114