OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/agc/agc.h" | 11 #include "webrtc/modules/audio_processing/agc/agc.h" |
12 | 12 |
13 #include <cmath> | 13 #include <cmath> |
14 #include <cstdlib> | 14 #include <cstdlib> |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/modules/audio_processing/agc/histogram.h" | 20 #include "webrtc/modules/audio_processing/agc/loudness_histogram.h" |
21 #include "webrtc/modules/audio_processing/agc/utility.h" | 21 #include "webrtc/modules/audio_processing/agc/utility.h" |
22 #include "webrtc/modules/include/module_common_types.h" | 22 #include "webrtc/modules/include/module_common_types.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 namespace { | 25 namespace { |
26 | 26 |
27 const int kDefaultLevelDbfs = -18; | 27 const int kDefaultLevelDbfs = -18; |
28 const int kNumAnalysisFrames = 100; | 28 const int kNumAnalysisFrames = 100; |
29 const double kActivityThreshold = 0.3; | 29 const double kActivityThreshold = 0.3; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 Agc::Agc() | 33 Agc::Agc() |
34 : target_level_loudness_(Dbfs2Loudness(kDefaultLevelDbfs)), | 34 : target_level_loudness_(Dbfs2Loudness(kDefaultLevelDbfs)), |
35 target_level_dbfs_(kDefaultLevelDbfs), | 35 target_level_dbfs_(kDefaultLevelDbfs), |
36 histogram_(Histogram::Create(kNumAnalysisFrames)), | 36 histogram_(LoudnessHistogram::Create(kNumAnalysisFrames)), |
37 inactive_histogram_(Histogram::Create()) { | 37 inactive_histogram_(LoudnessHistogram::Create()) {} |
38 } | |
39 | 38 |
40 Agc::~Agc() {} | 39 Agc::~Agc() {} |
41 | 40 |
42 float Agc::AnalyzePreproc(const int16_t* audio, size_t length) { | 41 float Agc::AnalyzePreproc(const int16_t* audio, size_t length) { |
43 assert(length > 0); | 42 assert(length > 0); |
44 size_t num_clipped = 0; | 43 size_t num_clipped = 0; |
45 for (size_t i = 0; i < length; ++i) { | 44 for (size_t i = 0; i < length; ++i) { |
46 if (audio[i] == 32767 || audio[i] == -32768) | 45 if (audio[i] == 32767 || audio[i] == -32768) |
47 ++num_clipped; | 46 ++num_clipped; |
48 } | 47 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // limits. The upper limit should be chosen such that the risk of clipping is | 91 // limits. The upper limit should be chosen such that the risk of clipping is |
93 // low. The lower limit should not result in a too quiet signal. | 92 // low. The lower limit should not result in a too quiet signal. |
94 if (level >= 0 || level <= -100) | 93 if (level >= 0 || level <= -100) |
95 return -1; | 94 return -1; |
96 target_level_dbfs_ = level; | 95 target_level_dbfs_ = level; |
97 target_level_loudness_ = Dbfs2Loudness(level); | 96 target_level_loudness_ = Dbfs2Loudness(level); |
98 return 0; | 97 return 0; |
99 } | 98 } |
100 | 99 |
101 } // namespace webrtc | 100 } // namespace webrtc |
OLD | NEW |