blob: c374a3517d60e37a7991d4ee964b100ed7001d64 [file] [log] [blame]
peah522d71b2017-02-23 05:16:26 -08001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/aec3/aec3_common.h"
peah522d71b2017-02-23 05:16:26 -080012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "system_wrappers/include/cpu_features_wrapper.h"
peah522d71b2017-02-23 05:16:26 -080014
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020015#include "rtc_base/checks.h"
Niels Möllera12c42a2018-07-25 16:05:48 +020016#include "rtc_base/system/arch.h"
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020017
peah522d71b2017-02-23 05:16:26 -080018namespace webrtc {
19
20Aec3Optimization DetectOptimization() {
21#if defined(WEBRTC_ARCH_X86_FAMILY)
22 if (WebRtc_GetCPUInfo(kSSE2) != 0) {
23 return Aec3Optimization::kSse2;
24 }
25#endif
peah5d153c72017-05-03 06:45:44 -070026
27#if defined(WEBRTC_HAS_NEON)
28 return Aec3Optimization::kNeon;
29#endif
30
peah522d71b2017-02-23 05:16:26 -080031 return Aec3Optimization::kNone;
32}
33
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020034float FastApproxLog2f(const float in) {
35 RTC_DCHECK_GT(in, .0f);
36 // Read and interpret float as uint32_t and then cast to float.
37 // This is done to extract the exponent (bits 30 - 23).
38 // "Right shift" of the exponent is then performed by multiplying
39 // with the constant (1/2^23). Finally, we subtract a constant to
40 // remove the bias (https://en.wikipedia.org/wiki/Exponent_bias).
41 union {
42 float dummy;
43 uint32_t a;
44 } x = {in};
45 float out = x.a;
46 out *= 1.1920929e-7f; // 1/2^23
47 out -= 126.942695f; // Remove bias.
48 return out;
49}
50
51float Log2TodB(const float in_log2) {
52 return 3.0102999566398121 * in_log2;
53}
54
peah522d71b2017-02-23 05:16:26 -080055} // namespace webrtc