blob: aeb848a5700a64820ddccd4f33ff93305b561f4f [file] [log] [blame]
peah522d71b2017-02-23 13:16:261/*
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 04:47:3111#include "modules/audio_processing/aec3/aec3_common.h"
peah522d71b2017-02-23 13:16:2612
Yves Gerey988cc082018-10-23 10:03:0113#include <stdint.h>
peah522d71b2017-02-23 13:16:2614
Jesús de Vicente Peña496cedf2018-07-04 09:02:0915#include "rtc_base/checks.h"
Niels Möllera12c42a2018-07-25 14:05:4816#include "rtc_base/system/arch.h"
Yves Gerey988cc082018-10-23 10:03:0117#include "system_wrappers/include/cpu_features_wrapper.h"
Jesús de Vicente Peña496cedf2018-07-04 09:02:0918
peah522d71b2017-02-23 13:16:2619namespace webrtc {
20
21Aec3Optimization DetectOptimization() {
22#if defined(WEBRTC_ARCH_X86_FAMILY)
23 if (WebRtc_GetCPUInfo(kSSE2) != 0) {
24 return Aec3Optimization::kSse2;
25 }
26#endif
peah5d153c72017-05-03 13:45:4427
28#if defined(WEBRTC_HAS_NEON)
29 return Aec3Optimization::kNeon;
30#endif
31
peah522d71b2017-02-23 13:16:2632 return Aec3Optimization::kNone;
33}
34
Jesús de Vicente Peña496cedf2018-07-04 09:02:0935float 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
52float Log2TodB(const float in_log2) {
53 return 3.0102999566398121 * in_log2;
54}
55
peah522d71b2017-02-23 13:16:2656} // namespace webrtc