Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 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 | |
| 11 #include "webrtc/modules/audio_processing/agc2/gain_controller2.h" | |
| 12 | |
| 13 #include "webrtc/base/atomicops.h" | |
| 14 #include "webrtc/base/checks.h" | |
| 15 #include "webrtc/modules/audio_processing/audio_buffer.h" | |
| 16 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | |
| 17 | |
| 18 namespace webrtc { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 constexpr float kGain = 0.9f; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 int GainController2::instance_count_ = 0; | |
| 27 | |
| 28 GainController2::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 | |
| 42 GainController2::~GainController2() = default; | |
| 43 | |
| 44 void GainController2::Process(AudioBuffer* audio) { | |
| 45 RTC_DCHECK_LT(0, audio->num_channels()); | |
|
peah-webrtc
2017/05/18 12:27:05
Since you anyway store sample_rate_hz_, I'd sugges
peah-webrtc
2017/05/18 12:27:05
Is this DCHECK necessary? It will fail for 0 numbe
AleBzk
2017/05/19 13:15:41
I couldn't find any sample_rate property in AudioB
peah-webrtc
2017/05/22 08:16:00
Ah, sorry, I forgot about it not being present.
P
| |
| 46 for (size_t k = 0; k < audio->num_channels(); ++k) { | |
| 47 auto channel_view = rtc::ArrayView<float>( | |
| 48 audio->channels_f()[k], audio->num_frames()); | |
| 49 digital_gain_applier_.Process(gain_, channel_view); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 bool GainController2::Validate( | |
| 54 const AudioProcessing::Config::GainController2& config) { | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 std::string GainController2::ToString( | |
| 59 const AudioProcessing::Config::GainController2& config) { | |
| 60 std::stringstream ss; | |
| 61 ss << "{" | |
| 62 << "enabled: " << (config.enabled ? "true" : "false") << "}"; | |
| 63 return ss.str(); | |
| 64 } | |
| 65 | |
| 66 } // namespace webrtc | |
| OLD | NEW |