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 "BQ_2I_D32F32Cll_TRC_WRA_01_Private.h"
20 #include "LVM_Macros.h"
21
22 /**************************************************************************
23 ASSUMPTIONS:
24 COEFS-
25 pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1
26 pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2
27 pBiquadState->coefs[4] is -B1, these are in Q30 format
28
29 DELAYS-
30 pBiquadState->pDelays[0] is x(n-1)L in Q0 format
31 pBiquadState->pDelays[1] is x(n-1)R in Q0 format
32 pBiquadState->pDelays[2] is x(n-2)L in Q0 format
33 pBiquadState->pDelays[3] is x(n-2)R in Q0 format
34 pBiquadState->pDelays[4] is y(n-1)L in Q0 format
35 pBiquadState->pDelays[5] is y(n-1)R in Q0 format
36 pBiquadState->pDelays[6] is y(n-2)L in Q0 format
37 pBiquadState->pDelays[7] is y(n-2)R in Q0 format
38 ***************************************************************************/
BQ_2I_D32F32C30_TRC_WRA_01(Biquad_FLOAT_Instance_t * pInstance,LVM_FLOAT * pDataIn,LVM_FLOAT * pDataOut,LVM_INT16 NrSamples)39 void BQ_2I_D32F32C30_TRC_WRA_01 ( Biquad_FLOAT_Instance_t *pInstance,
40 LVM_FLOAT *pDataIn,
41 LVM_FLOAT *pDataOut,
42 LVM_INT16 NrSamples)
43
44 {
45 LVM_FLOAT ynL,ynR,templ,tempd;
46 LVM_INT16 ii;
47 PFilter_State_FLOAT pBiquadState = (PFilter_State_FLOAT) pInstance;
48
49 for (ii = NrSamples; ii != 0; ii--)
50 {
51
52 /**************************************************************************
53 PROCESSING OF THE LEFT CHANNEL
54 ***************************************************************************/
55 /* ynL= ( A2 * x(n-2)L ) */
56 ynL = pBiquadState->coefs[0] * pBiquadState->pDelays[2];
57
58 /* ynL+= ( A1 * x(n-1)L )*/
59 templ = pBiquadState->coefs[1] * pBiquadState->pDelays[0];
60 ynL += templ;
61
62 /* ynL+= ( A0 * x(n)L ) */
63 templ = pBiquadState->coefs[2] * (*pDataIn);
64 ynL += templ;
65
66 /* ynL+= (-B2 * y(n-2)L ) */
67 templ = pBiquadState->coefs[3] * pBiquadState->pDelays[6];
68 ynL += templ;
69
70 /* ynL+= (-B1 * y(n-1)L )*/
71 templ = pBiquadState->coefs[4] * pBiquadState->pDelays[4];
72 ynL += templ;
73
74 /**************************************************************************
75 PROCESSING OF THE RIGHT CHANNEL
76 ***************************************************************************/
77 /* ynR= ( A2 * x(n-2)R ) */
78 ynR = pBiquadState->coefs[0] * pBiquadState->pDelays[3];
79
80 /* ynR+= ( A1 * x(n-1)R ) */
81 templ = pBiquadState->coefs[1] * pBiquadState->pDelays[1];
82 ynR += templ;
83
84 /* ynR+= ( A0 * x(n)R ) */
85 tempd =* (pDataIn+1);
86 templ = pBiquadState->coefs[2] * tempd;
87 ynR += templ;
88
89 /* ynR+= (-B2 * y(n-2)R ) */
90 templ = pBiquadState->coefs[3] * pBiquadState->pDelays[7];
91 ynR += templ;
92
93 /* ynR+= (-B1 * y(n-1)R ) */
94 templ = pBiquadState->coefs[4] * pBiquadState->pDelays[5];
95 ynR += templ;
96
97 /**************************************************************************
98 UPDATING THE DELAYS
99 ***************************************************************************/
100 pBiquadState->pDelays[7] = pBiquadState->pDelays[5]; /* y(n-2)R=y(n-1)R*/
101 pBiquadState->pDelays[6] = pBiquadState->pDelays[4]; /* y(n-2)L=y(n-1)L*/
102 pBiquadState->pDelays[3] = pBiquadState->pDelays[1]; /* x(n-2)R=x(n-1)R*/
103 pBiquadState->pDelays[2] = pBiquadState->pDelays[0]; /* x(n-2)L=x(n-1)L*/
104 pBiquadState->pDelays[5] = (LVM_FLOAT)ynR; /* Update y(n-1)R */
105 pBiquadState->pDelays[4] = (LVM_FLOAT)ynL; /* Update y(n-1)L */
106 pBiquadState->pDelays[0] = (*pDataIn); /* Update x(n-1)L */
107 pDataIn++;
108 pBiquadState->pDelays[1] = (*pDataIn); /* Update x(n-1)R */
109 pDataIn++;
110
111 /**************************************************************************
112 WRITING THE OUTPUT
113 ***************************************************************************/
114 *pDataOut = (LVM_FLOAT)ynL; /* Write Left output */
115 pDataOut++;
116 *pDataOut = (LVM_FLOAT)ynR; /* Write Right ouput */
117 pDataOut++;
118
119 }
120
121 }
122
123 #ifdef SUPPORT_MC
124 /**************************************************************************
125 ASSUMPTIONS:
126 COEFS-
127 pBiquadState->coefs[0] is A2, pBiquadState->coefs[1] is A1
128 pBiquadState->coefs[2] is A0, pBiquadState->coefs[3] is -B2
129 pBiquadState->coefs[4] is -B1
130
131 DELAYS-
132 pBiquadState->pDelays[0] to
133 pBiquadState->pDelays[NrChannels - 1] is x(n-1) for all NrChannels
134
135 pBiquadState->pDelays[NrChannels] to
136 pBiquadState->pDelays[2*NrChannels - 1] is x(n-2) for all NrChannels
137
138 pBiquadState->pDelays[2*NrChannels] to
139 pBiquadState->pDelays[3*NrChannels - 1] is y(n-1) for all NrChannels
140
141 pBiquadState->pDelays[3*NrChannels] to
142 pBiquadState->pDelays[4*NrChannels - 1] is y(n-2) for all NrChannels
143 ***************************************************************************/
BQ_MC_D32F32C30_TRC_WRA_01(Biquad_FLOAT_Instance_t * pInstance,LVM_FLOAT * pDataIn,LVM_FLOAT * pDataOut,LVM_INT16 NrFrames,LVM_INT16 NrChannels)144 void BQ_MC_D32F32C30_TRC_WRA_01 ( Biquad_FLOAT_Instance_t *pInstance,
145 LVM_FLOAT *pDataIn,
146 LVM_FLOAT *pDataOut,
147 LVM_INT16 NrFrames,
148 LVM_INT16 NrChannels)
149
150 {
151 LVM_FLOAT yn, temp;
152 LVM_INT16 ii, jj;
153 PFilter_State_FLOAT pBiquadState = (PFilter_State_FLOAT) pInstance;
154
155 for (ii = NrFrames; ii != 0; ii--)
156 {
157 /**************************************************************************
158 PROCESSING CHANNEL-WISE
159 ***************************************************************************/
160 for (jj = 0; jj < NrChannels; jj++)
161 {
162 /* yn= (A2 * x(n-2)) */
163 yn = pBiquadState->coefs[0] * pBiquadState->pDelays[NrChannels + jj];
164
165 /* yn+= (A1 * x(n-1)) */
166 temp = pBiquadState->coefs[1] * pBiquadState->pDelays[jj];
167 yn += temp;
168
169 /* yn+= (A0 * x(n)) */
170 temp = pBiquadState->coefs[2] * (*pDataIn);
171 yn += temp;
172
173 /* yn+= (-B2 * y(n-2)) */
174 temp = pBiquadState->coefs[3] * pBiquadState->pDelays[NrChannels*3 + jj];
175 yn += temp;
176
177 /* yn+= (-B1 * y(n-1)) */
178 temp = pBiquadState->coefs[4] * pBiquadState->pDelays[NrChannels*2 + jj];
179 yn += temp;
180
181 /**************************************************************************
182 UPDATING THE DELAYS
183 ***************************************************************************/
184 pBiquadState->pDelays[NrChannels * 3 + jj] =
185 pBiquadState->pDelays[NrChannels * 2 + jj]; /* y(n-2)=y(n-1)*/
186 pBiquadState->pDelays[NrChannels * 1 + jj] =
187 pBiquadState->pDelays[jj]; /* x(n-2)=x(n-1)*/
188 pBiquadState->pDelays[NrChannels * 2 + jj] = (LVM_FLOAT)yn; /* Update y(n-1)*/
189 pBiquadState->pDelays[jj] = (*pDataIn); /* Update x(n-1)*/
190 pDataIn++;
191 /**************************************************************************
192 WRITING THE OUTPUT
193 ***************************************************************************/
194 *pDataOut = (LVM_FLOAT)yn; /* Write jj Channel output */
195 pDataOut++;
196 }
197 }
198
199 }
200 #endif /*SUPPORT_MC*/
201
202