Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/main/source/filter_functions.c

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory.h> 11 #include <memory.h>
12 #include <string.h> 12 #include <string.h>
13 #ifdef WEBRTC_ANDROID 13 #ifdef WEBRTC_ANDROID
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #endif 15 #endif
16 #include "pitch_estimator.h" 16 #include "pitch_estimator.h"
17 #include "lpc_analysis.h" 17 #include "lpc_analysis.h"
18 #include "codec.h" 18 #include "codec.h"
19 19
20 20
21 21
22 void WebRtcIsac_AllPoleFilter(double *InOut, double *Coef, int lengthInOut, int orderCoef){ 22 void WebRtcIsac_AllPoleFilter(double* InOut,
23 23 double* Coef,
24 size_t lengthInOut,
25 int orderCoef) {
24 /* the state of filter is assumed to be in InOut[-1] to InOut[-orderCoef] */ 26 /* the state of filter is assumed to be in InOut[-1] to InOut[-orderCoef] */
25 double scal; 27 double scal;
26 double sum; 28 double sum;
27 int n,k; 29 size_t n;
30 int k;
28 31
29 //if (fabs(Coef[0]-1.0)<0.001) { 32 //if (fabs(Coef[0]-1.0)<0.001) {
30 if ( (Coef[0] > 0.9999) && (Coef[0] < 1.0001) ) 33 if ( (Coef[0] > 0.9999) && (Coef[0] < 1.0001) )
31 { 34 {
32 for(n = 0; n < lengthInOut; n++) 35 for(n = 0; n < lengthInOut; n++)
33 { 36 {
34 sum = Coef[1] * InOut[-1]; 37 sum = Coef[1] * InOut[-1];
35 for(k = 2; k <= orderCoef; k++){ 38 for(k = 2; k <= orderCoef; k++){
36 sum += Coef[k] * InOut[-k]; 39 sum += Coef[k] * InOut[-k];
37 } 40 }
38 *InOut++ -= sum; 41 *InOut++ -= sum;
39 } 42 }
40 } 43 }
41 else 44 else
42 { 45 {
43 scal = 1.0 / Coef[0]; 46 scal = 1.0 / Coef[0];
44 for(n=0;n<lengthInOut;n++) 47 for(n=0;n<lengthInOut;n++)
45 { 48 {
46 *InOut *= scal; 49 *InOut *= scal;
47 for(k=1;k<=orderCoef;k++){ 50 for(k=1;k<=orderCoef;k++){
48 *InOut -= scal*Coef[k]*InOut[-k]; 51 *InOut -= scal*Coef[k]*InOut[-k];
49 } 52 }
50 InOut++; 53 InOut++;
51 } 54 }
52 } 55 }
53 } 56 }
54 57
55 58
56 void WebRtcIsac_AllZeroFilter(double *In, double *Coef, int lengthInOut, int ord erCoef, double *Out){ 59 void WebRtcIsac_AllZeroFilter(double* In,
57 60 double* Coef,
61 size_t lengthInOut,
62 int orderCoef,
63 double* Out) {
58 /* the state of filter is assumed to be in In[-1] to In[-orderCoef] */ 64 /* the state of filter is assumed to be in In[-1] to In[-orderCoef] */
59 65
60 int n, k; 66 size_t n;
67 int k;
61 double tmp; 68 double tmp;
62 69
63 for(n = 0; n < lengthInOut; n++) 70 for(n = 0; n < lengthInOut; n++)
64 { 71 {
65 tmp = In[0] * Coef[0]; 72 tmp = In[0] * Coef[0];
66 73
67 for(k = 1; k <= orderCoef; k++){ 74 for(k = 1; k <= orderCoef; k++){
68 tmp += Coef[k] * In[-k]; 75 tmp += Coef[k] * In[-k];
69 } 76 }
70 77
71 *Out++ = tmp; 78 *Out++ = tmp;
72 In++; 79 In++;
73 } 80 }
74 } 81 }
75 82
76 83
77 84 void WebRtcIsac_ZeroPoleFilter(double* In,
78 void WebRtcIsac_ZeroPoleFilter(double *In, double *ZeroCoef, double *PoleCoef, i nt lengthInOut, int orderCoef, double *Out){ 85 double* ZeroCoef,
79 86 double* PoleCoef,
87 size_t lengthInOut,
88 int orderCoef,
89 double* Out) {
80 /* the state of the zero section is assumed to be in In[-1] to In[-orderCoef] */ 90 /* the state of the zero section is assumed to be in In[-1] to In[-orderCoef] */
81 /* the state of the pole section is assumed to be in Out[-1] to Out[-orderCoef ] */ 91 /* the state of the pole section is assumed to be in Out[-1] to Out[-orderCoef ] */
82 92
83 WebRtcIsac_AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out); 93 WebRtcIsac_AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);
84 WebRtcIsac_AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef); 94 WebRtcIsac_AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);
85 } 95 }
86 96
87 97
88 void WebRtcIsac_AutoCorr( 98 void WebRtcIsac_AutoCorr(double* r, const double* x, size_t N, size_t order) {
89 double *r, 99 size_t lag, n;
90 const double *x,
91 int N,
92 int order
93 )
94 {
95 int lag, n;
96 double sum, prod; 100 double sum, prod;
97 const double *x_lag; 101 const double *x_lag;
98 102
99 for (lag = 0; lag <= order; lag++) 103 for (lag = 0; lag <= order; lag++)
100 { 104 {
101 sum = 0.0f; 105 sum = 0.0f;
102 x_lag = &x[lag]; 106 x_lag = &x[lag];
103 prod = x[0] * x_lag[0]; 107 prod = x[0] * x_lag[0];
104 for (n = 1; n < N - lag; n++) { 108 for (n = 1; n < N - lag; n++) {
105 sum += prod; 109 sum += prod;
106 prod = x[n] * x_lag[n]; 110 prod = x[n] * x_lag[n];
107 } 111 }
108 sum += prod; 112 sum += prod;
109 r[lag] = sum; 113 r[lag] = sum;
110 } 114 }
111 115
112 } 116 }
113 117
114 118
115 void WebRtcIsac_BwExpand(double *out, double *in, double coef, short length) { 119 void WebRtcIsac_BwExpand(double* out, double* in, double coef, size_t length) {
116 int i; 120 size_t i;
117 double chirp; 121 double chirp;
118 122
119 chirp = coef; 123 chirp = coef;
120 124
121 out[0] = in[0]; 125 out[0] = in[0];
122 for (i = 1; i < length; i++) { 126 for (i = 1; i < length; i++) {
123 out[i] = chirp * in[i]; 127 out[i] = chirp * in[i];
124 chirp *= coef; 128 chirp *= coef;
125 } 129 }
126 } 130 }
127 131
128 void WebRtcIsac_WeightingFilter(const double *in, double *weiout, double *whiout , WeightFiltstr *wfdata) { 132 void WebRtcIsac_WeightingFilter(const double* in,
129 133 double* weiout,
134 double* whiout,
135 WeightFiltstr* wfdata) {
130 double tmpbuffer[PITCH_FRAME_LEN + PITCH_WLPCBUFLEN]; 136 double tmpbuffer[PITCH_FRAME_LEN + PITCH_WLPCBUFLEN];
131 double corr[PITCH_WLPCORDER+1], rc[PITCH_WLPCORDER+1]; 137 double corr[PITCH_WLPCORDER+1], rc[PITCH_WLPCORDER+1];
132 double apol[PITCH_WLPCORDER+1], apolr[PITCH_WLPCORDER+1]; 138 double apol[PITCH_WLPCORDER+1], apolr[PITCH_WLPCORDER+1];
133 double rho=0.9, *inp, *dp, *dp2; 139 double rho=0.9, *inp, *dp, *dp2;
134 double whoutbuf[PITCH_WLPCBUFLEN + PITCH_WLPCORDER]; 140 double whoutbuf[PITCH_WLPCBUFLEN + PITCH_WLPCORDER];
135 double weoutbuf[PITCH_WLPCBUFLEN + PITCH_WLPCORDER]; 141 double weoutbuf[PITCH_WLPCBUFLEN + PITCH_WLPCORDER];
136 double *weo, *who, opol[PITCH_WLPCORDER+1], ext[PITCH_WLPCWINLEN]; 142 double *weo, *who, opol[PITCH_WLPCORDER+1], ext[PITCH_WLPCWINLEN];
137 int k, n, endpos, start; 143 int k, n, endpos, start;
138 144
139 /* Set up buffer and states */ 145 /* Set up buffer and states */
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 /* Export output data */ 194 /* Export output data */
189 memcpy(weiout, weoutbuf+PITCH_WLPCORDER, sizeof(double) * PITCH_FRAME_LEN); 195 memcpy(weiout, weoutbuf+PITCH_WLPCORDER, sizeof(double) * PITCH_FRAME_LEN);
190 memcpy(whiout, whoutbuf+PITCH_WLPCORDER, sizeof(double) * PITCH_FRAME_LEN); 196 memcpy(whiout, whoutbuf+PITCH_WLPCORDER, sizeof(double) * PITCH_FRAME_LEN);
191 } 197 }
192 198
193 199
194 static const double APupper[ALLPASSSECTIONS] = {0.0347, 0.3826}; 200 static const double APupper[ALLPASSSECTIONS] = {0.0347, 0.3826};
195 static const double APlower[ALLPASSSECTIONS] = {0.1544, 0.744}; 201 static const double APlower[ALLPASSSECTIONS] = {0.1544, 0.744};
196 202
197 203
198 204 void WebRtcIsac_AllpassFilterForDec(double* InOut,
199 void WebRtcIsac_AllpassFilterForDec(double *InOut, 205 const double* APSectionFactors,
200 const double *APSectionFactors, 206 size_t lengthInOut,
201 int lengthInOut, 207 double* FilterState) {
202 double *FilterState)
203 {
204 //This performs all-pass filtering--a series of first order all-pass sections are used 208 //This performs all-pass filtering--a series of first order all-pass sections are used
205 //to filter the input in a cascade manner. 209 //to filter the input in a cascade manner.
206 int n,j; 210 size_t n,j;
207 double temp; 211 double temp;
208 for (j=0; j<ALLPASSSECTIONS; j++){ 212 for (j=0; j<ALLPASSSECTIONS; j++){
209 for (n=0;n<lengthInOut;n+=2){ 213 for (n=0;n<lengthInOut;n+=2){
210 temp = InOut[n]; //store input 214 temp = InOut[n]; //store input
211 InOut[n] = FilterState[j] + APSectionFactors[j]*temp; 215 InOut[n] = FilterState[j] + APSectionFactors[j]*temp;
212 FilterState[j] = -APSectionFactors[j]*InOut[n] + temp; 216 FilterState[j] = -APSectionFactors[j]*InOut[n] + temp;
213 } 217 }
214 } 218 }
215 } 219 }
216 220
217 void WebRtcIsac_DecimateAllpass(const double *in, 221 void WebRtcIsac_DecimateAllpass(const double* in,
218 double *state_in, /* array of size: 2*ALL PASSSECTIONS+1 */ 222 double* state_in,
219 int N, /* number of input samp les */ 223 size_t N,
220 double *out) /* array of size N/2 */ 224 double* out) {
221 { 225 size_t n;
222 int n;
223 double data_vec[PITCH_FRAME_LEN]; 226 double data_vec[PITCH_FRAME_LEN];
224 227
225 /* copy input */ 228 /* copy input */
226 memcpy(data_vec+1, in, sizeof(double) * (N-1)); 229 memcpy(data_vec+1, in, sizeof(double) * (N-1));
227 230
228 data_vec[0] = state_in[2*ALLPASSSECTIONS]; //the z^(-1) state 231 data_vec[0] = state_in[2*ALLPASSSECTIONS]; //the z^(-1) state
229 state_in[2*ALLPASSSECTIONS] = in[N-1]; 232 state_in[2*ALLPASSSECTIONS] = in[N-1];
230 233
231 WebRtcIsac_AllpassFilterForDec(data_vec+1, APupper, N, state_in); 234 WebRtcIsac_AllpassFilterForDec(data_vec+1, APupper, N, state_in);
232 WebRtcIsac_AllpassFilterForDec(data_vec, APlower, N, state_in+ALLPASSSECTIONS) ; 235 WebRtcIsac_AllpassFilterForDec(data_vec, APlower, N, state_in+ALLPASSSECTIONS) ;
233 236
234 for (n=0;n<N/2;n++) 237 for (n=0;n<N/2;n++)
235 out[n] = data_vec[2*n] + data_vec[2*n+1]; 238 out[n] = data_vec[2*n] + data_vec[2*n+1];
236 239
237 } 240 }
238 241
239 242
240
241 /* create high-pass filter ocefficients 243 /* create high-pass filter ocefficients
242 * z = 0.998 * exp(j*2*pi*35/8000); 244 * z = 0.998 * exp(j*2*pi*35/8000);
243 * p = 0.94 * exp(j*2*pi*140/8000); 245 * p = 0.94 * exp(j*2*pi*140/8000);
244 * HP_b = [1, -2*real(z), abs(z)^2]; 246 * HP_b = [1, -2*real(z), abs(z)^2];
245 * HP_a = [1, -2*real(p), abs(p)^2]; */ 247 * HP_a = [1, -2*real(p), abs(p)^2]; */
246 static const double a_coef[2] = { 1.86864659625574, -0.88360000000000}; 248 static const double a_coef[2] = { 1.86864659625574, -0.88360000000000};
247 static const double b_coef[2] = {-1.99524591718270, 0.99600400000000}; 249 static const double b_coef[2] = {-1.99524591718270, 0.99600400000000};
248 250
249 /* second order high-pass filter */ 251 /* second order high-pass filter */
250 void WebRtcIsac_Highpass(const double *in, double *out, double *state, int N) 252 void WebRtcIsac_Highpass(const double* in,
251 { 253 double* out,
252 int k; 254 double* state,
255 size_t N) {
256 size_t k;
253 257
254 for (k=0; k<N; k++) { 258 for (k=0; k<N; k++) {
255 *out = *in + state[1]; 259 *out = *in + state[1];
256 state[1] = state[0] + b_coef[0] * *in + a_coef[0] * *out; 260 state[1] = state[0] + b_coef[0] * *in + a_coef[0] * *out;
257 state[0] = b_coef[1] * *in++ + a_coef[1] * *out++; 261 state[0] = b_coef[1] * *in++ + a_coef[1] * *out++;
258 } 262 }
259 } 263 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698