blob: e6cabb40ca2cd7b450e188257291a554e1cad60b [file] [log] [blame]
peahd0263542017-01-03 04:20:34 -08001/*
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
peah522d71b2017-02-23 05:16:26 -080011#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_
peahd0263542017-01-03 04:20:34 -080013
14#include <stddef.h>
peah522d71b2017-02-23 05:16:26 -080015#include "webrtc/typedefs.h"
peahd0263542017-01-03 04:20:34 -080016
17namespace webrtc {
18
peah522d71b2017-02-23 05:16:26 -080019#ifdef _MSC_VER /* visual c++ */
20#define ALIGN16_BEG __declspec(align(16))
21#define ALIGN16_END
22#else /* gcc or icc */
23#define ALIGN16_BEG
24#define ALIGN16_END __attribute__((aligned(16)))
25#endif
26
peah5d153c72017-05-03 06:45:44 -070027enum class Aec3Optimization { kNone, kSse2, kNeon };
peah522d71b2017-02-23 05:16:26 -080028
peah86afe9d2017-04-06 15:45:32 -070029constexpr int kNumBlocksPerSecond = 250;
30
31constexpr int kMetricsReportingIntervalBlocks = 10 * kNumBlocksPerSecond;
peahe985b3f2017-02-28 22:08:53 -080032constexpr int kMetricsComputationBlocks = 9;
33constexpr int kMetricsCollectionBlocks =
34 kMetricsReportingIntervalBlocks - kMetricsComputationBlocks;
35
peahd0263542017-01-03 04:20:34 -080036constexpr size_t kFftLengthBy2 = 64;
37constexpr size_t kFftLengthBy2Plus1 = kFftLengthBy2 + 1;
peah522d71b2017-02-23 05:16:26 -080038constexpr size_t kFftLengthBy2Minus1 = kFftLengthBy2 - 1;
peahd0263542017-01-03 04:20:34 -080039constexpr size_t kFftLength = 2 * kFftLengthBy2;
40
peah29103572017-07-11 02:54:02 -070041constexpr int kAdaptiveFilterLength = 12;
42constexpr int kResidualEchoPowerRenderWindowSize = 30;
43constexpr int kAdaptiveFilterTimeDomainLength =
44 kAdaptiveFilterLength * kFftLengthBy2;
45
peahd0263542017-01-03 04:20:34 -080046constexpr size_t kMaxNumBands = 3;
47constexpr size_t kSubFrameLength = 80;
48
49constexpr size_t kBlockSize = kFftLengthBy2;
50constexpr size_t kExtendedBlockSize = 2 * kFftLengthBy2;
51constexpr size_t kSubBlockSize = 16;
52
peahcf02cf12017-04-05 14:18:07 -070053constexpr size_t kNumMatchedFilters = 4;
54constexpr size_t kMatchedFilterWindowSizeSubBlocks = 32;
55constexpr size_t kMatchedFilterAlignmentShiftSizeSubBlocks =
56 kMatchedFilterWindowSizeSubBlocks * 3 / 4;
57constexpr size_t kDownsampledRenderBufferSize =
58 kSubBlockSize *
59 (kMatchedFilterAlignmentShiftSizeSubBlocks * kNumMatchedFilters +
60 kMatchedFilterWindowSizeSubBlocks +
61 1);
62
peah86afe9d2017-04-06 15:45:32 -070063constexpr float kFixedEchoPathGain = 100;
64
peahcf02cf12017-04-05 14:18:07 -070065constexpr size_t kRenderDelayBufferSize =
66 (3 * kDownsampledRenderBufferSize) / (4 * kSubBlockSize);
67
peah8f9ce1d2017-06-30 03:13:21 -070068constexpr size_t kMaxApiCallsJitterBlocks = 30;
peahcf02cf12017-04-05 14:18:07 -070069constexpr size_t kRenderTransferQueueSize = kMaxApiCallsJitterBlocks / 2;
peah86afe9d2017-04-06 15:45:32 -070070static_assert(2 * kRenderTransferQueueSize >= kMaxApiCallsJitterBlocks,
71 "Requirement to ensure buffer overflow detection");
peahcf02cf12017-04-05 14:18:07 -070072
peah2ce640f2017-04-07 03:57:48 -070073// TODO(peah): Integrate this with how it is done inside audio_processing_impl.
peahd0263542017-01-03 04:20:34 -080074constexpr size_t NumBandsForRate(int sample_rate_hz) {
75 return static_cast<size_t>(sample_rate_hz == 8000 ? 1
76 : sample_rate_hz / 16000);
77}
78constexpr int LowestBandRate(int sample_rate_hz) {
79 return sample_rate_hz == 8000 ? sample_rate_hz : 16000;
80}
81
peah21920892017-02-08 05:08:56 -080082constexpr bool ValidFullBandRate(int sample_rate_hz) {
83 return sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
84 sample_rate_hz == 32000 || sample_rate_hz == 48000;
85}
86
peah522d71b2017-02-23 05:16:26 -080087// Detects what kind of optimizations to use for the code.
88Aec3Optimization DetectOptimization();
89
peahd0263542017-01-03 04:20:34 -080090static_assert(1 == NumBandsForRate(8000), "Number of bands for 8 kHz");
91static_assert(1 == NumBandsForRate(16000), "Number of bands for 16 kHz");
92static_assert(2 == NumBandsForRate(32000), "Number of bands for 32 kHz");
93static_assert(3 == NumBandsForRate(48000), "Number of bands for 48 kHz");
94
95static_assert(8000 == LowestBandRate(8000), "Sample rate of band 0 for 8 kHz");
96static_assert(16000 == LowestBandRate(16000),
97 "Sample rate of band 0 for 16 kHz");
98static_assert(16000 == LowestBandRate(32000),
99 "Sample rate of band 0 for 32 kHz");
100static_assert(16000 == LowestBandRate(48000),
101 "Sample rate of band 0 for 48 kHz");
102
peah21920892017-02-08 05:08:56 -0800103static_assert(ValidFullBandRate(8000),
104 "Test that 8 kHz is a valid sample rate");
105static_assert(ValidFullBandRate(16000),
106 "Test that 16 kHz is a valid sample rate");
107static_assert(ValidFullBandRate(32000),
108 "Test that 32 kHz is a valid sample rate");
109static_assert(ValidFullBandRate(48000),
110 "Test that 48 kHz is a valid sample rate");
111static_assert(!ValidFullBandRate(8001),
112 "Test that 8001 Hz is not a valid sample rate");
113
peahd0263542017-01-03 04:20:34 -0800114} // namespace webrtc
115
peah522d71b2017-02-23 05:16:26 -0800116#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_