blob: 7bd8d6267a0b5f51a9e520fdf24d0f6ba4b71804 [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
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stdint.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"
Yves Gerey988cc082018-10-23 12:03:01 +020017#include "system_wrappers/include/cpu_features_wrapper.h"
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020018
peah522d71b2017-02-23 05:16:26 -080019namespace webrtc {
20
21Aec3Optimization DetectOptimization() {
22#if defined(WEBRTC_ARCH_X86_FAMILY)
Mirko Bonadeibef022b2020-09-06 16:07:15 +020023 if (GetCPUInfo(kAVX2) != 0) {
Zhaoliang Mae537e9c2020-08-31 10:20:47 +080024 return Aec3Optimization::kAvx2;
Mirko Bonadeibef022b2020-09-06 16:07:15 +020025 } else if (GetCPUInfo(kSSE2) != 0) {
peah522d71b2017-02-23 05:16:26 -080026 return Aec3Optimization::kSse2;
27 }
28#endif
peah5d153c72017-05-03 06:45:44 -070029
30#if defined(WEBRTC_HAS_NEON)
31 return Aec3Optimization::kNeon;
32#endif
33
peah522d71b2017-02-23 05:16:26 -080034 return Aec3Optimization::kNone;
35}
36
Jesús de Vicente Peña496cedf2018-07-04 11:02:09 +020037float FastApproxLog2f(const float in) {
38 RTC_DCHECK_GT(in, .0f);
39 // Read and interpret float as uint32_t and then cast to float.
40 // This is done to extract the exponent (bits 30 - 23).
41 // "Right shift" of the exponent is then performed by multiplying
42 // with the constant (1/2^23). Finally, we subtract a constant to
43 // remove the bias (https://en.wikipedia.org/wiki/Exponent_bias).
44 union {
45 float dummy;
46 uint32_t a;
47 } x = {in};
48 float out = x.a;
49 out *= 1.1920929e-7f; // 1/2^23
50 out -= 126.942695f; // Remove bias.
51 return out;
52}
53
54float Log2TodB(const float in_log2) {
55 return 3.0102999566398121 * in_log2;
56}
57
peah522d71b2017-02-23 05:16:26 -080058} // namespace webrtc