blob: 6c1ce45e70990e69b386305735f7b1f8e2ecd924 [file] [log] [blame]
alessiob3ec96df2017-05-22 06:57:06 -07001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/agc2/gain_controller2.h"
alessiob3ec96df2017-05-22 06:57:06 -070012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_processing/audio_buffer.h"
14#include "modules/audio_processing/logging/apm_data_dumper.h"
15#include "rtc_base/atomicops.h"
16#include "rtc_base/checks.h"
alessiob3ec96df2017-05-22 06:57:06 -070017
18namespace webrtc {
19
20namespace {
21
22constexpr float kGain = 0.5f;
23
24} // namespace
25
26int GainController2::instance_count_ = 0;
27
28GainController2::GainController2(int sample_rate_hz)
29 : sample_rate_hz_(sample_rate_hz),
30 data_dumper_(new ApmDataDumper(
31 rtc::AtomicOps::Increment(&instance_count_))),
32 digital_gain_applier_(),
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}
41
42GainController2::~GainController2() = default;
43
44void GainController2::Process(AudioBuffer* audio) {
45 for (size_t k = 0; k < audio->num_channels(); ++k) {
46 auto channel_view = rtc::ArrayView<float>(
47 audio->channels_f()[k], audio->num_frames());
48 digital_gain_applier_.Process(gain_, channel_view);
49 }
50}
51
52bool GainController2::Validate(
53 const AudioProcessing::Config::GainController2& config) {
54 return true;
55}
56
57std::string GainController2::ToString(
58 const AudioProcessing::Config::GainController2& config) {
59 std::stringstream ss;
60 ss << "{"
61 << "enabled: " << (config.enabled ? "true" : "false") << "}";
62 return ss.str();
63}
64
65} // namespace webrtc