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 |
(...skipping 21 matching lines...) Expand all Loading... |
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_(LoudnessHistogram::Create(kNumAnalysisFrames)), | 36 histogram_(LoudnessHistogram::Create(kNumAnalysisFrames)), |
37 inactive_histogram_(LoudnessHistogram::Create()) {} | 37 inactive_histogram_(LoudnessHistogram::Create()) {} |
38 | 38 |
39 Agc::~Agc() {} | 39 Agc::~Agc() {} |
40 | 40 |
41 float Agc::AnalyzePreproc(const int16_t* audio, size_t length) { | 41 float Agc::AnalyzePreproc(const int16_t* audio, size_t length) { |
42 assert(length > 0); | 42 RTC_DCHECK_GT(length, 0u); |
43 size_t num_clipped = 0; | 43 size_t num_clipped = 0; |
44 for (size_t i = 0; i < length; ++i) { | 44 for (size_t i = 0; i < length; ++i) { |
45 if (audio[i] == 32767 || audio[i] == -32768) | 45 if (audio[i] == 32767 || audio[i] == -32768) |
46 ++num_clipped; | 46 ++num_clipped; |
47 } | 47 } |
48 return 1.0f * num_clipped / length; | 48 return 1.0f * num_clipped / length; |
49 } | 49 } |
50 | 50 |
51 int Agc::Process(const int16_t* audio, size_t length, int sample_rate_hz) { | 51 int Agc::Process(const int16_t* audio, size_t length, int sample_rate_hz) { |
52 vad_.ProcessChunk(audio, length, sample_rate_hz); | 52 vad_.ProcessChunk(audio, length, sample_rate_hz); |
53 const std::vector<double>& rms = vad_.chunkwise_rms(); | 53 const std::vector<double>& rms = vad_.chunkwise_rms(); |
54 const std::vector<double>& probabilities = | 54 const std::vector<double>& probabilities = |
55 vad_.chunkwise_voice_probabilities(); | 55 vad_.chunkwise_voice_probabilities(); |
56 RTC_DCHECK_EQ(rms.size(), probabilities.size()); | 56 RTC_DCHECK_EQ(rms.size(), probabilities.size()); |
57 for (size_t i = 0; i < rms.size(); ++i) { | 57 for (size_t i = 0; i < rms.size(); ++i) { |
58 histogram_->Update(rms[i], probabilities[i]); | 58 histogram_->Update(rms[i], probabilities[i]); |
59 } | 59 } |
60 return 0; | 60 return 0; |
61 } | 61 } |
62 | 62 |
63 bool Agc::GetRmsErrorDb(int* error) { | 63 bool Agc::GetRmsErrorDb(int* error) { |
64 if (!error) { | 64 if (!error) { |
65 assert(false); | 65 RTC_NOTREACHED(); |
66 return false; | 66 return false; |
67 } | 67 } |
68 | 68 |
69 if (histogram_->num_updates() < kNumAnalysisFrames) { | 69 if (histogram_->num_updates() < kNumAnalysisFrames) { |
70 // We haven't yet received enough frames. | 70 // We haven't yet received enough frames. |
71 return false; | 71 return false; |
72 } | 72 } |
73 | 73 |
74 if (histogram_->AudioContent() < kNumAnalysisFrames * kActivityThreshold) { | 74 if (histogram_->AudioContent() < kNumAnalysisFrames * kActivityThreshold) { |
75 // We are likely in an inactive segment. | 75 // We are likely in an inactive segment. |
(...skipping 23 matching lines...) Expand all Loading... |
99 | 99 |
100 int Agc::target_level_dbfs() const { | 100 int Agc::target_level_dbfs() const { |
101 return target_level_dbfs_; | 101 return target_level_dbfs_; |
102 } | 102 } |
103 | 103 |
104 float Agc::voice_probability() const { | 104 float Agc::voice_probability() const { |
105 return vad_.last_voice_probability(); | 105 return vad_.last_voice_probability(); |
106 } | 106 } |
107 | 107 |
108 } // namespace webrtc | 108 } // namespace webrtc |
OLD | NEW |