Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1040)

Side by Side Diff: webrtc/modules/audio_processing/agc2/gain_controller2.cc

Issue 2995043002: AGC2 dummy module: fixed gain param, APM integration, audioproc_f adaptation (Closed)
Patch Set: UT fix Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 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/agc2/gain_controller2.h" 11 #include "webrtc/modules/audio_processing/agc2/gain_controller2.h"
12 12
13 #include <cmath>
14
13 #include "webrtc/modules/audio_processing/audio_buffer.h" 15 #include "webrtc/modules/audio_processing/audio_buffer.h"
14 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 16 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
15 #include "webrtc/rtc_base/atomicops.h" 17 #include "webrtc/rtc_base/atomicops.h"
16 #include "webrtc/rtc_base/checks.h" 18 #include "webrtc/rtc_base/checks.h"
17 19
18 namespace webrtc { 20 namespace webrtc {
19 21
20 namespace {
21
22 constexpr float kGain = 0.5f;
23
24 } // namespace
25
26 int GainController2::instance_count_ = 0; 22 int GainController2::instance_count_ = 0;
27 23
28 GainController2::GainController2(int sample_rate_hz) 24 GainController2::GainController2(const float fixed_gain_db)
aleloi 2017/08/15 14:34:02 The list of args will certainly grow. At some poin
peah-webrtc 2017/08/18 04:51:06 I agree, and I think we instead need to adopt the
AleBzk 2017/09/14 09:21:55 Thanks. As per our discussion, I switched to the A
AleBzk 2017/09/14 09:21:55 Done.
29 : sample_rate_hz_(sample_rate_hz), 25 : data_dumper_(new ApmDataDumper(instance_count_)),
30 data_dumper_(new ApmDataDumper( 26 fixed_gain_(std::pow(10.0, fixed_gain_db / 20.0)) {
31 rtc::AtomicOps::Increment(&instance_count_))), 27 Initialize(AudioProcessing::kSampleRate48kHz);
32 digital_gain_applier_(), 28 ++instance_count_;
33 gain_(kGain) {
34 RTC_DCHECK(sample_rate_hz_ == AudioProcessing::kSampleRate8kHz ||
35 sample_rate_hz_ == AudioProcessing::kSampleRate16kHz ||
36 sample_rate_hz_ == AudioProcessing::kSampleRate32kHz ||
37 sample_rate_hz_ == AudioProcessing::kSampleRate48kHz);
38 data_dumper_->InitiateNewSetOfRecordings();
39 data_dumper_->DumpRaw("gain_", 1, &gain_);
40 } 29 }
41 30
42 GainController2::~GainController2() = default; 31 GainController2::~GainController2() = default;
43 32
33 void GainController2::Initialize(int sample_rate_hz) {
34 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz ||
35 sample_rate_hz == AudioProcessing::kSampleRate16kHz ||
36 sample_rate_hz == AudioProcessing::kSampleRate32kHz ||
37 sample_rate_hz == AudioProcessing::kSampleRate48kHz);
aleloi 2017/08/15 14:34:03 Why restriction on sample rates? A complete gain c
peah-webrtc 2017/08/18 04:51:06 Regarding being sample rate agnostic, I agree, but
aleloi 2017/08/18 08:28:31 Acknowledged. Keep Initialize because re-creating
AleBzk 2017/09/14 09:21:54 Acknowledged.
AleBzk 2017/09/14 09:21:55 This dummy AGC2 module does work at any sample rat
AleBzk 2017/09/14 09:21:55 Acknowledged.
38 data_dumper_->InitiateNewSetOfRecordings();
39 data_dumper_->DumpRaw("fixed gain (linear)", fixed_gain_);
40 sample_rate_hz_ = sample_rate_hz;
41 }
42
44 void GainController2::Process(AudioBuffer* audio) { 43 void GainController2::Process(AudioBuffer* audio) {
aleloi 2017/08/15 14:34:03 Can you please add a DCHECK for the correct rate h
AleBzk 2017/09/14 09:21:55 Unfortunately not. AudioBuffer doesn't have a samp
44 bool saturated_frame = false;
45 for (size_t k = 0; k < audio->num_channels(); ++k) { 45 for (size_t k = 0; k < audio->num_channels(); ++k) {
46 auto channel_view = rtc::ArrayView<float>( 46 for (size_t j = 0; j < audio->num_frames(); ++j) {
47 audio->channels_f()[k], audio->num_frames()); 47 audio->channels_f()[k][j] = std::min(
48 digital_gain_applier_.Process(gain_, channel_view); 48 32767.f, std::max(-32768.f, fixed_gain_ * audio->channels_f()[k][j]));
aleloi 2017/08/15 14:34:03 I think we can use SafeClamp or similar here: http
AleBzk 2017/09/14 09:21:55 Done.
49 if (audio->channels_f()[k][j] == -32768.f ||
50 audio->channels_f()[k][j] == 32767.f) {
51 saturated_frame = true;
52 }
53 }
54 }
55
56 if (saturated_frame) {
57 data_dumper_->DumpRaw("saturated frame detected", true);
49 } 58 }
50 } 59 }
51 60
52 bool GainController2::Validate( 61 bool GainController2::Validate(
53 const AudioProcessing::Config::GainController2& config) { 62 const AudioProcessing::Config::GainController2& config) {
54 return true; 63 return config.fixed_gain_db >= 0.f;
aleloi 2017/08/15 14:34:03 Does it only make sense to use this module for amp
AleBzk 2017/09/14 09:21:55 I'd say yes. I don't see any useful application fo
55 } 64 }
56 65
57 std::string GainController2::ToString( 66 std::string GainController2::ToString(
58 const AudioProcessing::Config::GainController2& config) { 67 const AudioProcessing::Config::GainController2& config) {
59 std::stringstream ss; 68 std::stringstream ss;
60 ss << "{" 69 ss << "{"
61 << "enabled: " << (config.enabled ? "true" : "false") << "}"; 70 << "enabled: " << (config.enabled ? "true" : "false") << ", "
71 << "fixed_gain_dB: " << config.fixed_gain_db << "}";
62 return ss.str(); 72 return ss.str();
63 } 73 }
64 74
65 } // namespace webrtc 75 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698