peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_ |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 13 | |
| 14 | #include <stddef.h> |
| 15 | |
| 16 | namespace webrtc { |
| 17 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 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 | |
peah | 5d153c7 | 2017-05-03 06:45:44 -0700 | [diff] [blame] | 26 | enum class Aec3Optimization { kNone, kSse2, kNeon }; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 27 | |
peah | 86afe9d | 2017-04-06 15:45:32 -0700 | [diff] [blame] | 28 | constexpr int kNumBlocksPerSecond = 250; |
| 29 | |
| 30 | constexpr int kMetricsReportingIntervalBlocks = 10 * kNumBlocksPerSecond; |
Gustaf Ullberg | 2723fb1 | 2017-11-23 14:46:48 +0100 | [diff] [blame] | 31 | constexpr int kMetricsComputationBlocks = 11; |
peah | e985b3f | 2017-02-28 22:08:53 -0800 | [diff] [blame] | 32 | constexpr int kMetricsCollectionBlocks = |
| 33 | kMetricsReportingIntervalBlocks - kMetricsComputationBlocks; |
| 34 | |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 35 | constexpr size_t kFftLengthBy2 = 64; |
| 36 | constexpr size_t kFftLengthBy2Plus1 = kFftLengthBy2 + 1; |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 37 | constexpr size_t kFftLengthBy2Minus1 = kFftLengthBy2 - 1; |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 38 | constexpr size_t kFftLength = 2 * kFftLengthBy2; |
| 39 | |
Per Åhgren | 09a718a | 2017-12-11 22:28:45 +0100 | [diff] [blame] | 40 | constexpr int kMaxAdaptiveFilterLength = 50; |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 41 | constexpr int kRenderTransferQueueSizeFrames = 100; |
peah | 2910357 | 2017-07-11 02:54:02 -0700 | [diff] [blame] | 42 | |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 43 | constexpr size_t kMaxNumBands = 3; |
| 44 | constexpr size_t kSubFrameLength = 80; |
| 45 | |
| 46 | constexpr size_t kBlockSize = kFftLengthBy2; |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 47 | constexpr size_t kBlockSizeLog2 = 6; |
| 48 | |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 49 | constexpr size_t kExtendedBlockSize = 2 * kFftLengthBy2; |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 50 | constexpr size_t kMatchedFilterWindowSizeSubBlocks = 32; |
| 51 | constexpr size_t kMatchedFilterAlignmentShiftSizeSubBlocks = |
| 52 | kMatchedFilterWindowSizeSubBlocks * 3 / 4; |
peah | cf02cf1 | 2017-04-05 14:18:07 -0700 | [diff] [blame] | 53 | |
peah | 2ce640f | 2017-04-07 03:57:48 -0700 | [diff] [blame] | 54 | // TODO(peah): Integrate this with how it is done inside audio_processing_impl. |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 55 | constexpr size_t NumBandsForRate(int sample_rate_hz) { |
| 56 | return static_cast<size_t>(sample_rate_hz == 8000 ? 1 |
| 57 | : sample_rate_hz / 16000); |
| 58 | } |
| 59 | constexpr int LowestBandRate(int sample_rate_hz) { |
| 60 | return sample_rate_hz == 8000 ? sample_rate_hz : 16000; |
| 61 | } |
| 62 | |
peah | 2192089 | 2017-02-08 05:08:56 -0800 | [diff] [blame] | 63 | constexpr bool ValidFullBandRate(int sample_rate_hz) { |
| 64 | return sample_rate_hz == 8000 || sample_rate_hz == 16000 || |
| 65 | sample_rate_hz == 32000 || sample_rate_hz == 48000; |
| 66 | } |
| 67 | |
Per Åhgren | 09a718a | 2017-12-11 22:28:45 +0100 | [diff] [blame] | 68 | constexpr int GetTimeDomainLength(int filter_length_blocks) { |
| 69 | return filter_length_blocks * kFftLengthBy2; |
| 70 | } |
| 71 | |
Per Åhgren | 38e2d95 | 2017-11-17 14:54:28 +0100 | [diff] [blame] | 72 | constexpr size_t GetDownSampledBufferSize(size_t down_sampling_factor, |
| 73 | size_t num_matched_filters) { |
| 74 | return kBlockSize / down_sampling_factor * |
| 75 | (kMatchedFilterAlignmentShiftSizeSubBlocks * num_matched_filters + |
| 76 | kMatchedFilterWindowSizeSubBlocks + 1); |
| 77 | } |
| 78 | |
| 79 | constexpr size_t GetRenderDelayBufferSize(size_t down_sampling_factor, |
Per Åhgren | 09a718a | 2017-12-11 22:28:45 +0100 | [diff] [blame] | 80 | size_t num_matched_filters, |
| 81 | size_t filter_length_blocks) { |
Per Åhgren | 8ba5861 | 2017-12-01 23:01:44 +0100 | [diff] [blame] | 82 | return GetDownSampledBufferSize(down_sampling_factor, num_matched_filters) / |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 83 | (kBlockSize / down_sampling_factor) + |
Per Åhgren | 09a718a | 2017-12-11 22:28:45 +0100 | [diff] [blame] | 84 | filter_length_blocks + 1; |
Per Åhgren | 38e2d95 | 2017-11-17 14:54:28 +0100 | [diff] [blame] | 85 | } |
| 86 | |
peah | 522d71b | 2017-02-23 05:16:26 -0800 | [diff] [blame] | 87 | // Detects what kind of optimizations to use for the code. |
| 88 | Aec3Optimization DetectOptimization(); |
| 89 | |
Jesús de Vicente Peña | 496cedf | 2018-07-04 11:02:09 +0200 | [diff] [blame] | 90 | // Computes the log2 of the input in a fast an approximate manner. |
| 91 | float FastApproxLog2f(const float in); |
| 92 | |
| 93 | // Returns dB from a power quantity expressed in log2. |
| 94 | float Log2TodB(const float in_log2); |
| 95 | |
Per Åhgren | c59a576 | 2017-12-11 21:34:19 +0100 | [diff] [blame] | 96 | static_assert(1 << kBlockSizeLog2 == kBlockSize, |
| 97 | "Proper number of shifts for blocksize"); |
| 98 | |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 99 | static_assert(1 == NumBandsForRate(8000), "Number of bands for 8 kHz"); |
| 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(8000 == LowestBandRate(8000), "Sample rate of band 0 for 8 kHz"); |
| 105 | static_assert(16000 == LowestBandRate(16000), |
| 106 | "Sample rate of band 0 for 16 kHz"); |
| 107 | static_assert(16000 == LowestBandRate(32000), |
| 108 | "Sample rate of band 0 for 32 kHz"); |
| 109 | static_assert(16000 == LowestBandRate(48000), |
| 110 | "Sample rate of band 0 for 48 kHz"); |
| 111 | |
peah | 2192089 | 2017-02-08 05:08:56 -0800 | [diff] [blame] | 112 | static_assert(ValidFullBandRate(8000), |
| 113 | "Test that 8 kHz is a valid sample rate"); |
| 114 | static_assert(ValidFullBandRate(16000), |
| 115 | "Test that 16 kHz is a valid sample rate"); |
| 116 | static_assert(ValidFullBandRate(32000), |
| 117 | "Test that 32 kHz is a valid sample rate"); |
| 118 | static_assert(ValidFullBandRate(48000), |
| 119 | "Test that 48 kHz is a valid sample rate"); |
| 120 | static_assert(!ValidFullBandRate(8001), |
| 121 | "Test that 8001 Hz is not a valid sample rate"); |
| 122 | |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 123 | } // namespace webrtc |
| 124 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 125 | #endif // MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_ |