blob: 1d4a9feba1e8fd67762a4921e2663b55353e1e56 [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
27enum class Aec3Optimization { kNone, kSse2 };
28
peahe985b3f2017-02-28 22:08:53 -080029constexpr int kMetricsReportingIntervalBlocks = 10 * 250;
30constexpr int kMetricsComputationBlocks = 9;
31constexpr int kMetricsCollectionBlocks =
32 kMetricsReportingIntervalBlocks - kMetricsComputationBlocks;
33
peahd0263542017-01-03 04:20:34 -080034constexpr size_t kFftLengthBy2 = 64;
35constexpr size_t kFftLengthBy2Plus1 = kFftLengthBy2 + 1;
peah522d71b2017-02-23 05:16:26 -080036constexpr size_t kFftLengthBy2Minus1 = kFftLengthBy2 - 1;
peahd0263542017-01-03 04:20:34 -080037constexpr size_t kFftLength = 2 * kFftLengthBy2;
38
39constexpr size_t kMaxNumBands = 3;
40constexpr size_t kSubFrameLength = 80;
41
42constexpr size_t kBlockSize = kFftLengthBy2;
43constexpr size_t kExtendedBlockSize = 2 * kFftLengthBy2;
44constexpr size_t kSubBlockSize = 16;
45
46constexpr size_t NumBandsForRate(int sample_rate_hz) {
47 return static_cast<size_t>(sample_rate_hz == 8000 ? 1
48 : sample_rate_hz / 16000);
49}
50constexpr int LowestBandRate(int sample_rate_hz) {
51 return sample_rate_hz == 8000 ? sample_rate_hz : 16000;
52}
53
peah21920892017-02-08 05:08:56 -080054constexpr bool ValidFullBandRate(int sample_rate_hz) {
55 return sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
56 sample_rate_hz == 32000 || sample_rate_hz == 48000;
57}
58
peah522d71b2017-02-23 05:16:26 -080059// Detects what kind of optimizations to use for the code.
60Aec3Optimization DetectOptimization();
61
peahd0263542017-01-03 04:20:34 -080062static_assert(1 == NumBandsForRate(8000), "Number of bands for 8 kHz");
63static_assert(1 == NumBandsForRate(16000), "Number of bands for 16 kHz");
64static_assert(2 == NumBandsForRate(32000), "Number of bands for 32 kHz");
65static_assert(3 == NumBandsForRate(48000), "Number of bands for 48 kHz");
66
67static_assert(8000 == LowestBandRate(8000), "Sample rate of band 0 for 8 kHz");
68static_assert(16000 == LowestBandRate(16000),
69 "Sample rate of band 0 for 16 kHz");
70static_assert(16000 == LowestBandRate(32000),
71 "Sample rate of band 0 for 32 kHz");
72static_assert(16000 == LowestBandRate(48000),
73 "Sample rate of band 0 for 48 kHz");
74
peah21920892017-02-08 05:08:56 -080075static_assert(ValidFullBandRate(8000),
76 "Test that 8 kHz is a valid sample rate");
77static_assert(ValidFullBandRate(16000),
78 "Test that 16 kHz is a valid sample rate");
79static_assert(ValidFullBandRate(32000),
80 "Test that 32 kHz is a valid sample rate");
81static_assert(ValidFullBandRate(48000),
82 "Test that 48 kHz is a valid sample rate");
83static_assert(!ValidFullBandRate(8001),
84 "Test that 8001 Hz is not a valid sample rate");
85
peahd0263542017-01-03 04:20:34 -080086} // namespace webrtc
87
peah522d71b2017-02-23 05:16:26 -080088#endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_AEC3_COMMON_H_