diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index 58347933e5..454d1be06a 100644 --- a/webrtc/modules/audio_processing/BUILD.gn +++ b/webrtc/modules/audio_processing/BUILD.gn @@ -22,14 +22,14 @@ declare_args() { source_set("audio_processing") { sources = [ - "aec/aec_core.c", + "aec/aec_core.cc", "aec/aec_core.h", "aec/aec_core_internal.h", "aec/aec_rdft.c", "aec/aec_rdft.h", "aec/aec_resampler.c", "aec/aec_resampler.h", - "aec/echo_cancellation.c", + "aec/echo_cancellation.cc", "aec/echo_cancellation.h", "aec/echo_cancellation_internal.h", "aecm/aecm_core.c", @@ -198,7 +198,7 @@ source_set("audio_processing") { sources += [ "aecm/aecm_core_mips.c" ] if (mips_float_abi == "hard") { sources += [ - "aec/aec_core_mips.c", + "aec/aec_core_mips.cc", "aec/aec_rdft_mips.c", ] } @@ -239,7 +239,7 @@ if (rtc_enable_protobuf) { if (current_cpu == "x86" || current_cpu == "x64") { source_set("audio_processing_sse2") { sources = [ - "aec/aec_core_sse2.c", + "aec/aec_core_sse2.cc", "aec/aec_rdft_sse2.c", ] @@ -255,7 +255,7 @@ if (current_cpu == "x86" || current_cpu == "x64") { if (rtc_build_with_neon) { source_set("audio_processing_neon") { sources = [ - "aec/aec_core_neon.c", + "aec/aec_core_neon.cc", "aec/aec_rdft_neon.c", "aecm/aecm_core_neon.c", "ns/nsx_core_neon.c", diff --git a/webrtc/modules/audio_processing/aec/aec_core.c b/webrtc/modules/audio_processing/aec/aec_core.cc similarity index 95% rename from webrtc/modules/audio_processing/aec/aec_core.c rename to webrtc/modules/audio_processing/aec/aec_core.cc index 76a33cec16..2cc2968f81 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.c +++ b/webrtc/modules/audio_processing/aec/aec_core.cc @@ -24,13 +24,19 @@ #include #include +extern "C" { #include "webrtc/common_audio/ring_buffer.h" +} #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_processing/aec/aec_common.h" #include "webrtc/modules/audio_processing/aec/aec_core_internal.h" +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" @@ -43,8 +49,7 @@ static const int countLen = 50; static const int kDelayMetricsAggregationWindow = 1250; // 5 seconds at 16 kHz. // Quantities to control H band scaling for SWB input -static const float cnScaleHband = - (float)0.4; // scale for comfort noise in H band +static const float cnScaleHband = 0.4f; // scale for comfort noise in H band. // Initial bin for averaging nlp gain in low band static const int freqAvgIc = PART_LEN / 2; @@ -416,11 +421,11 @@ static void SubbandCoherence(AecCore* aec, static void GetHighbandGain(const float* lambda, float* nlpGainHband) { int i; - *nlpGainHband = (float)0.0; + *nlpGainHband = 0.0f; for (i = freqAvgIc; i < PART_LEN1 - 1; i++) { *nlpGainHband += lambda[i]; } - *nlpGainHband /= (float)(PART_LEN1 - 1 - freqAvgIc); + *nlpGainHband /= static_cast(PART_LEN1 - 1 - freqAvgIc); } static void ComfortNoise(AecCore* aec, @@ -439,7 +444,7 @@ static void ComfortNoise(AecCore* aec, // Generate a uniform random array on [0 1] WebRtcSpl_RandUArray(randW16, PART_LEN, &aec->seed); for (i = 0; i < PART_LEN; i++) { - rand[i] = ((float)randW16[i]) / 32768; + rand[i] = static_cast(randW16[i]) / 32768; } // Reject LF noise @@ -463,32 +468,34 @@ static void ComfortNoise(AecCore* aec, } // For H band comfort noise - // TODO: don't compute noise and "tmp" twice. Use the previous results. + // TODO(peah): don't compute noise and "tmp" twice. Use the previous results. noiseAvg = 0.0; tmpAvg = 0.0; num = 0; if (aec->num_bands > 1) { // average noise scale // average over second half of freq spectrum (i.e., 4->8khz) - // TODO: we shouldn't need num. We know how many elements we're summing. + // TODO(peah): we shouldn't need num. We know how many elements we're + // summing. for (i = PART_LEN1 >> 1; i < PART_LEN1; i++) { num++; noiseAvg += sqrtf(noisePow[i]); } - noiseAvg /= (float)num; + noiseAvg /= static_cast(num); // average nlp scale // average over second half of freq spectrum (i.e., 4->8khz) - // TODO: we shouldn't need num. We know how many elements we're summing. + // TODO(peah): we shouldn't need num. We know how many elements + // we're summing. num = 0; for (i = PART_LEN1 >> 1; i < PART_LEN1; i++) { num++; tmpAvg += sqrtf(WEBRTC_SPL_MAX(1 - lambda[i] * lambda[i], 0)); } - tmpAvg /= (float)num; + tmpAvg /= static_cast(num); // Use average noise for H band - // TODO: we should probably have a new random vector here. + // TODO(peah): we should probably have a new random vector here. // Reject LF noise u[0][0] = 0; u[1][0] = 0; @@ -496,8 +503,8 @@ static void ComfortNoise(AecCore* aec, tmp = pi2 * rand[i - 1]; // Use average noise for H band - u[0][i] = noiseAvg * (float)cos(tmp); - u[1][i] = -noiseAvg * (float)sin(tmp); + u[0][i] = noiseAvg * static_cast(cos(tmp)); + u[1][i] = -noiseAvg * static_cast(sin(tmp)); } u[1][PART_LEN] = 0; @@ -621,10 +628,12 @@ static void UpdateMetrics(AecCore* aec) { echo = aec->nearlevel.averagelevel - safety * aec->nearlevel.minlevel; // ERL - dtmp = 10 * (float)log10(aec->farlevel.averagelevel / - aec->nearlevel.averagelevel + - 1e-10f); - dtmp2 = 10 * (float)log10(aec->farlevel.averagelevel / echo + 1e-10f); + dtmp = 10 * static_cast(log10(aec->farlevel.averagelevel / + aec->nearlevel.averagelevel + + 1e-10f)); + dtmp2 = 10 * static_cast(log10(aec->farlevel.averagelevel / + echo + + 1e-10f)); aec->erl.instant = dtmp; if (dtmp > aec->erl.max) { @@ -647,14 +656,15 @@ static void UpdateMetrics(AecCore* aec) { } // A_NLP - dtmp = 10 * (float)log10(aec->nearlevel.averagelevel / - aec->linoutlevel.averagelevel + 1e-10f); + dtmp = 10 * static_cast(log10(aec->nearlevel.averagelevel / + aec->linoutlevel.averagelevel + + 1e-10f)); // subtract noise power suppressedEcho = aec->linoutlevel.averagelevel - safety * aec->linoutlevel.minlevel; - dtmp2 = 10 * (float)log10(echo / suppressedEcho + 1e-10f); + dtmp2 = 10 * static_cast(log10(echo / suppressedEcho + 1e-10f)); aec->aNlp.instant = dtmp2; if (dtmp > aec->aNlp.max) { @@ -682,10 +692,10 @@ static void UpdateMetrics(AecCore* aec) { suppressedEcho = 2 * (aec->nlpoutlevel.averagelevel - safety * aec->nlpoutlevel.minlevel); - dtmp = 10 * (float)log10(aec->nearlevel.averagelevel / - (2 * aec->nlpoutlevel.averagelevel) + - 1e-10f); - dtmp2 = 10 * (float)log10(echo / suppressedEcho + 1e-10f); + dtmp = 10 * static_cast(log10(aec->nearlevel.averagelevel / + (2 * aec->nlpoutlevel.averagelevel) + + 1e-10f)); + dtmp2 = 10 * static_cast(log10(echo / suppressedEcho + 1e-10f)); dtmp = dtmp2; aec->erle.instant = dtmp; @@ -751,8 +761,8 @@ static void UpdateDelayMetrics(AecCore* self) { l1_norm += abs(i - median) * self->delay_histogram[i]; } self->delay_std = - (int)((l1_norm + self->num_delay_values / 2) / self->num_delay_values) * - kMsPerBlock; + static_cast((l1_norm + self->num_delay_values / 2) / + self->num_delay_values) * kMsPerBlock; // Determine fraction of delays that are out of bounds, that is, either // negative (anti-causal system) or larger than the AEC filter length. @@ -765,7 +775,7 @@ static void UpdateDelayMetrics(AecCore* self) { num_delays_out_of_bounds -= self->delay_histogram[i]; } self->fraction_poor_delays = - (float)num_delays_out_of_bounds / self->num_delay_values; + static_cast(num_delays_out_of_bounds) / self->num_delay_values; } // Reset histogram. @@ -780,7 +790,7 @@ static void ScaledInverseFft(float freq_data[2][PART_LEN1], float scale, int conjugate) { int i; - const float normalization = scale / ((float)PART_LEN2); + const float normalization = scale / static_cast(PART_LEN2); const float sign = (conjugate ? -1 : 1); time_data[0] = freq_data[0][0] * normalization; time_data[1] = freq_data[0][PART_LEN] * normalization; @@ -844,7 +854,8 @@ static int SignalBasedDelayCorrection(AecCore* self) { const int upper_bound = self->num_partitions * 3 / 4; const int do_correction = delay <= lower_bound || delay > upper_bound; if (do_correction == 1) { - int available_read = (int)WebRtc_available_read(self->far_time_buf); + int available_read = + static_cast(WebRtc_available_read(self->far_time_buf)); // With |shift_offset| we gradually rely on the delay estimates. For // positive delays we reduce the correction by |shift_offset| to lower the // risk of pushing the AEC into a non causal state. For negative delays @@ -1079,11 +1090,14 @@ static void EchoSuppression(AecCore* aec, } // Select an order statistic from the preferred bands. - // TODO: Using quicksort now, but a selection algorithm may be preferred. + // TODO(peah): Using quicksort now, but a selection algorithm may be + // preferred. memcpy(hNlPref, &hNl[minPrefBand], sizeof(float) * prefBandSize); qsort(hNlPref, prefBandSize, sizeof(float), CmpFloat); - hNlFb = hNlPref[(int)floor(prefBandQuant * (prefBandSize - 1))]; - hNlFbLow = hNlPref[(int)floor(prefBandQuantLow * (prefBandSize - 1))]; + hNlFb = hNlPref[static_cast(floor(prefBandQuant * + (prefBandSize - 1)))]; + hNlFbLow = hNlPref[static_cast(floor(prefBandQuantLow * + (prefBandSize - 1)))]; } } @@ -1106,7 +1120,7 @@ static void EchoSuppression(AecCore* aec, aec->hNlMinCtr = 0; aec->overDrive = WEBRTC_SPL_MAX(kTargetSupp[aec->nlp_mode] / - ((float)log(aec->hNlFbMin + 1e-10f) + 1e-10f), + static_cast(log(aec->hNlFbMin + 1e-10f) + 1e-10f), min_overdrive[aec->nlp_mode]); } @@ -1225,16 +1239,19 @@ static void ProcessBlock(AecCore* aec) { // Concatenate old and new nearend blocks. for (i = 0; i < aec->num_bands - 1; ++i) { - WebRtc_ReadBuffer(aec->nearFrBufH[i], (void**)&nearend_ptr, nearend, - PART_LEN); + WebRtc_ReadBuffer(aec->nearFrBufH[i], + reinterpret_cast(&nearend_ptr), + nearend, PART_LEN); memcpy(aec->dBufH[i] + PART_LEN, nearend_ptr, sizeof(nearend)); } - WebRtc_ReadBuffer(aec->nearFrBuf, (void**)&nearend_ptr, nearend, PART_LEN); + WebRtc_ReadBuffer(aec->nearFrBuf, reinterpret_cast(&nearend_ptr), + nearend, PART_LEN); memcpy(aec->dBuf + PART_LEN, nearend_ptr, sizeof(nearend)); // We should always have at least one element stored in |far_buf|. assert(WebRtc_available_read(aec->far_time_buf) > 0); - WebRtc_ReadBuffer(aec->far_time_buf, (void**)&farend_ptr, farend, 1); + WebRtc_ReadBuffer(aec->far_time_buf, reinterpret_cast(&farend_ptr), + farend, 1); #ifdef WEBRTC_AEC_DEBUG_DUMP { @@ -1356,7 +1373,7 @@ static void ProcessBlock(AecCore* aec) { AecCore* WebRtcAec_CreateAec() { int i; - AecCore* aec = malloc(sizeof(AecCore)); + AecCore* aec = reinterpret_cast(malloc(sizeof(AecCore))); if (!aec) { return NULL; } @@ -1585,7 +1602,7 @@ int WebRtcAec_InitAec(AecCore* aec, int sampFreq) { if (aec->num_bands > 1) { aec->mult = 2; } else { - aec->mult = (short)aec->sampFreq / 8000; + aec->mult = static_cast(aec->sampFreq) / 8000; } aec->farBufWritePos = 0; @@ -1616,8 +1633,8 @@ int WebRtcAec_InitAec(AecCore* aec, int sampFreq) { // Holds the last block written to aec->xfBufBlockPos = 0; - // TODO: Investigate need for these initializations. Deleting them doesn't - // change the output at all and yields 0.4% overall speedup. + // TODO(peah): Investigate need for these initializations. Deleting them + // doesn't change the output at all and yields 0.4% overall speedup. memset(aec->xfBuf, 0, sizeof(complex_t) * kExtendedNumPartitions * PART_LEN1); memset(aec->wfBuf, 0, sizeof(complex_t) * kExtendedNumPartitions * PART_LEN1); memset(aec->sde, 0, sizeof(complex_t) * PART_LEN1); @@ -1782,7 +1799,7 @@ void WebRtcAec_ProcessFrames(AecCore* aec, // 6) Update output frame. // Stuff the out buffer if we have less than a frame to output. // This should only happen for the first frame. - out_elements = (int)WebRtc_available_read(aec->outFrBuf); + out_elements = static_cast(WebRtc_available_read(aec->outFrBuf)); if (out_elements < FRAME_LEN) { WebRtc_MoveReadPtr(aec->outFrBuf, out_elements - FRAME_LEN); for (i = 0; i < num_bands - 1; ++i) { diff --git a/webrtc/modules/audio_processing/aec/aec_core_internal.h b/webrtc/modules/audio_processing/aec/aec_core_internal.h index 6758d0a578..b2e7301724 100644 --- a/webrtc/modules/audio_processing/aec/aec_core_internal.h +++ b/webrtc/modules/audio_processing/aec/aec_core_internal.h @@ -11,7 +11,9 @@ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_ +extern "C" { #include "webrtc/common_audio/ring_buffer.h" +} #include "webrtc/common_audio/wav_file.h" #include "webrtc/modules/audio_processing/aec/aec_common.h" #include "webrtc/modules/audio_processing/aec/aec_core.h" diff --git a/webrtc/modules/audio_processing/aec/aec_core_mips.c b/webrtc/modules/audio_processing/aec/aec_core_mips.cc similarity index 94% rename from webrtc/modules/audio_processing/aec/aec_core_mips.c rename to webrtc/modules/audio_processing/aec/aec_core_mips.cc index 4fbc6137e2..61111e4e19 100644 --- a/webrtc/modules/audio_processing/aec/aec_core_mips.c +++ b/webrtc/modules/audio_processing/aec/aec_core_mips.cc @@ -16,9 +16,13 @@ #include +extern "C" { #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +} #include "webrtc/modules/audio_processing/aec/aec_core_internal.h" +extern "C" { #include "webrtc/modules/audio_processing/aec/aec_rdft.h" +} extern const float WebRtcAec_weightCurve[65]; extern const float WebRtcAec_overDriveCurve[65]; @@ -45,7 +49,7 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, int32_t tmp1s, tmp2s, tmp3s, tmp4s; for (i = 0; i < PART_LEN; i += 4) { - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" "lh %[tmp1s], 0(%[randWptr]) \n\t" @@ -72,8 +76,7 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, [tmp2s] "=&r" (tmp2s), [tmp3s] "=&r" (tmp3s), [tmp4s] "=&r" (tmp4s) : [pi2t] "f" (pi2t) - : "memory" - ); + : "memory"); u[i + 1][0] = cosf(randTemp); u[i + 1][1] = sinf(randTemp); @@ -93,7 +96,7 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, u[0][0] = 0; u[0][1] = 0; for (i = 1; i < PART_LEN1; i += 4) { - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" "lwc1 %[noise], 4(%[noisePow]) \n\t" @@ -143,8 +146,7 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, [tmp5f] "=&f" (tmp5f), [tmp6f] "=&f" (tmp6f), [tmp7f] "=&f" (tmp7f), [tmp8f] "=&f" (tmp8f) : - : "memory" - ); + : "memory"); } u[PART_LEN][1] = 0; noisePow -= PART_LEN; @@ -156,10 +158,10 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, float tmp9f, tmp10f; const float tmp1c = 1.0; - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" - "1: \n\t" + "1: \n\t" "lwc1 %[tmp1f], 0(%[lambda]) \n\t" "lwc1 %[tmp6f], 4(%[lambda]) \n\t" "addiu %[lambda], %[lambda], 8 \n\t" @@ -169,7 +171,7 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, "c.lt.s %[tmp6f], %[tmp1c] \n\t" "bc1f 3f \n\t" " nop \n\t" - "2: \n\t" + "2: \n\t" "mul.s %[tmp1f], %[tmp1f], %[tmp1f] \n\t" "mul.s %[tmp6f], %[tmp6f], %[tmp6f] \n\t" "sub.s %[tmp1f], %[tmp1c], %[tmp1f] \n\t" @@ -193,18 +195,18 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, "add.s %[tmp7f], %[tmp7f], %[tmp3f] \n\t" "mul.s %[tmp3f], %[tmp6f], %[tmp10f] \n\t" "add.s %[tmp9f], %[tmp9f], %[tmp3f] \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "madd.s %[tmp2f], %[tmp2f], %[tmp1f], %[tmp3f] \n\t" "madd.s %[tmp4f], %[tmp4f], %[tmp1f], %[tmp5f] \n\t" "madd.s %[tmp7f], %[tmp7f], %[tmp6f], %[tmp8f] \n\t" "madd.s %[tmp9f], %[tmp9f], %[tmp6f], %[tmp10f] \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "swc1 %[tmp2f], 0(%[efw_ptr_0]) \n\t" "swc1 %[tmp4f], 0(%[efw_ptr_1]) \n\t" "swc1 %[tmp7f], 4(%[efw_ptr_0]) \n\t" "b 5f \n\t" " swc1 %[tmp9f], 4(%[efw_ptr_1]) \n\t" - "3: \n\t" + "3: \n\t" "mul.s %[tmp1f], %[tmp1f], %[tmp1f] \n\t" "sub.s %[tmp1f], %[tmp1c], %[tmp1f] \n\t" "sqrt.s %[tmp1f], %[tmp1f] \n\t" @@ -217,14 +219,14 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, "add.s %[tmp2f], %[tmp2f], %[tmp3f] \n\t" "mul.s %[tmp3f], %[tmp1f], %[tmp5f] \n\t" "add.s %[tmp4f], %[tmp4f], %[tmp3f] \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "madd.s %[tmp2f], %[tmp2f], %[tmp1f], %[tmp3f] \n\t" "madd.s %[tmp4f], %[tmp4f], %[tmp1f], %[tmp5f] \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "swc1 %[tmp2f], 0(%[efw_ptr_0]) \n\t" "b 5f \n\t" " swc1 %[tmp4f], 0(%[efw_ptr_1]) \n\t" - "4: \n\t" + "4: \n\t" "c.lt.s %[tmp6f], %[tmp1c] \n\t" "bc1f 5f \n\t" " nop \n\t" @@ -240,13 +242,13 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, "add.s %[tmp7f], %[tmp7f], %[tmp3f] \n\t" "mul.s %[tmp3f], %[tmp6f], %[tmp10f] \n\t" "add.s %[tmp9f], %[tmp9f], %[tmp3f] \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "madd.s %[tmp7f], %[tmp7f], %[tmp6f], %[tmp8f] \n\t" "madd.s %[tmp9f], %[tmp9f], %[tmp6f], %[tmp10f] \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "swc1 %[tmp7f], 4(%[efw_ptr_0]) \n\t" "swc1 %[tmp9f], 4(%[efw_ptr_1]) \n\t" - "5: \n\t" + "5: \n\t" "addiu %[u_ptr], %[u_ptr], 16 \n\t" "addiu %[efw_ptr_0], %[efw_ptr_0], 8 \n\t" "bne %[u_ptr], %[u_ptr_end], 1b \n\t" @@ -259,8 +261,7 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, [tmp6f] "=&f" (tmp6f), [tmp7f] "=&f" (tmp7f), [tmp8f] "=&f" (tmp8f), [tmp9f] "=&f" (tmp9f), [tmp10f] "=&f" (tmp10f) : [tmp1c] "f" (tmp1c), [u_ptr_end] "r" (u_ptr_end) - : "memory" - ); + : "memory"); lambda -= PART_LEN; tmp = sqrtf(WEBRTC_SPL_MAX(1 - lambda[PART_LEN] * lambda[PART_LEN], 0)); @@ -269,36 +270,38 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, efw[1][PART_LEN] += tmp * u[PART_LEN][1]; // For H band comfort noise - // TODO: don't compute noise and "tmp" twice. Use the previous results. + // TODO(peah): don't compute noise and "tmp" twice. Use the previous results. noiseAvg = 0.0; tmpAvg = 0.0; num = 0; if (aec->num_bands > 1) { for (i = 0; i < PART_LEN; i++) { - rand[i] = ((float)randW16[i]) / 32768; + rand[i] = (static_cast(randW16[i])) / 32768; } // average noise scale // average over second half of freq spectrum (i.e., 4->8khz) - // TODO: we shouldn't need num. We know how many elements we're summing. + // TODO(peah): we shouldn't need num. We know how many elements we're + // summing. for (i = PART_LEN1 >> 1; i < PART_LEN1; i++) { num++; noiseAvg += sqrtf(noisePow[i]); } - noiseAvg /= (float)num; + noiseAvg /= static_cast(num); // average nlp scale // average over second half of freq spectrum (i.e., 4->8khz) - // TODO: we shouldn't need num. We know how many elements we're summing. + // TODO(peah): we shouldn't need num. We know how many elements we're + // summing. num = 0; for (i = PART_LEN1 >> 1; i < PART_LEN1; i++) { num++; tmpAvg += sqrtf(WEBRTC_SPL_MAX(1 - lambda[i] * lambda[i], 0)); } - tmpAvg /= (float)num; + tmpAvg /= static_cast(num); // Use average noise for H band - // TODO: we should probably have a new random vector here. + // TODO(peah): we should probably have a new random vector here. // Reject LF noise u[0][0] = 0; u[0][1] = 0; @@ -306,8 +309,8 @@ void WebRtcAec_ComfortNoise_mips(AecCore* aec, tmp = pi2 * rand[i - 1]; // Use average noise for H band - u[i][0] = noiseAvg * (float)cos(tmp); - u[i][1] = -noiseAvg * (float)sin(tmp); + u[i][0] = noiseAvg * static_cast(cos(tmp)); + u[i][1] = -noiseAvg * static_cast(sin(tmp)); } u[PART_LEN][1] = 0; @@ -345,10 +348,10 @@ void WebRtcAec_FilterFar_mips( float f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13; int len = PART_LEN1 >> 1; - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" - "1: \n\t" + "1: \n\t" "lwc1 %[f0], 0(%[aRe]) \n\t" "lwc1 %[f1], 0(%[bRe]) \n\t" "lwc1 %[f2], 0(%[bIm]) \n\t" @@ -376,7 +379,7 @@ void WebRtcAec_FilterFar_mips( "sub.s %[f9], %[f9], %[f11] \n\t" "lwc1 %[f6], 4(%[yf0]) \n\t" "add.s %[f4], %[f4], %[f12] \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "addiu %[aRe], %[aRe], 8 \n\t" "addiu %[aIm], %[aIm], 8 \n\t" "addiu %[len], %[len], -1 \n\t" @@ -387,7 +390,7 @@ void WebRtcAec_FilterFar_mips( "nmsub.s %[f9], %[f9], %[f6], %[f7] \n\t" "lwc1 %[f6], 4(%[yf0]) \n\t" "madd.s %[f4], %[f4], %[f7], %[f5] \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "lwc1 %[f5], 4(%[yf1]) \n\t" "add.s %[f2], %[f2], %[f8] \n\t" "addiu %[bRe], %[bRe], 8 \n\t" @@ -415,12 +418,12 @@ void WebRtcAec_FilterFar_mips( "lwc1 %[f2], 0(%[yf0]) \n\t" "add.s %[f1], %[f0], %[f1] \n\t" "lwc1 %[f3], 0(%[yf1]) \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "nmsub.s %[f8], %[f8], %[f2], %[f3] \n\t" "lwc1 %[f2], 0(%[yf0]) \n\t" "madd.s %[f1], %[f0], %[f3], %[f1] \n\t" "lwc1 %[f3], 0(%[yf1]) \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "add.s %[f2], %[f2], %[f8] \n\t" "add.s %[f3], %[f3], %[f1] \n\t" "swc1 %[f2], 0(%[yf0]) \n\t" @@ -434,8 +437,7 @@ void WebRtcAec_FilterFar_mips( [aIm] "+r" (aIm), [bRe] "+r" (bRe), [bIm] "+r" (bIm), [yf0] "+r" (yf0), [yf1] "+r" (yf1), [len] "+r" (len) : - : "memory" - ); + : "memory"); } } @@ -465,11 +467,11 @@ void WebRtcAec_FilterAdaptation_mips( float f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12; int len = PART_LEN >> 1; - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" "addiu %[fft_tmp], %[fft], 0 \n\t" - "1: \n\t" + "1: \n\t" "lwc1 %[f0], 0(%[aRe]) \n\t" "lwc1 %[f1], 0(%[bRe]) \n\t" "lwc1 %[f2], 0(%[bIm]) \n\t" @@ -496,7 +498,7 @@ void WebRtcAec_FilterAdaptation_mips( "sub.s %[f1], %[f0], %[f1] \n\t" "add.s %[f9], %[f9], %[f11] \n\t" "sub.s %[f5], %[f4], %[f5] \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "addiu %[aIm], %[aIm], 8 \n\t" "addiu %[bIm], %[bIm], 8 \n\t" "addiu %[len], %[len], -1 \n\t" @@ -504,7 +506,7 @@ void WebRtcAec_FilterAdaptation_mips( "nmsub.s %[f1], %[f0], %[f3], %[f1] \n\t" "madd.s %[f9], %[f9], %[f7], %[f6] \n\t" "nmsub.s %[f5], %[f4], %[f7], %[f5] \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "swc1 %[f8], 0(%[fft_tmp]) \n\t" "swc1 %[f1], 4(%[fft_tmp]) \n\t" "swc1 %[f9], 8(%[fft_tmp]) \n\t" @@ -519,9 +521,9 @@ void WebRtcAec_FilterAdaptation_mips( #if !defined(MIPS32_R2_LE) "mul.s %[f10], %[f3], %[f2] \n\t" "add.s %[f8], %[f8], %[f10] \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "madd.s %[f8], %[f8], %[f3], %[f2] \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "swc1 %[f8], 4(%[fft]) \n\t" ".set pop \n\t" : [f0] "=&f" (f0), [f1] "=&f" (f1), [f2] "=&f" (f2), @@ -532,8 +534,7 @@ void WebRtcAec_FilterAdaptation_mips( [bRe] "+r" (bRe), [bIm] "+r" (bIm), [fft_tmp] "=&r" (fft_tmp), [len] "+r" (len) : [fft] "r" (fft) - : "memory" - ); + : "memory"); aec_rdft_inverse_128(fft); memset(fft + PART_LEN, 0, sizeof(float) * PART_LEN); @@ -541,12 +542,12 @@ void WebRtcAec_FilterAdaptation_mips( // fft scaling { float scale = 2.0f / PART_LEN2; - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" "addiu %[fft_tmp], %[fft], 0 \n\t" "addiu %[len], $zero, 8 \n\t" - "1: \n\t" + "1: \n\t" "addiu %[len], %[len], -1 \n\t" "lwc1 %[f0], 0(%[fft_tmp]) \n\t" "lwc1 %[f1], 4(%[fft_tmp]) \n\t" @@ -580,13 +581,12 @@ void WebRtcAec_FilterAdaptation_mips( [f6] "=&f" (f6), [f7] "=&f" (f7), [len] "=&r" (len), [fft_tmp] "=&r" (fft_tmp) : [scale] "f" (scale), [fft] "r" (fft) - : "memory" - ); + : "memory"); } aec_rdft_forward_128(fft); aRe = h_fft_buf[0] + pos; aIm = h_fft_buf[1] + pos; - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" "addiu %[fft_tmp], %[fft], 0 \n\t" @@ -610,7 +610,7 @@ void WebRtcAec_FilterAdaptation_mips( "addiu %[aRe], %[aRe], 8 \n\t" "swc1 %[f6], 4(%[aIm]) \n\t" "addiu %[aIm], %[aIm], 8 \n\t" - "1: \n\t" + "1: \n\t" "lwc1 %[f0], 0(%[aRe]) \n\t" "lwc1 %[f1], 0(%[fft_tmp]) \n\t" "lwc1 %[f2], 0(%[aIm]) \n\t" @@ -638,8 +638,7 @@ void WebRtcAec_FilterAdaptation_mips( [f6] "=&f" (f6), [f7] "=&f" (f7), [len] "=&r" (len), [fft_tmp] "=&r" (fft_tmp), [aRe] "+r" (aRe), [aIm] "+r" (aIm) : [fft] "r" (fft) - : "memory" - ); + : "memory"); } } @@ -658,11 +657,11 @@ void WebRtcAec_OverdriveAndSuppress_mips(AecCore* aec, p_hNl = &hNl[0]; p_efw0 = &efw[0][0]; p_efw1 = &efw[1][0]; - p_WebRtcAec_wC = (float*)&WebRtcAec_weightCurve[0]; + p_WebRtcAec_wC = reinterpret_cast(&WebRtcAec_weightCurve[0]); for (i = 0; i < PART_LEN1; i++) { // Weight subbands - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" "lwc1 %[temp1], 0(%[p_hNl]) \n\t" @@ -674,9 +673,9 @@ void WebRtcAec_OverdriveAndSuppress_mips(AecCore* aec, #if !defined(MIPS32_R2_LE) "mul.s %[temp1], %[temp1], %[temp4] \n\t" "add.s %[temp1], %[temp3], %[temp1] \n\t" -#else // #if !defined(MIPS32_R2_LE) +#else // #if !defined(MIPS32_R2_LE) "madd.s %[temp1], %[temp3], %[temp1], %[temp4] \n\t" -#endif // #if !defined(MIPS32_R2_LE) +#endif // #if !defined(MIPS32_R2_LE) "swc1 %[temp1], 0(%[p_hNl]) \n\t" "1: \n\t" "addiu %[p_wC], %[p_wC], 4 \n\t" @@ -684,12 +683,11 @@ void WebRtcAec_OverdriveAndSuppress_mips(AecCore* aec, : [temp1] "=&f" (temp1), [temp2] "=&f" (temp2), [temp3] "=&f" (temp3), [temp4] "=&f" (temp4), [p_wC] "+r" (p_WebRtcAec_wC) : [hNlFb] "f" (hNlFb), [one] "f" (one), [p_hNl] "r" (p_hNl) - : "memory" - ); + : "memory"); hNl[i] = powf(hNl[i], aec->overDriveSm * WebRtcAec_overDriveCurve[i]); - __asm __volatile ( + __asm __volatile( "lwc1 %[temp1], 0(%[p_hNl]) \n\t" "lwc1 %[temp3], 0(%[p_efw1]) \n\t" "lwc1 %[temp2], 0(%[p_efw0]) \n\t" @@ -705,8 +703,7 @@ void WebRtcAec_OverdriveAndSuppress_mips(AecCore* aec, [temp4] "=&f" (temp4), [p_efw0] "+r" (p_efw0), [p_efw1] "+r" (p_efw1), [p_hNl] "+r" (p_hNl) : - : "memory" - ); + : "memory"); } } @@ -729,10 +726,10 @@ void WebRtcAec_ScaleErrorSignal_mips(int extended_filter_enabled, float f3; #endif - __asm __volatile ( + __asm __volatile( ".set push \n\t" ".set noreorder \n\t" - "1: \n\t" + "1: \n\t" "lwc1 %[f0], 0(%[x_pow]) \n\t" "lwc1 %[f1], 0(%[ef0]) \n\t" "lwc1 %[f2], 0(%[ef1]) \n\t" @@ -755,7 +752,7 @@ void WebRtcAec_ScaleErrorSignal_mips(int extended_filter_enabled, "div.s %[f0], %[err_th], %[f0] \n\t" "mul.s %[f1], %[f1], %[f0] \n\t" "mul.s %[f2], %[f2], %[f0] \n\t" - "2: \n\t" + "2: \n\t" "mul.s %[f1], %[f1], %[mu] \n\t" "mul.s %[f2], %[f2], %[mu] \n\t" "swc1 %[f1], 0(%[ef0]) \n\t" @@ -774,8 +771,7 @@ void WebRtcAec_ScaleErrorSignal_mips(int extended_filter_enabled, [len] "+r" (len) : [fac1] "f" (fac1), [err_th2] "f" (err_th2), [mu] "f" (mu), [err_th] "f" (error_threshold) - : "memory" - ); + : "memory"); } void WebRtcAec_InitAec_mips(void) { diff --git a/webrtc/modules/audio_processing/aec/aec_core_neon.c b/webrtc/modules/audio_processing/aec/aec_core_neon.cc similarity index 99% rename from webrtc/modules/audio_processing/aec/aec_core_neon.c rename to webrtc/modules/audio_processing/aec/aec_core_neon.cc index 38c043a20b..ba374b21ab 100644 --- a/webrtc/modules/audio_processing/aec/aec_core_neon.c +++ b/webrtc/modules/audio_processing/aec/aec_core_neon.cc @@ -18,10 +18,14 @@ #include #include // memset +extern "C" { #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +} #include "webrtc/modules/audio_processing/aec/aec_common.h" #include "webrtc/modules/audio_processing/aec/aec_core_internal.h" +extern "C" { #include "webrtc/modules/audio_processing/aec/aec_rdft.h" +} enum { kShiftExponentIntoTopMantissa = 8 }; enum { kFloatExponentShift = 23 }; @@ -120,7 +124,6 @@ static float32x4_t vsqrtq_f32(float32x4_t s) { } // sqrt(s) = s * 1/sqrt(s) return vmulq_f32(s, x); - ; } #endif // WEBRTC_ARCH_ARM64 diff --git a/webrtc/modules/audio_processing/aec/aec_core_sse2.c b/webrtc/modules/audio_processing/aec/aec_core_sse2.cc similarity index 93% rename from webrtc/modules/audio_processing/aec/aec_core_sse2.c rename to webrtc/modules/audio_processing/aec/aec_core_sse2.cc index 1e86b92e34..bf194a400f 100644 --- a/webrtc/modules/audio_processing/aec/aec_core_sse2.c +++ b/webrtc/modules/audio_processing/aec/aec_core_sse2.cc @@ -16,10 +16,14 @@ #include #include // memset +extern "C" { #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +} #include "webrtc/modules/audio_processing/aec/aec_common.h" #include "webrtc/modules/audio_processing/aec/aec_core_internal.h" +extern "C" { #include "webrtc/modules/audio_processing/aec/aec_rdft.h" +} __inline static float MulRe(float aRe, float aIm, float bRe, float bIm) { return aRe * bRe - aIm * bIm; @@ -256,20 +260,25 @@ static __m128 mm_pow_ps(__m128 a, __m128 b) { static const ALIGN16_BEG int implicit_leading_one[4] ALIGN16_END = { 0x43BF8000, 0x43BF8000, 0x43BF8000, 0x43BF8000}; static const int shift_exponent_into_top_mantissa = 8; - const __m128 two_n = _mm_and_ps(a, *((__m128*)float_exponent_mask)); + const __m128 two_n = + _mm_and_ps(a, *(reinterpret_cast(float_exponent_mask))); const __m128 n_1 = _mm_castsi128_ps(_mm_srli_epi32( _mm_castps_si128(two_n), shift_exponent_into_top_mantissa)); - const __m128 n_0 = _mm_or_ps(n_1, *((__m128*)eight_biased_exponent)); - const __m128 n = _mm_sub_ps(n_0, *((__m128*)implicit_leading_one)); + const __m128 n_0 = + _mm_or_ps(n_1, *(reinterpret_cast(eight_biased_exponent))); + const __m128 n = + _mm_sub_ps(n_0, *(reinterpret_cast(implicit_leading_one))); // Compute y. static const ALIGN16_BEG int mantissa_mask[4] ALIGN16_END = { 0x007FFFFF, 0x007FFFFF, 0x007FFFFF, 0x007FFFFF}; static const ALIGN16_BEG int zero_biased_exponent_is_one[4] ALIGN16_END = { 0x3F800000, 0x3F800000, 0x3F800000, 0x3F800000}; - const __m128 mantissa = _mm_and_ps(a, *((__m128*)mantissa_mask)); + const __m128 mantissa = + _mm_and_ps(a, *(reinterpret_cast(mantissa_mask))); const __m128 y = - _mm_or_ps(mantissa, *((__m128*)zero_biased_exponent_is_one)); + _mm_or_ps(mantissa, + *(reinterpret_cast(zero_biased_exponent_is_one))); // Approximate log2(y) ~= (y - 1) * pol5(y). // pol5(y) = C5 * y^5 + C4 * y^4 + C3 * y^3 + C2 * y^2 + C1 * y + C0 @@ -285,18 +294,25 @@ static __m128 mm_pow_ps(__m128 a, __m128 b) { -3.3241990f, -3.3241990f, -3.3241990f, -3.3241990f}; static const ALIGN16_BEG float ALIGN16_END C0[4] = {3.1157899f, 3.1157899f, 3.1157899f, 3.1157899f}; - const __m128 pol5_y_0 = _mm_mul_ps(y, *((__m128*)C5)); - const __m128 pol5_y_1 = _mm_add_ps(pol5_y_0, *((__m128*)C4)); + const __m128 pol5_y_0 = + _mm_mul_ps(y, *(reinterpret_cast(C5))); + const __m128 pol5_y_1 = + _mm_add_ps(pol5_y_0, *(reinterpret_cast(C4))); const __m128 pol5_y_2 = _mm_mul_ps(pol5_y_1, y); - const __m128 pol5_y_3 = _mm_add_ps(pol5_y_2, *((__m128*)C3)); + const __m128 pol5_y_3 = + _mm_add_ps(pol5_y_2, *(reinterpret_cast(C3))); const __m128 pol5_y_4 = _mm_mul_ps(pol5_y_3, y); - const __m128 pol5_y_5 = _mm_add_ps(pol5_y_4, *((__m128*)C2)); + const __m128 pol5_y_5 = + _mm_add_ps(pol5_y_4, *(reinterpret_cast(C2))); const __m128 pol5_y_6 = _mm_mul_ps(pol5_y_5, y); - const __m128 pol5_y_7 = _mm_add_ps(pol5_y_6, *((__m128*)C1)); + const __m128 pol5_y_7 = + _mm_add_ps(pol5_y_6, *(reinterpret_cast(C1))); const __m128 pol5_y_8 = _mm_mul_ps(pol5_y_7, y); - const __m128 pol5_y = _mm_add_ps(pol5_y_8, *((__m128*)C0)); + const __m128 pol5_y = + _mm_add_ps(pol5_y_8, *(reinterpret_cast(C0))); const __m128 y_minus_one = - _mm_sub_ps(y, *((__m128*)zero_biased_exponent_is_one)); + _mm_sub_ps(y, + *(reinterpret_cast(zero_biased_exponent_is_one))); const __m128 log2_y = _mm_mul_ps(y_minus_one, pol5_y); // Combine parts. @@ -325,19 +341,23 @@ static __m128 mm_pow_ps(__m128 a, __m128 b) { 129.f, 129.f}; static const ALIGN16_BEG float min_input[4] ALIGN16_END = { -126.99999f, -126.99999f, -126.99999f, -126.99999f}; - const __m128 x_min = _mm_min_ps(b_log2_a, *((__m128*)max_input)); - const __m128 x_max = _mm_max_ps(x_min, *((__m128*)min_input)); + const __m128 x_min = + _mm_min_ps(b_log2_a, *(reinterpret_cast(max_input))); + const __m128 x_max = + _mm_max_ps(x_min, *(reinterpret_cast(min_input))); // Compute n. static const ALIGN16_BEG float half[4] ALIGN16_END = {0.5f, 0.5f, 0.5f, 0.5f}; - const __m128 x_minus_half = _mm_sub_ps(x_max, *((__m128*)half)); + const __m128 x_minus_half = + _mm_sub_ps(x_max, *(reinterpret_cast(half))); const __m128i x_minus_half_floor = _mm_cvtps_epi32(x_minus_half); // Compute 2^n. static const ALIGN16_BEG int float_exponent_bias[4] ALIGN16_END = { 127, 127, 127, 127}; static const int float_exponent_shift = 23; const __m128i two_n_exponent = - _mm_add_epi32(x_minus_half_floor, *((__m128i*)float_exponent_bias)); + _mm_add_epi32(x_minus_half_floor, + *(reinterpret_cast(float_exponent_bias))); const __m128 two_n = _mm_castsi128_ps(_mm_slli_epi32(two_n_exponent, float_exponent_shift)); // Compute y. @@ -349,10 +369,13 @@ static __m128 mm_pow_ps(__m128 a, __m128 b) { 6.5763628e-1f, 6.5763628e-1f, 6.5763628e-1f, 6.5763628e-1f}; static const ALIGN16_BEG float C0[4] ALIGN16_END = {1.0017247f, 1.0017247f, 1.0017247f, 1.0017247f}; - const __m128 exp2_y_0 = _mm_mul_ps(y, *((__m128*)C2)); - const __m128 exp2_y_1 = _mm_add_ps(exp2_y_0, *((__m128*)C1)); + const __m128 exp2_y_0 = + _mm_mul_ps(y, *(reinterpret_cast(C2))); + const __m128 exp2_y_1 = + _mm_add_ps(exp2_y_0, *(reinterpret_cast(C1))); const __m128 exp2_y_2 = _mm_mul_ps(exp2_y_1, y); - const __m128 exp2_y = _mm_add_ps(exp2_y_2, *((__m128*)C0)); + const __m128 exp2_y = + _mm_add_ps(exp2_y_2, *(reinterpret_cast(C0))); // Combine parts. a_exp_b = _mm_mul_ps(exp2_y, two_n); diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.c b/webrtc/modules/audio_processing/aec/echo_cancellation.cc similarity index 93% rename from webrtc/modules/audio_processing/aec/echo_cancellation.c rename to webrtc/modules/audio_processing/aec/echo_cancellation.cc index 5a30cc3ce4..8bbf151155 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation.c +++ b/webrtc/modules/audio_processing/aec/echo_cancellation.cc @@ -20,10 +20,14 @@ #include #include +extern "C" { #include "webrtc/common_audio/ring_buffer.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +} #include "webrtc/modules/audio_processing/aec/aec_core.h" +extern "C" { #include "webrtc/modules/audio_processing/aec/aec_resampler.h" +} #include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h" #include "webrtc/typedefs.h" @@ -119,7 +123,7 @@ static void ProcessExtended(Aec* self, int32_t skew); void* WebRtcAec_Create() { - Aec* aecpc = malloc(sizeof(Aec)); + Aec* aecpc = reinterpret_cast(malloc(sizeof(Aec))); if (!aecpc) { return NULL; @@ -150,11 +154,14 @@ void* WebRtcAec_Create() { #ifdef WEBRTC_AEC_DEBUG_DUMP { char filename[64]; - sprintf(filename, "aec_buf%d.dat", webrtc_aec_instance_count); + snprintf(filename, sizeof(filename), "aec_buf%d.dat", + webrtc_aec_instance_count); aecpc->bufFile = fopen(filename, "wb"); - sprintf(filename, "aec_skew%d.dat", webrtc_aec_instance_count); + snprintf(filename, sizeof(filename), "aec_skew%d.dat", + webrtc_aec_instance_count); aecpc->skewFile = fopen(filename, "wb"); - sprintf(filename, "aec_delay%d.dat", webrtc_aec_instance_count); + snprintf(filename, sizeof(filename), "aec_delay%d.dat", + webrtc_aec_instance_count); aecpc->delayFile = fopen(filename, "wb"); webrtc_aec_instance_count++; } @@ -164,7 +171,7 @@ void* WebRtcAec_Create() { } void WebRtcAec_Free(void* aecInst) { - Aec* aecpc = (Aec*)aecInst; + Aec* aecpc = reinterpret_cast(aecInst); if (aecpc == NULL) { return; @@ -184,7 +191,7 @@ void WebRtcAec_Free(void* aecInst) { } int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) { - Aec* aecpc = (Aec*)aecInst; + Aec* aecpc = reinterpret_cast(aecInst); AecConfig aecConfig; if (sampFreq != 8000 && sampFreq != 16000 && sampFreq != 32000 && @@ -265,7 +272,7 @@ int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) { int32_t WebRtcAec_GetBufferFarendError(void* aecInst, const float* farend, size_t nrOfSamples) { - Aec* aecpc = (Aec*)aecInst; + Aec* aecpc = reinterpret_cast(aecInst); if (!farend) return AEC_NULL_POINTER_ERROR; @@ -284,7 +291,7 @@ int32_t WebRtcAec_GetBufferFarendError(void* aecInst, int32_t WebRtcAec_BufferFarend(void* aecInst, const float* farend, size_t nrOfSamples) { - Aec* aecpc = (Aec*)aecInst; + Aec* aecpc = reinterpret_cast(aecInst); size_t newNrOfSamples = nrOfSamples; float new_farend[MAX_RESAMP_LEN]; const float* farend_ptr = farend; @@ -304,8 +311,8 @@ int32_t WebRtcAec_BufferFarend(void* aecInst, } aecpc->farend_started = 1; - WebRtcAec_SetSystemDelay( - aecpc->aec, WebRtcAec_system_delay(aecpc->aec) + (int)newNrOfSamples); + WebRtcAec_SetSystemDelay(aecpc->aec, WebRtcAec_system_delay(aecpc->aec) + + static_cast(newNrOfSamples)); // Write the time-domain data to |far_pre_buf|. WebRtc_WriteBuffer(aecpc->far_pre_buf, farend_ptr, newNrOfSamples); @@ -317,7 +324,8 @@ int32_t WebRtcAec_BufferFarend(void* aecInst, { float* ptmp = NULL; float tmp[PART_LEN2]; - WebRtc_ReadBuffer(aecpc->far_pre_buf, (void**)&ptmp, tmp, PART_LEN2); + WebRtc_ReadBuffer(aecpc->far_pre_buf, + reinterpret_cast(&ptmp), tmp, PART_LEN2); WebRtcAec_BufferFarendPartition(aecpc->aec, ptmp); } @@ -335,7 +343,7 @@ int32_t WebRtcAec_Process(void* aecInst, size_t nrOfSamples, int16_t msInSndCardBuf, int32_t skew) { - Aec* aecpc = (Aec*)aecInst; + Aec* aecpc = reinterpret_cast(aecInst); int32_t retVal = 0; if (out == NULL) { @@ -382,7 +390,7 @@ int32_t WebRtcAec_Process(void* aecInst, } int WebRtcAec_set_config(void* handle, AecConfig config) { - Aec* self = (Aec*)handle; + Aec* self = reinterpret_cast(handle); if (self->initFlag != initCheck) { return AEC_UNINITIALIZED_ERROR; } @@ -412,7 +420,7 @@ int WebRtcAec_set_config(void* handle, AecConfig config) { } int WebRtcAec_get_echo_status(void* handle, int* status) { - Aec* self = (Aec*)handle; + Aec* self = reinterpret_cast(handle); if (status == NULL) { return AEC_NULL_POINTER_ERROR; } @@ -429,7 +437,7 @@ int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics) { const float kUpWeight = 0.7f; float dtmp; int stmp; - Aec* self = (Aec*)handle; + Aec* self = reinterpret_cast(handle); Stats erl; Stats erle; Stats a_nlp; @@ -447,39 +455,39 @@ int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics) { WebRtcAec_GetEchoStats(self->aec, &erl, &erle, &a_nlp); // ERL - metrics->erl.instant = (int)erl.instant; + metrics->erl.instant = static_cast(erl.instant); if ((erl.himean > kOffsetLevel) && (erl.average > kOffsetLevel)) { // Use a mix between regular average and upper part average. dtmp = kUpWeight * erl.himean + (1 - kUpWeight) * erl.average; - metrics->erl.average = (int)dtmp; + metrics->erl.average = static_cast(dtmp); } else { metrics->erl.average = kOffsetLevel; } - metrics->erl.max = (int)erl.max; + metrics->erl.max = static_cast(erl.max); if (erl.min < (kOffsetLevel * (-1))) { - metrics->erl.min = (int)erl.min; + metrics->erl.min = static_cast(erl.min); } else { metrics->erl.min = kOffsetLevel; } // ERLE - metrics->erle.instant = (int)erle.instant; + metrics->erle.instant = static_cast(erle.instant); if ((erle.himean > kOffsetLevel) && (erle.average > kOffsetLevel)) { // Use a mix between regular average and upper part average. dtmp = kUpWeight * erle.himean + (1 - kUpWeight) * erle.average; - metrics->erle.average = (int)dtmp; + metrics->erle.average = static_cast(dtmp); } else { metrics->erle.average = kOffsetLevel; } - metrics->erle.max = (int)erle.max; + metrics->erle.max = static_cast(erle.max); if (erle.min < (kOffsetLevel * (-1))) { - metrics->erle.min = (int)erle.min; + metrics->erle.min = static_cast(erle.min); } else { metrics->erle.min = kOffsetLevel; } @@ -499,20 +507,20 @@ int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics) { metrics->rerl.min = stmp; // A_NLP - metrics->aNlp.instant = (int)a_nlp.instant; + metrics->aNlp.instant = static_cast(a_nlp.instant); if ((a_nlp.himean > kOffsetLevel) && (a_nlp.average > kOffsetLevel)) { // Use a mix between regular average and upper part average. dtmp = kUpWeight * a_nlp.himean + (1 - kUpWeight) * a_nlp.average; - metrics->aNlp.average = (int)dtmp; + metrics->aNlp.average = static_cast(dtmp); } else { metrics->aNlp.average = kOffsetLevel; } - metrics->aNlp.max = (int)a_nlp.max; + metrics->aNlp.max = static_cast(a_nlp.max); if (a_nlp.min < (kOffsetLevel * (-1))) { - metrics->aNlp.min = (int)a_nlp.min; + metrics->aNlp.min = static_cast(a_nlp.min); } else { metrics->aNlp.min = kOffsetLevel; } @@ -524,7 +532,7 @@ int WebRtcAec_GetDelayMetrics(void* handle, int* median, int* std, float* fraction_poor_delays) { - Aec* self = (Aec*)handle; + Aec* self = reinterpret_cast(handle); if (median == NULL) { return AEC_NULL_POINTER_ERROR; } @@ -547,7 +555,7 @@ AecCore* WebRtcAec_aec_core(void* handle) { if (!handle) { return NULL; } - return ((Aec*)handle)->aec; + return reinterpret_cast(handle)->aec; } static int ProcessNormal(Aec* aecpc, @@ -795,7 +803,9 @@ static void EstBufDelayNormal(Aec* aecpc) { // compensate for that. aecpc->filtDelay = aecpc->filtDelay < 0 ? 0 : aecpc->filtDelay; aecpc->filtDelay = - WEBRTC_SPL_MAX(0, (short)(0.8 * aecpc->filtDelay + 0.2 * current_delay)); + WEBRTC_SPL_MAX(0, static_cast(0.8 * + aecpc->filtDelay + + 0.2 * current_delay)); delay_difference = aecpc->filtDelay - aecpc->knownDelay; if (delay_difference > 224) { @@ -848,7 +858,7 @@ static void EstBufDelayExtended(Aec* self) { self->filtDelay = WEBRTC_SPL_MAX(0, 0.5 * current_delay); } else { self->filtDelay = WEBRTC_SPL_MAX( - 0, (short)(0.95 * self->filtDelay + 0.05 * current_delay)); + 0, static_cast(0.95 * self->filtDelay + 0.05 * current_delay)); } delay_difference = self->filtDelay - self->knownDelay; diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.h b/webrtc/modules/audio_processing/aec/echo_cancellation.h index c2e8a09b6c..5c592631a8 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation.h +++ b/webrtc/modules/audio_processing/aec/echo_cancellation.h @@ -53,10 +53,6 @@ typedef struct { struct AecCore; -#ifdef __cplusplus -extern "C" { -#endif - /* * Allocates the memory needed by the AEC. The memory needs to be initialized * separately using the WebRtcAec_Init() function. Returns a pointer to the @@ -238,7 +234,4 @@ int WebRtcAec_GetDelayMetrics(void* handle, // struct AecCore* WebRtcAec_aec_core(void* handle); -#ifdef __cplusplus -} -#endif #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_H_ diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h b/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h index e87219f33d..ccedb28a14 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h +++ b/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h @@ -11,7 +11,9 @@ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ +extern "C" { #include "webrtc/common_audio/ring_buffer.h" +} #include "webrtc/modules/audio_processing/aec/aec_core.h" typedef struct { diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc b/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc index 42db082ff9..074816c9a5 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc +++ b/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc @@ -15,10 +15,7 @@ #include #include -extern "C" { #include "webrtc/modules/audio_processing/aec/aec_core.h" -} - #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/checks.h" diff --git a/webrtc/modules/audio_processing/aec/system_delay_unittest.cc b/webrtc/modules/audio_processing/aec/system_delay_unittest.cc index 567118d828..60b8c092f8 100644 --- a/webrtc/modules/audio_processing/aec/system_delay_unittest.cc +++ b/webrtc/modules/audio_processing/aec/system_delay_unittest.cc @@ -9,9 +9,7 @@ */ #include "testing/gtest/include/gtest/gtest.h" -extern "C" { #include "webrtc/modules/audio_processing/aec/aec_core.h" -} #include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h" #include "webrtc/modules/audio_processing/aec/echo_cancellation.h" #include "webrtc/typedefs.h" diff --git a/webrtc/modules/audio_processing/audio_processing.gypi b/webrtc/modules/audio_processing/audio_processing.gypi index eaee6443dd..85698cf7f3 100644 --- a/webrtc/modules/audio_processing/audio_processing.gypi +++ b/webrtc/modules/audio_processing/audio_processing.gypi @@ -32,14 +32,14 @@ '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', ], 'sources': [ - 'aec/aec_core.c', + 'aec/aec_core.cc', 'aec/aec_core.h', 'aec/aec_core_internal.h', 'aec/aec_rdft.c', 'aec/aec_rdft.h', 'aec/aec_resampler.c', 'aec/aec_resampler.h', - 'aec/echo_cancellation.c', + 'aec/echo_cancellation.cc', 'aec/echo_cancellation_internal.h', 'aec/echo_cancellation.h', 'aecm/aecm_core.c', @@ -205,7 +205,7 @@ 'conditions': [ ['mips_float_abi=="hard"', { 'sources': [ - 'aec/aec_core_mips.c', + 'aec/aec_core_mips.cc', 'aec/aec_rdft_mips.c', ], }], @@ -244,7 +244,7 @@ 'target_name': 'audio_processing_sse2', 'type': 'static_library', 'sources': [ - 'aec/aec_core_sse2.c', + 'aec/aec_core_sse2.cc', 'aec/aec_rdft_sse2.c', ], 'conditions': [ @@ -267,7 +267,7 @@ '<(webrtc_root)/common_audio/common_audio.gyp:common_audio', ], 'sources': [ - 'aec/aec_core_neon.c', + 'aec/aec_core_neon.cc', 'aec/aec_rdft_neon.c', 'aecm/aecm_core_neon.c', 'ns/nsx_core_neon.c', diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc index bb746ee635..0027c6687c 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc @@ -20,9 +20,7 @@ #include "webrtc/common_audio/channel_buffer.h" #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" -extern "C" { #include "webrtc/modules/audio_processing/aec/aec_core.h" -} #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" #include "webrtc/modules/audio_processing/audio_buffer.h" #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.cc b/webrtc/modules/audio_processing/echo_cancellation_impl.cc index 3c3a2f17bf..1c3ebe4abb 100644 --- a/webrtc/modules/audio_processing/echo_cancellation_impl.cc +++ b/webrtc/modules/audio_processing/echo_cancellation_impl.cc @@ -13,9 +13,7 @@ #include #include -extern "C" { #include "webrtc/modules/audio_processing/aec/aec_core.h" -} #include "webrtc/modules/audio_processing/aec/echo_cancellation.h" #include "webrtc/modules/audio_processing/audio_buffer.h" diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc b/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc index 163e420662..e9a936fb52 100644 --- a/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc +++ b/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc @@ -11,9 +11,7 @@ #include #include "testing/gtest/include/gtest/gtest.h" -extern "C" { #include "webrtc/modules/audio_processing/aec/aec_core.h" -} #include "webrtc/modules/audio_processing/include/audio_processing.h" namespace webrtc {