From bdb7af692f48d4cf2a2e7d13c053facdc57df99a Mon Sep 17 00:00:00 2001 From: peah Date: Tue, 12 Apr 2016 14:47:40 -0700 Subject: [PATCH] Changed the delay estimator to be built using C++ BUG=webrtc:5724 NOPRESUBMIT=true Review URL: https://codereview.webrtc.org/1878613002 Cr-Commit-Position: refs/heads/master@{#12336} --- webrtc/modules/audio_processing/BUILD.gn | 4 +-- .../modules/audio_processing/aec/aec_core.cc | 2 -- .../audio_processing/aecm/aecm_core.cc | 3 +- .../audio_processing/aecm/aecm_core_c.cc | 2 +- .../audio_processing/aecm/aecm_core_mips.cc | 2 -- .../audio_processing/audio_processing.gypi | 4 +-- .../{delay_estimator.c => delay_estimator.cc} | 31 ++++++++++--------- .../utility/delay_estimator_unittest.cc | 2 -- ...r_wrapper.c => delay_estimator_wrapper.cc} | 19 ++++++------ 9 files changed, 34 insertions(+), 35 deletions(-) rename webrtc/modules/audio_processing/utility/{delay_estimator.c => delay_estimator.cc} (97%) rename webrtc/modules/audio_processing/utility/{delay_estimator_wrapper.c => delay_estimator_wrapper.cc} (95%) diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index 1060ec8871..006d3a74cd 100644 --- a/webrtc/modules/audio_processing/BUILD.gn +++ b/webrtc/modules/audio_processing/BUILD.gn @@ -110,10 +110,10 @@ source_set("audio_processing") { "typing_detection.h", "utility/block_mean_calculator.cc", "utility/block_mean_calculator.h", - "utility/delay_estimator.c", + "utility/delay_estimator.cc", "utility/delay_estimator.h", "utility/delay_estimator_internal.h", - "utility/delay_estimator_wrapper.c", + "utility/delay_estimator_wrapper.cc", "utility/delay_estimator_wrapper.h", "vad/common.h", "vad/gmm.cc", diff --git a/webrtc/modules/audio_processing/aec/aec_core.cc b/webrtc/modules/audio_processing/aec/aec_core.cc index c4379c6171..27a897a352 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.cc +++ b/webrtc/modules/audio_processing/aec/aec_core.cc @@ -35,9 +35,7 @@ extern "C" { #include "webrtc/modules/audio_processing/aec/aec_rdft.h" } #include "webrtc/modules/audio_processing/logging/aec_logging.h" -extern "C" { #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" -} #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" #include "webrtc/typedefs.h" diff --git a/webrtc/modules/audio_processing/aecm/aecm_core.cc b/webrtc/modules/audio_processing/aecm/aecm_core.cc index 8a5524e04d..efaa7f0a8f 100644 --- a/webrtc/modules/audio_processing/aecm/aecm_core.cc +++ b/webrtc/modules/audio_processing/aecm/aecm_core.cc @@ -19,10 +19,11 @@ extern "C" { #include "webrtc/common_audio/signal_processing/include/real_fft.h" } #include "webrtc/modules/audio_processing/aecm/echo_control_mobile.h" -extern "C" { #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" +extern "C" { #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" } + #include "webrtc/typedefs.h" #ifdef AEC_DEBUG diff --git a/webrtc/modules/audio_processing/aecm/aecm_core_c.cc b/webrtc/modules/audio_processing/aecm/aecm_core_c.cc index 3ee053b092..57f859f550 100644 --- a/webrtc/modules/audio_processing/aecm/aecm_core_c.cc +++ b/webrtc/modules/audio_processing/aecm/aecm_core_c.cc @@ -19,8 +19,8 @@ extern "C" { #include "webrtc/common_audio/signal_processing/include/real_fft.h" } #include "webrtc/modules/audio_processing/aecm/echo_control_mobile.h" -extern "C" { #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" +extern "C" { #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" } #include "webrtc/typedefs.h" diff --git a/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc b/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc index bca32fea1c..e625a46ec5 100644 --- a/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc +++ b/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc @@ -13,9 +13,7 @@ #include #include "webrtc/modules/audio_processing/aecm/echo_control_mobile.h" -extern "C" { #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" -} static const ALIGN8_BEG int16_t WebRtcAecm_kSqrtHanning[] ALIGN8_END = { 0, 399, 798, 1196, 1594, 1990, 2386, 2780, 3172, diff --git a/webrtc/modules/audio_processing/audio_processing.gypi b/webrtc/modules/audio_processing/audio_processing.gypi index 2b47f7e6b0..45b3aa33e5 100644 --- a/webrtc/modules/audio_processing/audio_processing.gypi +++ b/webrtc/modules/audio_processing/audio_processing.gypi @@ -120,10 +120,10 @@ 'typing_detection.h', 'utility/block_mean_calculator.cc', 'utility/block_mean_calculator.h', - 'utility/delay_estimator.c', + 'utility/delay_estimator.cc', 'utility/delay_estimator.h', 'utility/delay_estimator_internal.h', - 'utility/delay_estimator_wrapper.c', + 'utility/delay_estimator_wrapper.cc', 'utility/delay_estimator_wrapper.h', 'vad/common.h', 'vad/gmm.cc', diff --git a/webrtc/modules/audio_processing/utility/delay_estimator.c b/webrtc/modules/audio_processing/utility/delay_estimator.cc similarity index 97% rename from webrtc/modules/audio_processing/utility/delay_estimator.c rename to webrtc/modules/audio_processing/utility/delay_estimator.cc index f9f3dc2457..15a67472b1 100644 --- a/webrtc/modules/audio_processing/utility/delay_estimator.c +++ b/webrtc/modules/audio_processing/utility/delay_estimator.cc @@ -276,7 +276,8 @@ BinaryDelayEstimatorFarend* WebRtc_CreateBinaryDelayEstimatorFarend( if (history_size > 1) { // Sanity conditions fulfilled. - self = malloc(sizeof(BinaryDelayEstimatorFarend)); + self = static_cast( + malloc(sizeof(BinaryDelayEstimatorFarend))); } if (self == NULL) { return NULL; @@ -296,11 +297,12 @@ int WebRtc_AllocateFarendBufferMemory(BinaryDelayEstimatorFarend* self, int history_size) { assert(self != NULL); // (Re-)Allocate memory for history buffers. - self->binary_far_history = + self->binary_far_history = static_cast( realloc(self->binary_far_history, - history_size * sizeof(*self->binary_far_history)); - self->far_bit_counts = realloc(self->far_bit_counts, - history_size * sizeof(*self->far_bit_counts)); + history_size * sizeof(*self->binary_far_history))); + self->far_bit_counts = static_cast( + realloc(self->far_bit_counts, + history_size * sizeof(*self->far_bit_counts))); if ((self->binary_far_history == NULL) || (self->far_bit_counts == NULL)) { history_size = 0; } @@ -404,7 +406,8 @@ BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator( if ((farend != NULL) && (max_lookahead >= 0)) { // Sanity conditions fulfilled. - self = malloc(sizeof(BinaryDelayEstimator)); + self = static_cast( + malloc(sizeof(BinaryDelayEstimator))); } if (self == NULL) { return NULL; @@ -422,8 +425,8 @@ BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator( self->mean_bit_counts = NULL; self->bit_counts = NULL; self->histogram = NULL; - self->binary_near_history = - malloc((max_lookahead + 1) * sizeof(*self->binary_near_history)); + self->binary_near_history = static_cast( + malloc((max_lookahead + 1) * sizeof(*self->binary_near_history))); if (self->binary_near_history == NULL || WebRtc_AllocateHistoryBufferMemory(self, farend->history_size) == 0) { WebRtc_FreeBinaryDelayEstimator(self); @@ -444,13 +447,13 @@ int WebRtc_AllocateHistoryBufferMemory(BinaryDelayEstimator* self, // The extra array element in |mean_bit_counts| and |histogram| is a dummy // element only used while |last_delay| == -2, i.e., before we have a valid // estimate. - self->mean_bit_counts = + self->mean_bit_counts = static_cast( realloc(self->mean_bit_counts, - (history_size + 1) * sizeof(*self->mean_bit_counts)); - self->bit_counts = - realloc(self->bit_counts, history_size * sizeof(*self->bit_counts)); - self->histogram = - realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram)); + (history_size + 1) * sizeof(*self->mean_bit_counts))); + self->bit_counts = static_cast( + realloc(self->bit_counts, history_size * sizeof(*self->bit_counts))); + self->histogram = static_cast( + realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram))); if ((self->mean_bit_counts == NULL) || (self->bit_counts == NULL) || diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc index 4ebe0e6128..3e46763a6a 100644 --- a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc +++ b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc @@ -10,11 +10,9 @@ #include "testing/gtest/include/gtest/gtest.h" -extern "C" { #include "webrtc/modules/audio_processing/utility/delay_estimator.h" #include "webrtc/modules/audio_processing/utility/delay_estimator_internal.h" #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h" -} #include "webrtc/typedefs.h" namespace { diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.cc similarity index 95% rename from webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c rename to webrtc/modules/audio_processing/utility/delay_estimator_wrapper.cc index b5448bc5bd..75c7abea77 100644 --- a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c +++ b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.cc @@ -16,7 +16,6 @@ #include "webrtc/modules/audio_processing/utility/delay_estimator.h" #include "webrtc/modules/audio_processing/utility/delay_estimator_internal.h" -#include "webrtc/system_wrappers/include/compile_assert_c.h" // Only bit |kBandFirst| through bit |kBandLast| are processed and // |kBandFirst| - |kBandLast| must be < 32. @@ -144,10 +143,11 @@ void* WebRtc_CreateDelayEstimatorFarend(int spectrum_size, int history_size) { // Check if the sub band used in the delay estimation is small enough to fit // the binary spectra in a uint32_t. - COMPILE_ASSERT(kBandLast - kBandFirst < 32); + static_assert(kBandLast - kBandFirst < 32, ""); if (spectrum_size >= kBandLast) { - self = malloc(sizeof(DelayEstimatorFarend)); + self = static_cast( + malloc(sizeof(DelayEstimatorFarend))); } if (self != NULL) { @@ -158,7 +158,8 @@ void* WebRtc_CreateDelayEstimatorFarend(int spectrum_size, int history_size) { memory_fail |= (self->binary_farend == NULL); // Allocate memory for spectrum buffers. - self->mean_far_spectrum = malloc(spectrum_size * sizeof(SpectrumType)); + self->mean_far_spectrum = + static_cast(malloc(spectrum_size * sizeof(SpectrumType))); memory_fail |= (self->mean_far_spectrum == NULL); self->spectrum_size = spectrum_size; @@ -275,7 +276,7 @@ void* WebRtc_CreateDelayEstimator(void* farend_handle, int max_lookahead) { DelayEstimatorFarend* farend = (DelayEstimatorFarend*) farend_handle; if (farend_handle != NULL) { - self = malloc(sizeof(DelayEstimator)); + self = static_cast(malloc(sizeof(DelayEstimator))); } if (self != NULL) { @@ -287,8 +288,8 @@ void* WebRtc_CreateDelayEstimator(void* farend_handle, int max_lookahead) { memory_fail |= (self->binary_handle == NULL); // Allocate memory for spectrum buffers. - self->mean_near_spectrum = malloc(farend->spectrum_size * - sizeof(SpectrumType)); + self->mean_near_spectrum = static_cast( + malloc(farend->spectrum_size * sizeof(SpectrumType))); memory_fail |= (self->mean_near_spectrum == NULL); self->spectrum_size = farend->spectrum_size; @@ -328,7 +329,7 @@ int WebRtc_SoftResetDelayEstimator(void* handle, int delay_shift) { } int WebRtc_set_history_size(void* handle, int history_size) { - DelayEstimator* self = handle; + DelayEstimator* self = static_cast(handle); if ((self == NULL) || (history_size <= 1)) { return -1; @@ -337,7 +338,7 @@ int WebRtc_set_history_size(void* handle, int history_size) { } int WebRtc_history_size(const void* handle) { - const DelayEstimator* self = handle; + const DelayEstimator* self = static_cast(handle); if (self == NULL) { return -1;