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 19 matching lines...) Expand all Loading... | |
30 case GainControl::kFixedDigital: | 30 case GainControl::kFixedDigital: |
31 return kAgcModeFixedDigital; | 31 return kAgcModeFixedDigital; |
32 } | 32 } |
33 assert(false); | 33 assert(false); |
34 return -1; | 34 return -1; |
35 } | 35 } |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 GainControlImpl::GainControlImpl(const AudioProcessing* apm, | 38 GainControlImpl::GainControlImpl(const AudioProcessing* apm, |
39 CriticalSectionWrapper* crit) | 39 CriticalSectionWrapper* crit) |
40 : ProcessingComponent(), | 40 : ProcessingComponent(), |
41 apm_(apm), | 41 apm_(apm), |
42 crit_(crit), | 42 crit_(crit), |
43 mode_(kAdaptiveAnalog), | 43 mode_(kAdaptiveAnalog), |
44 minimum_capture_level_(0), | 44 minimum_capture_level_(0), |
45 maximum_capture_level_(255), | 45 maximum_capture_level_(255), |
46 limiter_enabled_(true), | 46 limiter_enabled_(true), |
47 target_level_dbfs_(3), | 47 target_level_dbfs_(3), |
48 compression_gain_db_(9), | 48 compression_gain_db_(9), |
49 analog_capture_level_(0), | 49 analog_capture_level_(0), |
50 was_analog_level_set_(false), | 50 was_analog_level_set_(false), |
51 stream_is_saturated_(false) {} | 51 stream_is_saturated_(false), |
52 render_queue_buffer_(kNumSamplesPerFrameToBuffer), | |
53 capture_queue_buffer_(kNumSamplesPerFrameToBuffer) { | |
54 std::vector<int16_t> template_queue_element(kNumSamplesPerFrameToBuffer); | |
55 | |
56 render_signal_queue_.reset( | |
57 new SwapQueue<std::vector<int16_t>, &RenderQueueItemVerifier>( | |
58 (kMaxNumFramesToBuffer * kMaxNumChannelsPerFrameToBuffer), | |
59 template_queue_element)); | |
60 } | |
52 | 61 |
53 GainControlImpl::~GainControlImpl() {} | 62 GainControlImpl::~GainControlImpl() {} |
54 | 63 |
55 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { | 64 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
56 if (!is_component_enabled()) { | 65 if (!is_component_enabled()) { |
57 return apm_->kNoError; | 66 return apm_->kNoError; |
58 } | 67 } |
59 | 68 |
60 assert(audio->num_frames_per_band() <= 160); | 69 assert(audio->num_frames_per_band() <= 160); |
61 | 70 |
62 for (int i = 0; i < num_handles(); i++) { | 71 for (int i = 0; i < num_handles(); i++) { |
63 Handle* my_handle = static_cast<Handle*>(handle(i)); | 72 Handle* my_handle = static_cast<Handle*>(handle(i)); |
64 int err = WebRtcAgc_AddFarend( | 73 int err = |
65 my_handle, | 74 WebRtcAgc_GetAddFarendError(my_handle, audio->num_frames_per_band()); |
66 audio->mixed_low_pass_data(), | |
67 audio->num_frames_per_band()); | |
68 | 75 |
69 if (err != apm_->kNoError) { | 76 if (err != apm_->kNoError) |
70 return GetHandleError(my_handle); | 77 return GetHandleError(my_handle); |
71 } | 78 |
79 // Buffer the samples in the render queue. | |
80 // TODO(peah): Do a proper size check agains the actual sample size | |
81 // once the APM properly checks the sample type passed the AGC. | |
the sun
2015/10/19 14:47:04
// TODO: Remove copying.
peah-webrtc
2015/10/26 09:09:56
This has now been refactored. Please recheck!
| |
82 memcpy(&render_queue_buffer_[0], audio->mixed_low_pass_data(), | |
83 (audio->num_frames_per_band() * sizeof(int16_t))); | |
84 render_queue_buffer_.resize(audio->num_frames_per_band()); | |
85 // TODO(peah): Refactor so that it is possible to check the | |
86 // return value of Insert. Currently, that is not possible | |
87 // due to the code design when the capture thread is never | |
88 // started. | |
89 render_signal_queue_->Insert(&render_queue_buffer_); | |
72 } | 90 } |
73 | 91 |
74 return apm_->kNoError; | 92 return apm_->kNoError; |
75 } | 93 } |
76 | 94 |
95 // Read chunks of data that were received and queued on the render side from | |
96 // a queue. All the data chunks are buffered into the farend signal of the AGC. | |
97 void GainControlImpl::ReadQueuedRenderData() { | |
98 if (!is_component_enabled()) { | |
99 return; | |
100 } | |
101 | |
102 while (render_signal_queue_->Remove(&capture_queue_buffer_)) { | |
103 for (int i = 0; i < num_handles(); i++) { | |
104 Handle* my_handle = static_cast<Handle*>(handle(i)); | |
105 (void)WebRtcAgc_AddFarend(my_handle, &capture_queue_buffer_[0], | |
106 capture_queue_buffer_.size()); | |
107 } | |
108 } | |
109 } | |
110 | |
77 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { | 111 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
78 if (!is_component_enabled()) { | 112 if (!is_component_enabled()) { |
79 return apm_->kNoError; | 113 return apm_->kNoError; |
80 } | 114 } |
81 | 115 |
82 assert(audio->num_frames_per_band() <= 160); | 116 assert(audio->num_frames_per_band() <= 160); |
83 assert(audio->num_channels() == num_handles()); | 117 assert(audio->num_channels() == num_handles()); |
84 | 118 |
85 int err = apm_->kNoError; | 119 int err = apm_->kNoError; |
86 | 120 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 int GainControlImpl::num_handles_required() const { | 367 int GainControlImpl::num_handles_required() const { |
334 return apm_->num_output_channels(); | 368 return apm_->num_output_channels(); |
335 } | 369 } |
336 | 370 |
337 int GainControlImpl::GetHandleError(void* handle) const { | 371 int GainControlImpl::GetHandleError(void* handle) const { |
338 // The AGC has no get_error() function. | 372 // The AGC has no get_error() function. |
339 // (Despite listing errors in its interface...) | 373 // (Despite listing errors in its interface...) |
340 assert(handle != NULL); | 374 assert(handle != NULL); |
341 return apm_->kUnspecifiedError; | 375 return apm_->kUnspecifiedError; |
342 } | 376 } |
377 | |
378 bool GainControlImpl::RenderQueueItemVerifier(const std::vector<int16_t>& v) { | |
379 return (v.size() == kNumSamplesPerFrameToBuffer); | |
380 } | |
343 } // namespace webrtc | 381 } // namespace webrtc |
OLD | NEW |