OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 269 |
270 free(self); | 270 free(self); |
271 } | 271 } |
272 | 272 |
273 BinaryDelayEstimatorFarend* WebRtc_CreateBinaryDelayEstimatorFarend( | 273 BinaryDelayEstimatorFarend* WebRtc_CreateBinaryDelayEstimatorFarend( |
274 int history_size) { | 274 int history_size) { |
275 BinaryDelayEstimatorFarend* self = NULL; | 275 BinaryDelayEstimatorFarend* self = NULL; |
276 | 276 |
277 if (history_size > 1) { | 277 if (history_size > 1) { |
278 // Sanity conditions fulfilled. | 278 // Sanity conditions fulfilled. |
279 self = malloc(sizeof(BinaryDelayEstimatorFarend)); | 279 self = static_cast<BinaryDelayEstimatorFarend*>( |
| 280 malloc(sizeof(BinaryDelayEstimatorFarend))); |
280 } | 281 } |
281 if (self == NULL) { | 282 if (self == NULL) { |
282 return NULL; | 283 return NULL; |
283 } | 284 } |
284 | 285 |
285 self->history_size = 0; | 286 self->history_size = 0; |
286 self->binary_far_history = NULL; | 287 self->binary_far_history = NULL; |
287 self->far_bit_counts = NULL; | 288 self->far_bit_counts = NULL; |
288 if (WebRtc_AllocateFarendBufferMemory(self, history_size) == 0) { | 289 if (WebRtc_AllocateFarendBufferMemory(self, history_size) == 0) { |
289 WebRtc_FreeBinaryDelayEstimatorFarend(self); | 290 WebRtc_FreeBinaryDelayEstimatorFarend(self); |
290 self = NULL; | 291 self = NULL; |
291 } | 292 } |
292 return self; | 293 return self; |
293 } | 294 } |
294 | 295 |
295 int WebRtc_AllocateFarendBufferMemory(BinaryDelayEstimatorFarend* self, | 296 int WebRtc_AllocateFarendBufferMemory(BinaryDelayEstimatorFarend* self, |
296 int history_size) { | 297 int history_size) { |
297 assert(self != NULL); | 298 assert(self != NULL); |
298 // (Re-)Allocate memory for history buffers. | 299 // (Re-)Allocate memory for history buffers. |
299 self->binary_far_history = | 300 self->binary_far_history = static_cast<uint32_t*>( |
300 realloc(self->binary_far_history, | 301 realloc(self->binary_far_history, |
301 history_size * sizeof(*self->binary_far_history)); | 302 history_size * sizeof(*self->binary_far_history))); |
302 self->far_bit_counts = realloc(self->far_bit_counts, | 303 self->far_bit_counts = static_cast<int*>( |
303 history_size * sizeof(*self->far_bit_counts)); | 304 realloc(self->far_bit_counts, |
| 305 history_size * sizeof(*self->far_bit_counts))); |
304 if ((self->binary_far_history == NULL) || (self->far_bit_counts == NULL)) { | 306 if ((self->binary_far_history == NULL) || (self->far_bit_counts == NULL)) { |
305 history_size = 0; | 307 history_size = 0; |
306 } | 308 } |
307 // Fill with zeros if we have expanded the buffers. | 309 // Fill with zeros if we have expanded the buffers. |
308 if (history_size > self->history_size) { | 310 if (history_size > self->history_size) { |
309 int size_diff = history_size - self->history_size; | 311 int size_diff = history_size - self->history_size; |
310 memset(&self->binary_far_history[self->history_size], | 312 memset(&self->binary_far_history[self->history_size], |
311 0, | 313 0, |
312 sizeof(*self->binary_far_history) * size_diff); | 314 sizeof(*self->binary_far_history) * size_diff); |
313 memset(&self->far_bit_counts[self->history_size], | 315 memset(&self->far_bit_counts[self->history_size], |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 399 |
398 free(self); | 400 free(self); |
399 } | 401 } |
400 | 402 |
401 BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator( | 403 BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator( |
402 BinaryDelayEstimatorFarend* farend, int max_lookahead) { | 404 BinaryDelayEstimatorFarend* farend, int max_lookahead) { |
403 BinaryDelayEstimator* self = NULL; | 405 BinaryDelayEstimator* self = NULL; |
404 | 406 |
405 if ((farend != NULL) && (max_lookahead >= 0)) { | 407 if ((farend != NULL) && (max_lookahead >= 0)) { |
406 // Sanity conditions fulfilled. | 408 // Sanity conditions fulfilled. |
407 self = malloc(sizeof(BinaryDelayEstimator)); | 409 self = static_cast<BinaryDelayEstimator*>( |
| 410 malloc(sizeof(BinaryDelayEstimator))); |
408 } | 411 } |
409 if (self == NULL) { | 412 if (self == NULL) { |
410 return NULL; | 413 return NULL; |
411 } | 414 } |
412 | 415 |
413 self->farend = farend; | 416 self->farend = farend; |
414 self->near_history_size = max_lookahead + 1; | 417 self->near_history_size = max_lookahead + 1; |
415 self->history_size = 0; | 418 self->history_size = 0; |
416 self->robust_validation_enabled = 0; // Disabled by default. | 419 self->robust_validation_enabled = 0; // Disabled by default. |
417 self->allowed_offset = 0; | 420 self->allowed_offset = 0; |
418 | 421 |
419 self->lookahead = max_lookahead; | 422 self->lookahead = max_lookahead; |
420 | 423 |
421 // Allocate memory for spectrum and history buffers. | 424 // Allocate memory for spectrum and history buffers. |
422 self->mean_bit_counts = NULL; | 425 self->mean_bit_counts = NULL; |
423 self->bit_counts = NULL; | 426 self->bit_counts = NULL; |
424 self->histogram = NULL; | 427 self->histogram = NULL; |
425 self->binary_near_history = | 428 self->binary_near_history = static_cast<uint32_t*>( |
426 malloc((max_lookahead + 1) * sizeof(*self->binary_near_history)); | 429 malloc((max_lookahead + 1) * sizeof(*self->binary_near_history))); |
427 if (self->binary_near_history == NULL || | 430 if (self->binary_near_history == NULL || |
428 WebRtc_AllocateHistoryBufferMemory(self, farend->history_size) == 0) { | 431 WebRtc_AllocateHistoryBufferMemory(self, farend->history_size) == 0) { |
429 WebRtc_FreeBinaryDelayEstimator(self); | 432 WebRtc_FreeBinaryDelayEstimator(self); |
430 self = NULL; | 433 self = NULL; |
431 } | 434 } |
432 | 435 |
433 return self; | 436 return self; |
434 } | 437 } |
435 | 438 |
436 int WebRtc_AllocateHistoryBufferMemory(BinaryDelayEstimator* self, | 439 int WebRtc_AllocateHistoryBufferMemory(BinaryDelayEstimator* self, |
437 int history_size) { | 440 int history_size) { |
438 BinaryDelayEstimatorFarend* far = self->farend; | 441 BinaryDelayEstimatorFarend* far = self->farend; |
439 // (Re-)Allocate memory for spectrum and history buffers. | 442 // (Re-)Allocate memory for spectrum and history buffers. |
440 if (history_size != far->history_size) { | 443 if (history_size != far->history_size) { |
441 // Only update far-end buffers if we need. | 444 // Only update far-end buffers if we need. |
442 history_size = WebRtc_AllocateFarendBufferMemory(far, history_size); | 445 history_size = WebRtc_AllocateFarendBufferMemory(far, history_size); |
443 } | 446 } |
444 // The extra array element in |mean_bit_counts| and |histogram| is a dummy | 447 // The extra array element in |mean_bit_counts| and |histogram| is a dummy |
445 // element only used while |last_delay| == -2, i.e., before we have a valid | 448 // element only used while |last_delay| == -2, i.e., before we have a valid |
446 // estimate. | 449 // estimate. |
447 self->mean_bit_counts = | 450 self->mean_bit_counts = static_cast<int32_t*>( |
448 realloc(self->mean_bit_counts, | 451 realloc(self->mean_bit_counts, |
449 (history_size + 1) * sizeof(*self->mean_bit_counts)); | 452 (history_size + 1) * sizeof(*self->mean_bit_counts))); |
450 self->bit_counts = | 453 self->bit_counts = static_cast<int32_t*>( |
451 realloc(self->bit_counts, history_size * sizeof(*self->bit_counts)); | 454 realloc(self->bit_counts, history_size * sizeof(*self->bit_counts))); |
452 self->histogram = | 455 self->histogram = static_cast<float*>( |
453 realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram)); | 456 realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram))); |
454 | 457 |
455 if ((self->mean_bit_counts == NULL) || | 458 if ((self->mean_bit_counts == NULL) || |
456 (self->bit_counts == NULL) || | 459 (self->bit_counts == NULL) || |
457 (self->histogram == NULL)) { | 460 (self->histogram == NULL)) { |
458 history_size = 0; | 461 history_size = 0; |
459 } | 462 } |
460 // Fill with zeros if we have expanded the buffers. | 463 // Fill with zeros if we have expanded the buffers. |
461 if (history_size > self->history_size) { | 464 if (history_size > self->history_size) { |
462 int size_diff = history_size - self->history_size; | 465 int size_diff = history_size - self->history_size; |
463 memset(&self->mean_bit_counts[self->history_size], | 466 memset(&self->mean_bit_counts[self->history_size], |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 int32_t diff = new_value - *mean_value; | 678 int32_t diff = new_value - *mean_value; |
676 | 679 |
677 // mean_new = mean_value + ((new_value - mean_value) >> factor); | 680 // mean_new = mean_value + ((new_value - mean_value) >> factor); |
678 if (diff < 0) { | 681 if (diff < 0) { |
679 diff = -((-diff) >> factor); | 682 diff = -((-diff) >> factor); |
680 } else { | 683 } else { |
681 diff = (diff >> factor); | 684 diff = (diff >> factor); |
682 } | 685 } |
683 *mean_value += diff; | 686 *mean_value += diff; |
684 } | 687 } |
OLD | NEW |