peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/aec3/aec3_common.h" |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stdint.h> |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 14 | |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 15 | #include "rtc_base/checks.h" |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 16 | #include "rtc_base/system/arch.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 17 | #include "system_wrappers/include/cpu_features_wrapper.h" |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 18 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 19 | namespace webrtc { |
| 20 | |
| 21 | Aec3Optimization DetectOptimization() { |
| 22 | #if defined(WEBRTC_ARCH_X86_FAMILY) |
Mirko Bonadei | bef022b | 2020-09-06 16:07:15 +0200 | [diff] [blame] | 23 | if (GetCPUInfo(kAVX2) != 0) { |
Zhaoliang Ma | e537e9c | 2020-08-31 10:20:47 +0800 | [diff] [blame] | 24 | return Aec3Optimization::kAvx2; |
Mirko Bonadei | bef022b | 2020-09-06 16:07:15 +0200 | [diff] [blame] | 25 | } else if (GetCPUInfo(kSSE2) != 0) { |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 26 | return Aec3Optimization::kSse2; |
| 27 | } |
| 28 | #endif |
peah | 5d153c7 | 2017-05-03 06:45:44 -0700 | [diff] [blame] | 29 | |
| 30 | #if defined(WEBRTC_HAS_NEON) |
| 31 | return Aec3Optimization::kNeon; |
| 32 | #endif |
| 33 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 34 | return Aec3Optimization::kNone; |
| 35 | } |
| 36 | |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 37 | float 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 | |
| 54 | float Log2TodB(const float in_log2) { |
| 55 | return 3.0102999566398121 * in_log2; |
| 56 | } |
| 57 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 58 | } // namespace webrtc |