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

Unified 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: comments addressed Created 3 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/agc2/gain_controller2.cc
diff --git a/webrtc/modules/audio_processing/agc2/gain_controller2.cc b/webrtc/modules/audio_processing/agc2/gain_controller2.cc
index 20680f64a840eee3aa1c63ee8cb23d8dfdf0dae2..bdfd87dd843f9c8d9a44f33676086e40b272b4b4 100644
--- a/webrtc/modules/audio_processing/agc2/gain_controller2.cc
+++ b/webrtc/modules/audio_processing/agc2/gain_controller2.cc
@@ -10,55 +10,77 @@
#include "webrtc/modules/audio_processing/agc2/gain_controller2.h"
+#include <cmath>
+
#include "webrtc/modules/audio_processing/audio_buffer.h"
#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
#include "webrtc/rtc_base/atomicops.h"
#include "webrtc/rtc_base/checks.h"
+#include "webrtc/rtc_base/safe_minmax.h"
namespace webrtc {
-namespace {
-
-constexpr float kGain = 0.5f;
-
-} // namespace
-
int GainController2::instance_count_ = 0;
-GainController2::GainController2(int sample_rate_hz)
- : sample_rate_hz_(sample_rate_hz),
- data_dumper_(new ApmDataDumper(
- rtc::AtomicOps::Increment(&instance_count_))),
- digital_gain_applier_(),
- gain_(kGain) {
- RTC_DCHECK(sample_rate_hz_ == AudioProcessing::kSampleRate8kHz ||
- sample_rate_hz_ == AudioProcessing::kSampleRate16kHz ||
- sample_rate_hz_ == AudioProcessing::kSampleRate32kHz ||
- sample_rate_hz_ == AudioProcessing::kSampleRate48kHz);
- data_dumper_->InitiateNewSetOfRecordings();
- data_dumper_->DumpRaw("gain_", 1, &gain_);
+GainController2::GainController2()
+ : data_dumper_(new ApmDataDumper(instance_count_)),
peah-webrtc 2017/09/15 07:44:25 You need to increase instance_count_ for each new
AleBzk 2017/09/29 09:39:06 Done, but note that I took LC as reference, in whi
+ sample_rate_hz_(0),
peah-webrtc 2017/09/15 07:44:25 Please initialize the sample rate to a valid rate.
AleBzk 2017/09/29 09:39:06 Done.
+ fixed_gain_(1.f) {
+ ++instance_count_;
peah-webrtc 2017/09/15 07:44:25 Please remove this increase and instead do it as a
AleBzk 2017/09/29 09:39:06 Done.
}
GainController2::~GainController2() = default;
+void GainController2::Initialize(int sample_rate_hz) {
+ RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz ||
+ sample_rate_hz == AudioProcessing::kSampleRate16kHz ||
+ sample_rate_hz == AudioProcessing::kSampleRate32kHz ||
+ sample_rate_hz == AudioProcessing::kSampleRate48kHz);
+ data_dumper_->InitiateNewSetOfRecordings();
+ data_dumper_->DumpRaw("fixed gain (linear)", fixed_gain_);
peah-webrtc 2017/09/15 07:44:25 Does filenames with spaces and parenthesis always
AleBzk 2017/09/29 09:39:06 Done.
+ sample_rate_hz_ = sample_rate_hz;
+}
+
void GainController2::Process(AudioBuffer* audio) {
+ if (fixed_gain_ == 1.f)
+ return;
+
+ bool saturated_frame = false;
for (size_t k = 0; k < audio->num_channels(); ++k) {
- auto channel_view = rtc::ArrayView<float>(
- audio->channels_f()[k], audio->num_frames());
- digital_gain_applier_.Process(gain_, channel_view);
+ for (size_t j = 0; j < audio->num_frames(); ++j) {
+ audio->channels_f()[k][j] = rtc::SafeClamp(
+ fixed_gain_ * audio->channels_f()[k][j], -32768.f, 32767.f);
+ if (audio->channels_f()[k][j] == -32768.f ||
peah-webrtc 2017/09/15 07:44:25 This is only used for the purpose of the DumpRaw c
AleBzk 2017/09/29 09:39:06 Done.
+ audio->channels_f()[k][j] == 32767.f) {
+ saturated_frame = true;
+ }
+ }
+ }
+
+ if (saturated_frame) {
+ data_dumper_->DumpRaw("saturated frame detected", true);
}
}
+void GainController2::ApplyConfig(
+ const AudioProcessing::Config::GainController2& config) {
+ RTC_DCHECK(Validate(config));
+ fixed_gain_ = (config.fixed_gain_db == 0.f)
peah-webrtc 2017/09/15 07:44:25 The parentheses are not needed here.
AleBzk 2017/09/29 09:39:06 Done.
+ ? 1.f
+ : std::pow(10.0, config.fixed_gain_db / 20.0);
+}
+
bool GainController2::Validate(
const AudioProcessing::Config::GainController2& config) {
- return true;
+ return config.fixed_gain_db >= 0.f;
}
std::string GainController2::ToString(
const AudioProcessing::Config::GainController2& config) {
std::stringstream ss;
ss << "{"
- << "enabled: " << (config.enabled ? "true" : "false") << "}";
+ << "enabled: " << (config.enabled ? "true" : "false") << ", "
+ << "fixed_gain_dB: " << config.fixed_gain_db << "}";
return ss.str();
}

Powered by Google App Engine
This is Rietveld 408576698