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

Side by Side Diff: webrtc/modules/audio_coding/codecs/ilbc/cb_search.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, 3 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
(...skipping 22 matching lines...) Expand all
33 * Search routine for codebook encoding and gain quantization. 33 * Search routine for codebook encoding and gain quantization.
34 *----------------------------------------------------------------*/ 34 *----------------------------------------------------------------*/
35 35
36 void WebRtcIlbcfix_CbSearch( 36 void WebRtcIlbcfix_CbSearch(
37 IlbcEncoder *iLBCenc_inst, 37 IlbcEncoder *iLBCenc_inst,
38 /* (i) the encoder state structure */ 38 /* (i) the encoder state structure */
39 int16_t *index, /* (o) Codebook indices */ 39 int16_t *index, /* (o) Codebook indices */
40 int16_t *gain_index, /* (o) Gain quantization indices */ 40 int16_t *gain_index, /* (o) Gain quantization indices */
41 int16_t *intarget, /* (i) Target vector for encoding */ 41 int16_t *intarget, /* (i) Target vector for encoding */
42 int16_t *decResidual,/* (i) Decoded residual for codebook construction */ 42 int16_t *decResidual,/* (i) Decoded residual for codebook construction */
43 int16_t lMem, /* (i) Length of buffer */ 43 size_t lMem, /* (i) Length of buffer */
44 int16_t lTarget, /* (i) Length of vector */ 44 size_t lTarget, /* (i) Length of vector */
45 int16_t *weightDenum,/* (i) weighting filter coefficients in Q12 */ 45 int16_t *weightDenum,/* (i) weighting filter coefficients in Q12 */
46 int16_t block /* (i) the subblock number */ 46 size_t block /* (i) the subblock number */
47 ) { 47 ) {
48 int16_t i, j, stage, range; 48 size_t i, range;
49 int16_t ii, j, stage;
49 int16_t *pp; 50 int16_t *pp;
50 int16_t tmp; 51 int16_t tmp;
51 int scale; 52 int scale;
52 int16_t bits, temp1, temp2; 53 int16_t bits, temp1, temp2;
53 int16_t base_size; 54 size_t base_size;
54 int32_t codedEner, targetEner; 55 int32_t codedEner, targetEner;
55 int16_t gains[CB_NSTAGES+1]; 56 int16_t gains[CB_NSTAGES+1];
56 int16_t *cb_vecPtr; 57 int16_t *cb_vecPtr;
57 int16_t indexOffset, sInd, eInd; 58 size_t indexOffset, sInd, eInd;
58 int32_t CritMax=0; 59 int32_t CritMax=0;
59 int16_t shTotMax=WEBRTC_SPL_WORD16_MIN; 60 int16_t shTotMax=WEBRTC_SPL_WORD16_MIN;
60 int16_t bestIndex=0; 61 size_t bestIndex=0;
61 int16_t bestGain=0; 62 int16_t bestGain=0;
62 int16_t indexNew, CritNewSh; 63 size_t indexNew;
64 int16_t CritNewSh;
63 int32_t CritNew; 65 int32_t CritNew;
64 int32_t *cDotPtr; 66 int32_t *cDotPtr;
65 int16_t noOfZeros; 67 size_t noOfZeros;
66 int16_t *gainPtr; 68 int16_t *gainPtr;
67 int32_t t32, tmpW32; 69 int32_t t32, tmpW32;
68 int16_t *WebRtcIlbcfix_kGainSq5_ptr; 70 int16_t *WebRtcIlbcfix_kGainSq5_ptr;
69 /* Stack based */ 71 /* Stack based */
70 int16_t CBbuf[CB_MEML+LPC_FILTERORDER+CB_HALFFILTERLEN]; 72 int16_t CBbuf[CB_MEML+LPC_FILTERORDER+CB_HALFFILTERLEN];
71 int32_t cDot[128]; 73 int32_t cDot[128];
72 int32_t Crit[128]; 74 int32_t Crit[128];
73 int16_t targetVec[SUBL+LPC_FILTERORDER]; 75 int16_t targetVec[SUBL+LPC_FILTERORDER];
74 int16_t cbvectors[CB_MEML + 1]; /* Adding one extra position for 76 int16_t cbvectors[CB_MEML + 1]; /* Adding one extra position for
75 Coverity warnings. */ 77 Coverity warnings. */
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 WebRtcIlbcfix_InterpolateSamples(interpSamples, buf, lMem); 143 WebRtcIlbcfix_InterpolateSamples(interpSamples, buf, lMem);
142 144
143 /* Second section, filtered half of the cb */ 145 /* Second section, filtered half of the cb */
144 WebRtcIlbcfix_InterpolateSamples(interpSamplesFilt, cbvectors, lMem); 146 WebRtcIlbcfix_InterpolateSamples(interpSamplesFilt, cbvectors, lMem);
145 147
146 /* Compute the CB vectors' energies for the first cb section (non-filtered) */ 148 /* Compute the CB vectors' energies for the first cb section (non-filtered) */
147 WebRtcIlbcfix_CbMemEnergyAugmentation(interpSamples, buf, 149 WebRtcIlbcfix_CbMemEnergyAugmentation(interpSamples, buf,
148 scale, 20, energyW16, energyShifts); 150 scale, 20, energyW16, energyShifts);
149 151
150 /* Compute the CB vectors' energies for the second cb section (filtered cb) */ 152 /* Compute the CB vectors' energies for the second cb section (filtered cb) */
151 WebRtcIlbcfix_CbMemEnergyAugmentation(interpSamplesFilt, cbvectors, 153 WebRtcIlbcfix_CbMemEnergyAugmentation(interpSamplesFilt, cbvectors, scale,
152 scale, (int16_t)(base_size + 20), 154 base_size + 20, energyW16,
153 energyW16, energyShifts); 155 energyShifts);
154 156
155 /* Compute the CB vectors' energies and store them in the vector 157 /* Compute the CB vectors' energies and store them in the vector
156 * energyW16. Also the corresponding shift values are stored. The 158 * energyW16. Also the corresponding shift values are stored. The
157 * energy values are used in all three stages. */ 159 * energy values are used in all three stages. */
158 WebRtcIlbcfix_CbMemEnergy(range, buf, cbvectors, lMem, 160 WebRtcIlbcfix_CbMemEnergy(range, buf, cbvectors, lMem,
159 lTarget, energyW16+20, energyShifts+20, scale, bas e_size); 161 lTarget, energyW16+20, energyShifts+20, scale, bas e_size);
160 162
161 } else { 163 } else {
162 /* Compute the CB vectors' energies and store them in the vector 164 /* Compute the CB vectors' energies and store them in the vector
163 * energyW16. Also the corresponding shift values are stored. The 165 * energyW16. Also the corresponding shift values are stored. The
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 indexOffset=0; 219 indexOffset=0;
218 220
219 /* Search for best index in this part of the vector */ 221 /* Search for best index in this part of the vector */
220 WebRtcIlbcfix_CbSearchCore( 222 WebRtcIlbcfix_CbSearchCore(
221 cDot, range, stage, inverseEnergy, 223 cDot, range, stage, inverseEnergy,
222 inverseEnergyShifts, Crit, 224 inverseEnergyShifts, Crit,
223 &indexNew, &CritNew, &CritNewSh); 225 &indexNew, &CritNew, &CritNewSh);
224 226
225 /* Update the global best index and the corresponding gain */ 227 /* Update the global best index and the corresponding gain */
226 WebRtcIlbcfix_CbUpdateBestIndex( 228 WebRtcIlbcfix_CbUpdateBestIndex(
227 CritNew, CritNewSh, (int16_t)(indexNew+indexOffset), cDot[indexNew+index Offset], 229 CritNew, CritNewSh, indexNew+indexOffset, cDot[indexNew+indexOffset],
228 inverseEnergy[indexNew+indexOffset], inverseEnergyShifts[indexNew+indexO ffset], 230 inverseEnergy[indexNew+indexOffset], inverseEnergyShifts[indexNew+indexO ffset],
229 &CritMax, &shTotMax, &bestIndex, &bestGain); 231 &CritMax, &shTotMax, &bestIndex, &bestGain);
230 232
231 sInd = ((CB_RESRANGE >> 1) > bestIndex) ? 233 sInd = ((CB_RESRANGE >> 1) > bestIndex) ?
232 0 : (bestIndex - (CB_RESRANGE >> 1)); 234 0 : (bestIndex - (CB_RESRANGE >> 1));
233 eInd=sInd+CB_RESRANGE; 235 eInd=sInd+CB_RESRANGE;
234 if (eInd>=range) { 236 if (eInd>=range) {
235 eInd=range-1; 237 eInd=range-1;
236 sInd=eInd-CB_RESRANGE; 238 sInd=eInd-CB_RESRANGE;
237 } 239 }
238 240
239 range = WebRtcIlbcfix_kSearchRange[block][stage]; 241 range = WebRtcIlbcfix_kSearchRange[block][stage];
240 242
241 if (lTarget==SUBL) { 243 if (lTarget==SUBL) {
242 i=sInd; 244 i=sInd;
243 if (sInd<20) { 245 if (sInd<20) {
244 WebRtcIlbcfix_AugmentedCbCorr(target, cbvectors + lMem, 246 WebRtcIlbcfix_AugmentedCbCorr(target, cbvectors + lMem,
245 interpSamplesFilt, cDot, 247 interpSamplesFilt, cDot, sInd + 20,
246 (int16_t)(sInd + 20), 248 WEBRTC_SPL_MIN(39, (eInd + 20)), scale);
247 (int16_t)(WEBRTC_SPL_MIN(39,
248 (eInd + 20))),
249 scale);
250 i=20; 249 i=20;
251 cDotPtr = &cDot[20 - sInd]; 250 cDotPtr = &cDot[20 - sInd];
252 } else { 251 } else {
253 cDotPtr = cDot; 252 cDotPtr = cDot;
254 } 253 }
255 254
256 cb_vecPtr = cbvectors+lMem-20-i; 255 cb_vecPtr = cbvectors+lMem-20-i;
257 256
258 /* Calculate the cross correlations (main part of the filtered CB) */ 257 /* Calculate the cross correlations (main part of the filtered CB) */
259 WebRtcSpl_CrossCorrelation(cDotPtr, target, cb_vecPtr, lTarget, 258 WebRtcSpl_CrossCorrelation(cDotPtr, target, cb_vecPtr, lTarget,
260 (int16_t)(eInd - i + 1), scale, -1); 259 eInd - i + 1, scale, -1);
261 260
262 } else { 261 } else {
263 cDotPtr = cDot; 262 cDotPtr = cDot;
264 cb_vecPtr = cbvectors+lMem-lTarget-sInd; 263 cb_vecPtr = cbvectors+lMem-lTarget-sInd;
265 264
266 /* Calculate the cross correlations (main part of the filtered CB) */ 265 /* Calculate the cross correlations (main part of the filtered CB) */
267 WebRtcSpl_CrossCorrelation(cDotPtr, target, cb_vecPtr, lTarget, 266 WebRtcSpl_CrossCorrelation(cDotPtr, target, cb_vecPtr, lTarget,
268 (int16_t)(eInd - sInd + 1), scale, -1); 267 eInd - sInd + 1, scale, -1);
269 268
270 } 269 }
271 270
272 /* Adjust the search range for the augmented vectors */ 271 /* Adjust the search range for the augmented vectors */
273 indexOffset=base_size+sInd; 272 indexOffset=base_size+sInd;
274 273
275 /* Search for best index in this part of the vector */ 274 /* Search for best index in this part of the vector */
276 WebRtcIlbcfix_CbSearchCore( 275 WebRtcIlbcfix_CbSearchCore(
277 cDot, (int16_t)(eInd-sInd+1), stage, inverseEnergy+indexOffset, 276 cDot, eInd-sInd+1, stage, inverseEnergy+indexOffset,
278 inverseEnergyShifts+indexOffset, Crit, 277 inverseEnergyShifts+indexOffset, Crit,
279 &indexNew, &CritNew, &CritNewSh); 278 &indexNew, &CritNew, &CritNewSh);
280 279
281 /* Update the global best index and the corresponding gain */ 280 /* Update the global best index and the corresponding gain */
282 WebRtcIlbcfix_CbUpdateBestIndex( 281 WebRtcIlbcfix_CbUpdateBestIndex(
283 CritNew, CritNewSh, (int16_t)(indexNew+indexOffset), cDot[indexNew], 282 CritNew, CritNewSh, indexNew+indexOffset, cDot[indexNew],
284 inverseEnergy[indexNew+indexOffset], inverseEnergyShifts[indexNew+indexO ffset], 283 inverseEnergy[indexNew+indexOffset], inverseEnergyShifts[indexNew+indexO ffset],
285 &CritMax, &shTotMax, &bestIndex, &bestGain); 284 &CritMax, &shTotMax, &bestIndex, &bestGain);
286 285
287 index[stage] = bestIndex; 286 index[stage] = (int16_t)bestIndex;
288 287
289 288
290 bestGain = WebRtcIlbcfix_GainQuant(bestGain, 289 bestGain = WebRtcIlbcfix_GainQuant(bestGain,
291 (int16_t)WEBRTC_SPL_ABS_W16(gains[stage]) , stage, &gain_index[stage]); 290 (int16_t)WEBRTC_SPL_ABS_W16(gains[stage]) , stage, &gain_index[stage]);
292 291
293 /* Extract the best (according to measure) codebook vector 292 /* Extract the best (according to measure) codebook vector
294 Also adjust the index, so that the augmented vectors are last. 293 Also adjust the index, so that the augmented vectors are last.
295 Above these vectors were first... 294 Above these vectors were first...
296 */ 295 */
297 296
298 if(lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) { 297 if(lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {
299 298
300 if(index[stage]<base_size) { 299 if((size_t)index[stage]<base_size) {
301 pp=buf+lMem-lTarget-index[stage]; 300 pp=buf+lMem-lTarget-index[stage];
302 } else { 301 } else {
303 pp=cbvectors+lMem-lTarget- 302 pp=cbvectors+lMem-lTarget-
304 index[stage]+base_size; 303 index[stage]+base_size;
305 } 304 }
306 305
307 } else { 306 } else {
308 307
309 if (index[stage]<base_size) { 308 if ((size_t)index[stage]<base_size) {
310 if (index[stage]>=20) { 309 if (index[stage]>=20) {
311 /* Adjust index and extract vector */ 310 /* Adjust index and extract vector */
312 index[stage]-=20; 311 index[stage]-=20;
313 pp=buf+lMem-lTarget-index[stage]; 312 pp=buf+lMem-lTarget-index[stage];
314 } else { 313 } else {
315 /* Adjust index and extract vector */ 314 /* Adjust index and extract vector */
316 index[stage]+=(base_size-20); 315 index[stage]+=(int16_t)(base_size-20);
317 316
318 WebRtcIlbcfix_CreateAugmentedVec((int16_t)(index[stage]-base_size+40), 317 WebRtcIlbcfix_CreateAugmentedVec(index[stage]-base_size+40,
319 buf+lMem, aug_vec); 318 buf+lMem, aug_vec);
320 pp = aug_vec; 319 pp = aug_vec;
321 320
322 } 321 }
323 } else { 322 } else {
324 323
325 if ((index[stage] - base_size) >= 20) { 324 if ((index[stage] - base_size) >= 20) {
326 /* Adjust index and extract vector */ 325 /* Adjust index and extract vector */
327 index[stage]-=20; 326 index[stage]-=20;
328 pp=cbvectors+lMem-lTarget- 327 pp=cbvectors+lMem-lTarget-
329 index[stage]+base_size; 328 index[stage]+base_size;
330 } else { 329 } else {
331 /* Adjust index and extract vector */ 330 /* Adjust index and extract vector */
332 index[stage]+=(base_size-20); 331 index[stage]+=(int16_t)(base_size-20);
333 WebRtcIlbcfix_CreateAugmentedVec((int16_t)(index[stage]-2*base_size+40 ), 332 WebRtcIlbcfix_CreateAugmentedVec(index[stage]-2*base_size+40,
334 cbvectors+lMem, aug_vec); 333 cbvectors+lMem, aug_vec);
335 pp = aug_vec; 334 pp = aug_vec;
336 } 335 }
337 } 336 }
338 } 337 }
339 338
340 /* Subtract the best codebook vector, according 339 /* Subtract the best codebook vector, according
341 to measure, from the target vector */ 340 to measure, from the target vector */
342 341
343 WebRtcSpl_AddAffineVectorToVector(target, pp, (int16_t)(-bestGain), 342 WebRtcSpl_AddAffineVectorToVector(target, pp, (int16_t)(-bestGain),
(...skipping 30 matching lines...) Expand all
374 tmpW32 = ((int32_t)(gains[1]-1))<<1; 373 tmpW32 = ((int32_t)(gains[1]-1))<<1;
375 374
376 /* Pointer to the table that contains 375 /* Pointer to the table that contains
377 gain_sq5TblFIX * gain_sq5TblFIX in Q14 */ 376 gain_sq5TblFIX * gain_sq5TblFIX in Q14 */
378 gainPtr=(int16_t*)WebRtcIlbcfix_kGainSq5Sq+gain_index[0]; 377 gainPtr=(int16_t*)WebRtcIlbcfix_kGainSq5Sq+gain_index[0];
379 temp1 = (int16_t)WEBRTC_SPL_SHIFT_W32(codedEner, -bits); 378 temp1 = (int16_t)WEBRTC_SPL_SHIFT_W32(codedEner, -bits);
380 379
381 WebRtcIlbcfix_kGainSq5_ptr = (int16_t*)&WebRtcIlbcfix_kGainSq5[j]; 380 WebRtcIlbcfix_kGainSq5_ptr = (int16_t*)&WebRtcIlbcfix_kGainSq5[j];
382 381
383 /* targetEner and codedEner are in Q(-2*scale) */ 382 /* targetEner and codedEner are in Q(-2*scale) */
384 for (i=gain_index[0];i<32;i++) { 383 for (ii=gain_index[0];ii<32;ii++) {
385 384
386 /* Change the index if 385 /* Change the index if
387 (codedEnergy*gainTbl[i]*gainTbl[i])<(targetEn*gain[0]*gain[0]) AND 386 (codedEnergy*gainTbl[i]*gainTbl[i])<(targetEn*gain[0]*gain[0]) AND
388 gainTbl[i] < 2*gain[0] 387 gainTbl[i] < 2*gain[0]
389 */ 388 */
390 389
391 t32 = temp1 * *gainPtr; 390 t32 = temp1 * *gainPtr;
392 t32 = t32 - targetEner; 391 t32 = t32 - targetEner;
393 if (t32 < 0) { 392 if (t32 < 0) {
394 if ((*WebRtcIlbcfix_kGainSq5_ptr) < tmpW32) { 393 if ((*WebRtcIlbcfix_kGainSq5_ptr) < tmpW32) {
395 j=i; 394 j=ii;
396 WebRtcIlbcfix_kGainSq5_ptr = (int16_t*)&WebRtcIlbcfix_kGainSq5[i]; 395 WebRtcIlbcfix_kGainSq5_ptr = (int16_t*)&WebRtcIlbcfix_kGainSq5[ii];
397 } 396 }
398 } 397 }
399 gainPtr++; 398 gainPtr++;
400 } 399 }
401 gain_index[0]=j; 400 gain_index[0]=j;
402 401
403 return; 402 return;
404 } 403 }
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/ilbc/cb_search.h ('k') | webrtc/modules/audio_coding/codecs/ilbc/cb_search_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698