tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

aec3_common.cc (1651B)


      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 
     11 #include "modules/audio_processing/aec3/aec3_common.h"
     12 
     13 #include <cstdint>
     14 
     15 #include "rtc_base/checks.h"
     16 #include "rtc_base/cpu_info.h"
     17 #include "rtc_base/system/arch.h"
     18 
     19 namespace webrtc {
     20 
     21 Aec3Optimization DetectOptimization() {
     22 #if defined(WEBRTC_ARCH_X86_FAMILY)
     23  if (cpu_info::Supports(cpu_info::ISA::kAVX2)) {
     24    return Aec3Optimization::kAvx2;
     25  } else if (cpu_info::Supports(cpu_info::ISA::kSSE2)) {
     26    return Aec3Optimization::kSse2;
     27  }
     28 #endif
     29 
     30 #if defined(WEBRTC_HAS_NEON)
     31  return Aec3Optimization::kNeon;
     32 #else
     33  return Aec3Optimization::kNone;
     34 #endif
     35 }
     36 
     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 
     58 }  // namespace webrtc