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"
DC_2I_D16_TRC_WRA_01(Biquad_FLOAT_Instance_t * pInstance,LVM_FLOAT * pDataIn,LVM_FLOAT * pDataOut,LVM_INT16 NrSamples)21 void DC_2I_D16_TRC_WRA_01( Biquad_FLOAT_Instance_t       *pInstance,
22                            LVM_FLOAT               *pDataIn,
23                            LVM_FLOAT               *pDataOut,
24                            LVM_INT16               NrSamples)
25     {
26         LVM_FLOAT LeftDC,RightDC;
27         LVM_FLOAT Diff;
28         LVM_INT32 j;
29         PFilter_FLOAT_State pBiquadState = (PFilter_FLOAT_State) pInstance;
30 
31         LeftDC = pBiquadState->LeftDC;
32         RightDC = pBiquadState->RightDC;
33         for(j = NrSamples-1; j >= 0; j--)
34         {
35             /* Subtract DC and saturate */
36             Diff =* (pDataIn++) - (LeftDC);
37             if (Diff > 1.0f) {
38                 Diff = 1.0f; }
39             else if (Diff < -1.0f) {
40                 Diff = -1.0f; }
41             *(pDataOut++) = (LVM_FLOAT)Diff;
42             if (Diff < 0) {
43                 LeftDC -= DC_FLOAT_STEP; }
44             else {
45                 LeftDC += DC_FLOAT_STEP; }
46 
47             /* Subtract DC an saturate */
48             Diff =* (pDataIn++) - (RightDC);
49             if (Diff > 1.0f) {
50                 Diff = 1.0f; }
51             else if (Diff < -1.0f) {
52                 Diff = -1.0f; }
53             *(pDataOut++) = (LVM_FLOAT)Diff;
54             if (Diff < 0) {
55                 RightDC -= DC_FLOAT_STEP; }
56             else {
57                 RightDC += DC_FLOAT_STEP; }
58 
59         }
60         pBiquadState->LeftDC = LeftDC;
61         pBiquadState->RightDC = RightDC;
62 
63     }
64 #ifdef SUPPORT_MC
65 /*
66  * FUNCTION:       DC_Mc_D16_TRC_WRA_01
67  *
68  * DESCRIPTION:
69  *  DC removal from all channels of a multichannel input
70  *
71  * PARAMETERS:
72  *  pInstance      Instance pointer
73  *  pDataIn        Input/Source
74  *  pDataOut       Output/Destination
75  *  NrFrames       Number of frames
76  *  NrChannels     Number of channels
77  *
78  * RETURNS:
79  *  void
80  *
81  */
DC_Mc_D16_TRC_WRA_01(Biquad_FLOAT_Instance_t * pInstance,LVM_FLOAT * pDataIn,LVM_FLOAT * pDataOut,LVM_INT16 NrFrames,LVM_INT16 NrChannels)82 void DC_Mc_D16_TRC_WRA_01(Biquad_FLOAT_Instance_t       *pInstance,
83                           LVM_FLOAT               *pDataIn,
84                           LVM_FLOAT               *pDataOut,
85                           LVM_INT16               NrFrames,
86                           LVM_INT16               NrChannels)
87     {
88         LVM_FLOAT *ChDC;
89         LVM_FLOAT Diff;
90         LVM_INT32 j;
91         LVM_INT32 i;
92         PFilter_FLOAT_State_Mc pBiquadState = (PFilter_FLOAT_State_Mc) pInstance;
93 
94         ChDC = &pBiquadState->ChDC[0];
95         for (j = NrFrames - 1; j >= 0; j--)
96         {
97             /* Subtract DC and saturate */
98             for (i = NrChannels - 1; i >= 0; i--)
99             {
100                 Diff = *(pDataIn++) - (ChDC[i]);
101                 if (Diff > 1.0f) {
102                     Diff = 1.0f;
103                 } else if (Diff < -1.0f) {
104                     Diff = -1.0f; }
105                 *(pDataOut++) = (LVM_FLOAT)Diff;
106                 if (Diff < 0) {
107                     ChDC[i] -= DC_FLOAT_STEP;
108                 } else {
109                     ChDC[i] += DC_FLOAT_STEP; }
110             }
111 
112         }
113 
114     }
115 #endif
116