tor-browser

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

aec3_common.h (4256B)


      1 /*
      2 *  Copyright (c) 2016 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 #ifndef MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_
     12 #define MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_
     13 
     14 #include <stddef.h>
     15 
     16 namespace webrtc {
     17 
     18 #ifdef _MSC_VER /* visual c++ */
     19 #define ALIGN16_BEG __declspec(align(16))
     20 #define ALIGN16_END
     21 #else /* gcc or icc */
     22 #define ALIGN16_BEG
     23 #define ALIGN16_END __attribute__((aligned(16)))
     24 #endif
     25 
     26 enum class Aec3Optimization { kNone, kSse2, kAvx2, kNeon };
     27 
     28 constexpr int kNumBlocksPerSecond = 250;
     29 
     30 constexpr int kMetricsReportingIntervalBlocks = 10 * kNumBlocksPerSecond;
     31 constexpr int kMetricsComputationBlocks = 3;
     32 constexpr int kMetricsCollectionBlocks =
     33    kMetricsReportingIntervalBlocks - kMetricsComputationBlocks;
     34 
     35 constexpr size_t kFftLengthBy2 = 64;
     36 constexpr size_t kFftLengthBy2Plus1 = kFftLengthBy2 + 1;
     37 constexpr size_t kFftLengthBy2Minus1 = kFftLengthBy2 - 1;
     38 constexpr size_t kFftLength = 2 * kFftLengthBy2;
     39 constexpr size_t kFftLengthBy2Log2 = 6;
     40 
     41 constexpr int kRenderTransferQueueSizeFrames = 100;
     42 
     43 constexpr size_t kMaxNumBands = 3;
     44 constexpr size_t kFrameSize = 160;
     45 constexpr size_t kSubFrameLength = kFrameSize / 2;
     46 
     47 constexpr size_t kBlockSize = kFftLengthBy2;
     48 constexpr size_t kBlockSizeLog2 = kFftLengthBy2Log2;
     49 constexpr size_t kBlockSizeMs = kFftLengthBy2 * 1000 / 16000;
     50 
     51 constexpr size_t kExtendedBlockSize = 2 * kFftLengthBy2;
     52 constexpr size_t kMatchedFilterWindowSizeSubBlocks = 32;
     53 constexpr size_t kMatchedFilterAlignmentShiftSizeSubBlocks =
     54    kMatchedFilterWindowSizeSubBlocks * 3 / 4;
     55 
     56 // TODO(peah): Integrate this with how it is done inside audio_processing_impl.
     57 constexpr size_t NumBandsForRate(int sample_rate_hz) {
     58  return static_cast<size_t>(sample_rate_hz / 16000);
     59 }
     60 
     61 constexpr bool ValidFullBandRate(int sample_rate_hz) {
     62  return sample_rate_hz == 16000 || sample_rate_hz == 32000 ||
     63         sample_rate_hz == 48000;
     64 }
     65 
     66 constexpr int GetTimeDomainLength(int filter_length_blocks) {
     67  return filter_length_blocks * kFftLengthBy2;
     68 }
     69 
     70 constexpr size_t GetDownSampledBufferSize(size_t down_sampling_factor,
     71                                          size_t num_matched_filters) {
     72  return kBlockSize / down_sampling_factor *
     73         (kMatchedFilterAlignmentShiftSizeSubBlocks * num_matched_filters +
     74          kMatchedFilterWindowSizeSubBlocks + 1);
     75 }
     76 
     77 constexpr size_t GetRenderDelayBufferSize(size_t down_sampling_factor,
     78                                          size_t num_matched_filters,
     79                                          size_t filter_length_blocks) {
     80  return GetDownSampledBufferSize(down_sampling_factor, num_matched_filters) /
     81             (kBlockSize / down_sampling_factor) +
     82         filter_length_blocks + 1;
     83 }
     84 
     85 // Detects what kind of optimizations to use for the code.
     86 Aec3Optimization DetectOptimization();
     87 
     88 // Computes the log2 of the input in a fast an approximate manner.
     89 float FastApproxLog2f(float in);
     90 
     91 // Returns dB from a power quantity expressed in log2.
     92 float Log2TodB(float in_log2);
     93 
     94 static_assert(1 << kBlockSizeLog2 == kBlockSize,
     95              "Proper number of shifts for blocksize");
     96 
     97 static_assert(1 << kFftLengthBy2Log2 == kFftLengthBy2,
     98              "Proper number of shifts for the fft length");
     99 
    100 static_assert(1 == NumBandsForRate(16000), "Number of bands for 16 kHz");
    101 static_assert(2 == NumBandsForRate(32000), "Number of bands for 32 kHz");
    102 static_assert(3 == NumBandsForRate(48000), "Number of bands for 48 kHz");
    103 
    104 static_assert(ValidFullBandRate(16000),
    105              "Test that 16 kHz is a valid sample rate");
    106 static_assert(ValidFullBandRate(32000),
    107              "Test that 32 kHz is a valid sample rate");
    108 static_assert(ValidFullBandRate(48000),
    109              "Test that 48 kHz is a valid sample rate");
    110 static_assert(!ValidFullBandRate(8001),
    111              "Test that 8001 Hz is not a valid sample rate");
    112 
    113 }  // namespace webrtc
    114 
    115 #endif  // MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_