blob: 2e25b199d1b9d3dfc22795f1e71ebb2bbfe53d20 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_
peahd0263542017-01-03 04:20:34 -080013
14#include <stddef.h>
Mirko Bonadei71207422017-09-15 13:58:09 +020015#include "typedefs.h" // NOLINT(build/include)
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;
Gustaf Ullberg2723fb12017-11-23 14:46:48 +010032constexpr int kMetricsComputationBlocks = 11;
peahe985b3f2017-02-28 22:08:53 -080033constexpr 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;
Per Åhgren63b494d2017-12-06 11:32:38 +010042constexpr int kUnknownDelayRenderWindowSize = 12;
peah29103572017-07-11 02:54:02 -070043constexpr int kAdaptiveFilterTimeDomainLength =
44 kAdaptiveFilterLength * kFftLengthBy2;
Per Åhgren8ba58612017-12-01 23:01:44 +010045constexpr int kRenderTransferQueueSizeFrames = 100;
peah29103572017-07-11 02:54:02 -070046
peahd0263542017-01-03 04:20:34 -080047constexpr size_t kMaxNumBands = 3;
48constexpr size_t kSubFrameLength = 80;
49
50constexpr size_t kBlockSize = kFftLengthBy2;
Per Åhgrenc59a5762017-12-11 21:34:19 +010051constexpr size_t kBlockSizeLog2 = 6;
52
peahd0263542017-01-03 04:20:34 -080053constexpr size_t kExtendedBlockSize = 2 * kFftLengthBy2;
peahcf02cf12017-04-05 14:18:07 -070054constexpr size_t kMatchedFilterWindowSizeSubBlocks = 32;
55constexpr size_t kMatchedFilterAlignmentShiftSizeSubBlocks =
56 kMatchedFilterWindowSizeSubBlocks * 3 / 4;
peahcf02cf12017-04-05 14:18:07 -070057
peahcf02cf12017-04-05 14:18:07 -070058
Per Åhgren1b4059e2017-10-15 20:19:21 +020059constexpr size_t kEchoPathChangeConvergenceBlocks = 2 * kNumBlocksPerSecond;
60
peah2ce640f2017-04-07 03:57:48 -070061// TODO(peah): Integrate this with how it is done inside audio_processing_impl.
peahd0263542017-01-03 04:20:34 -080062constexpr size_t NumBandsForRate(int sample_rate_hz) {
63 return static_cast<size_t>(sample_rate_hz == 8000 ? 1
64 : sample_rate_hz / 16000);
65}
66constexpr int LowestBandRate(int sample_rate_hz) {
67 return sample_rate_hz == 8000 ? sample_rate_hz : 16000;
68}
69
peah21920892017-02-08 05:08:56 -080070constexpr bool ValidFullBandRate(int sample_rate_hz) {
71 return sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
72 sample_rate_hz == 32000 || sample_rate_hz == 48000;
73}
74
Per Åhgren38e2d952017-11-17 14:54:28 +010075constexpr size_t GetDownSampledBufferSize(size_t down_sampling_factor,
76 size_t num_matched_filters) {
77 return kBlockSize / down_sampling_factor *
78 (kMatchedFilterAlignmentShiftSizeSubBlocks * num_matched_filters +
79 kMatchedFilterWindowSizeSubBlocks + 1);
80}
81
82constexpr size_t GetRenderDelayBufferSize(size_t down_sampling_factor,
83 size_t num_matched_filters) {
Per Åhgren8ba58612017-12-01 23:01:44 +010084 return GetDownSampledBufferSize(down_sampling_factor, num_matched_filters) /
Per Åhgrenc59a5762017-12-11 21:34:19 +010085 (kBlockSize / down_sampling_factor) +
86 kAdaptiveFilterLength + 1;
Per Åhgren38e2d952017-11-17 14:54:28 +010087}
88
peah522d71b2017-02-23 05:16:26 -080089// Detects what kind of optimizations to use for the code.
90Aec3Optimization DetectOptimization();
91
Per Åhgrenc59a5762017-12-11 21:34:19 +010092static_assert(1 << kBlockSizeLog2 == kBlockSize,
93 "Proper number of shifts for blocksize");
94
peahd0263542017-01-03 04:20:34 -080095static_assert(1 == NumBandsForRate(8000), "Number of bands for 8 kHz");
96static_assert(1 == NumBandsForRate(16000), "Number of bands for 16 kHz");
97static_assert(2 == NumBandsForRate(32000), "Number of bands for 32 kHz");
98static_assert(3 == NumBandsForRate(48000), "Number of bands for 48 kHz");
99
100static_assert(8000 == LowestBandRate(8000), "Sample rate of band 0 for 8 kHz");
101static_assert(16000 == LowestBandRate(16000),
102 "Sample rate of band 0 for 16 kHz");
103static_assert(16000 == LowestBandRate(32000),
104 "Sample rate of band 0 for 32 kHz");
105static_assert(16000 == LowestBandRate(48000),
106 "Sample rate of band 0 for 48 kHz");
107
peah21920892017-02-08 05:08:56 -0800108static_assert(ValidFullBandRate(8000),
109 "Test that 8 kHz is a valid sample rate");
110static_assert(ValidFullBandRate(16000),
111 "Test that 16 kHz is a valid sample rate");
112static_assert(ValidFullBandRate(32000),
113 "Test that 32 kHz is a valid sample rate");
114static_assert(ValidFullBandRate(48000),
115 "Test that 48 kHz is a valid sample rate");
116static_assert(!ValidFullBandRate(8001),
117 "Test that 8001 Hz is not a valid sample rate");
118
peahd0263542017-01-03 04:20:34 -0800119} // namespace webrtc
120
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200121#endif // MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_