peah | 522d71b | 2017-02-23 13:16:26 | [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 04:47:31 | [diff] [blame] | 11 | #include "modules/audio_processing/aec3/aec3_common.h" |
peah | 522d71b | 2017-02-23 13:16:26 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame^] | 13 | #include <stdint.h> |
peah | 522d71b | 2017-02-23 13:16:26 | [diff] [blame] | 14 | |
Jesús de Vicente Peña | 496cedf | 2018-07-04 09:02:09 | [diff] [blame] | 15 | #include "rtc_base/checks.h" |
Niels Möller | a12c42a | 2018-07-25 14:05:48 | [diff] [blame] | 16 | #include "rtc_base/system/arch.h" |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame^] | 17 | #include "system_wrappers/include/cpu_features_wrapper.h" |
Jesús de Vicente Peña | 496cedf | 2018-07-04 09:02:09 | [diff] [blame] | 18 | |
peah | 522d71b | 2017-02-23 13:16:26 | [diff] [blame] | 19 | namespace webrtc { |
| 20 | |
| 21 | Aec3Optimization DetectOptimization() { |
| 22 | #if defined(WEBRTC_ARCH_X86_FAMILY) |
| 23 | if (WebRtc_GetCPUInfo(kSSE2) != 0) { |
| 24 | return Aec3Optimization::kSse2; |
| 25 | } |
| 26 | #endif |
peah | 5d153c7 | 2017-05-03 13:45:44 | [diff] [blame] | 27 | |
| 28 | #if defined(WEBRTC_HAS_NEON) |
| 29 | return Aec3Optimization::kNeon; |
| 30 | #endif |
| 31 | |
peah | 522d71b | 2017-02-23 13:16:26 | [diff] [blame] | 32 | return Aec3Optimization::kNone; |
| 33 | } |
| 34 | |
Jesús de Vicente Peña | 496cedf | 2018-07-04 09:02:09 | [diff] [blame] | 35 | float FastApproxLog2f(const float in) { |
| 36 | RTC_DCHECK_GT(in, .0f); |
| 37 | // Read and interpret float as uint32_t and then cast to float. |
| 38 | // This is done to extract the exponent (bits 30 - 23). |
| 39 | // "Right shift" of the exponent is then performed by multiplying |
| 40 | // with the constant (1/2^23). Finally, we subtract a constant to |
| 41 | // remove the bias (https://en.wikipedia.org/wiki/Exponent_bias). |
| 42 | union { |
| 43 | float dummy; |
| 44 | uint32_t a; |
| 45 | } x = {in}; |
| 46 | float out = x.a; |
| 47 | out *= 1.1920929e-7f; // 1/2^23 |
| 48 | out -= 126.942695f; // Remove bias. |
| 49 | return out; |
| 50 | } |
| 51 | |
| 52 | float Log2TodB(const float in_log2) { |
| 53 | return 3.0102999566398121 * in_log2; |
| 54 | } |
| 55 | |
peah | 522d71b | 2017-02-23 13:16:26 | [diff] [blame] | 56 | } // namespace webrtc |