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