Update audio_processing module
Corresponds to upstream commit 524e9b043e7e86fd72353b987c9d5f6a1ebf83e1 Update notes: * Pull in third party license file * Replace .gypi files with BUILD.gn to keep track of what changes upstream * Bunch of new filse pulled in as dependencies * Won't build yet due to changes needed on top of these
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
@ -8,54 +8,38 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "gain_control_impl.h"
|
||||
#include "webrtc/modules/audio_processing/gain_control_impl.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <assert.h>
|
||||
|
||||
#include "critical_section_wrapper.h"
|
||||
#include "gain_control.h"
|
||||
|
||||
#include "audio_processing_impl.h"
|
||||
#include "audio_buffer.h"
|
||||
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
||||
#include "webrtc/modules/audio_processing/agc/legacy/gain_control.h"
|
||||
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
typedef void Handle;
|
||||
|
||||
/*template <class T>
|
||||
class GainControlHandle : public ComponentHandle<T> {
|
||||
public:
|
||||
GainControlHandle();
|
||||
virtual ~GainControlHandle();
|
||||
|
||||
virtual int Create();
|
||||
virtual T* ptr() const;
|
||||
|
||||
private:
|
||||
T* handle;
|
||||
};*/
|
||||
|
||||
namespace {
|
||||
WebRtc_Word16 MapSetting(GainControl::Mode mode) {
|
||||
int16_t MapSetting(GainControl::Mode mode) {
|
||||
switch (mode) {
|
||||
case GainControl::kAdaptiveAnalog:
|
||||
return kAgcModeAdaptiveAnalog;
|
||||
break;
|
||||
case GainControl::kAdaptiveDigital:
|
||||
return kAgcModeAdaptiveDigital;
|
||||
break;
|
||||
case GainControl::kFixedDigital:
|
||||
return kAgcModeFixedDigital;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
assert(false);
|
||||
return -1;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
GainControlImpl::GainControlImpl(const AudioProcessingImpl* apm)
|
||||
: ProcessingComponent(apm),
|
||||
GainControlImpl::GainControlImpl(const AudioProcessing* apm,
|
||||
CriticalSectionWrapper* crit)
|
||||
: ProcessingComponent(),
|
||||
apm_(apm),
|
||||
crit_(crit),
|
||||
mode_(kAdaptiveAnalog),
|
||||
minimum_capture_level_(0),
|
||||
maximum_capture_level_(255),
|
||||
@ -73,20 +57,14 @@ int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) {
|
||||
return apm_->kNoError;
|
||||
}
|
||||
|
||||
assert(audio->samples_per_split_channel() <= 160);
|
||||
|
||||
WebRtc_Word16* mixed_data = audio->low_pass_split_data(0);
|
||||
if (audio->num_channels() > 1) {
|
||||
audio->CopyAndMixLowPass(1);
|
||||
mixed_data = audio->mixed_low_pass_data(0);
|
||||
}
|
||||
assert(audio->num_frames_per_band() <= 160);
|
||||
|
||||
for (int i = 0; i < num_handles(); i++) {
|
||||
Handle* my_handle = static_cast<Handle*>(handle(i));
|
||||
int err = WebRtcAgc_AddFarend(
|
||||
my_handle,
|
||||
mixed_data,
|
||||
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()));
|
||||
audio->mixed_low_pass_data(),
|
||||
audio->num_frames_per_band());
|
||||
|
||||
if (err != apm_->kNoError) {
|
||||
return GetHandleError(my_handle);
|
||||
@ -101,19 +79,20 @@ int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
||||
return apm_->kNoError;
|
||||
}
|
||||
|
||||
assert(audio->samples_per_split_channel() <= 160);
|
||||
assert(audio->num_frames_per_band() <= 160);
|
||||
assert(audio->num_channels() == num_handles());
|
||||
|
||||
int err = apm_->kNoError;
|
||||
|
||||
if (mode_ == kAdaptiveAnalog) {
|
||||
capture_levels_.assign(num_handles(), analog_capture_level_);
|
||||
for (int i = 0; i < num_handles(); i++) {
|
||||
Handle* my_handle = static_cast<Handle*>(handle(i));
|
||||
err = WebRtcAgc_AddMic(
|
||||
my_handle,
|
||||
audio->low_pass_split_data(i),
|
||||
audio->high_pass_split_data(i),
|
||||
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()));
|
||||
audio->split_bands(i),
|
||||
audio->num_bands(),
|
||||
audio->num_frames_per_band());
|
||||
|
||||
if (err != apm_->kNoError) {
|
||||
return GetHandleError(my_handle);
|
||||
@ -123,14 +102,13 @@ int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
|
||||
|
||||
for (int i = 0; i < num_handles(); i++) {
|
||||
Handle* my_handle = static_cast<Handle*>(handle(i));
|
||||
WebRtc_Word32 capture_level_out = 0;
|
||||
int32_t capture_level_out = 0;
|
||||
|
||||
err = WebRtcAgc_VirtualMic(
|
||||
my_handle,
|
||||
audio->low_pass_split_data(i),
|
||||
audio->high_pass_split_data(i),
|
||||
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()),
|
||||
//capture_levels_[i],
|
||||
audio->split_bands(i),
|
||||
audio->num_bands(),
|
||||
audio->num_frames_per_band(),
|
||||
analog_capture_level_,
|
||||
&capture_level_out);
|
||||
|
||||
@ -155,22 +133,21 @@ int GainControlImpl::ProcessCaptureAudio(AudioBuffer* audio) {
|
||||
return apm_->kStreamParameterNotSetError;
|
||||
}
|
||||
|
||||
assert(audio->samples_per_split_channel() <= 160);
|
||||
assert(audio->num_frames_per_band() <= 160);
|
||||
assert(audio->num_channels() == num_handles());
|
||||
|
||||
stream_is_saturated_ = false;
|
||||
for (int i = 0; i < num_handles(); i++) {
|
||||
Handle* my_handle = static_cast<Handle*>(handle(i));
|
||||
WebRtc_Word32 capture_level_out = 0;
|
||||
WebRtc_UWord8 saturation_warning = 0;
|
||||
int32_t capture_level_out = 0;
|
||||
uint8_t saturation_warning = 0;
|
||||
|
||||
int err = WebRtcAgc_Process(
|
||||
my_handle,
|
||||
audio->low_pass_split_data(i),
|
||||
audio->high_pass_split_data(i),
|
||||
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()),
|
||||
audio->low_pass_split_data(i),
|
||||
audio->high_pass_split_data(i),
|
||||
audio->split_bands_const(i),
|
||||
audio->num_bands(),
|
||||
audio->num_frames_per_band(),
|
||||
audio->split_bands(i),
|
||||
capture_levels_[i],
|
||||
&capture_level_out,
|
||||
apm_->echo_cancellation()->stream_has_echo(),
|
||||
@ -202,17 +179,11 @@ int GainControlImpl::ProcessCaptureAudio(AudioBuffer* audio) {
|
||||
|
||||
// TODO(ajm): ensure this is called under kAdaptiveAnalog.
|
||||
int GainControlImpl::set_stream_analog_level(int level) {
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
was_analog_level_set_ = true;
|
||||
if (level < minimum_capture_level_ || level > maximum_capture_level_) {
|
||||
return apm_->kBadParameterError;
|
||||
}
|
||||
|
||||
if (mode_ == kAdaptiveAnalog) {
|
||||
if (level != analog_capture_level_) {
|
||||
// The analog level has been changed; update our internal levels.
|
||||
capture_levels_.assign(num_handles(), level);
|
||||
}
|
||||
}
|
||||
analog_capture_level_ = level;
|
||||
|
||||
return apm_->kNoError;
|
||||
@ -226,7 +197,7 @@ int GainControlImpl::stream_analog_level() {
|
||||
}
|
||||
|
||||
int GainControlImpl::Enable(bool enable) {
|
||||
CriticalSectionScoped crit_scoped(*apm_->crit());
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
return EnableComponent(enable);
|
||||
}
|
||||
|
||||
@ -235,7 +206,7 @@ bool GainControlImpl::is_enabled() const {
|
||||
}
|
||||
|
||||
int GainControlImpl::set_mode(Mode mode) {
|
||||
CriticalSectionScoped crit_scoped(*apm_->crit());
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
if (MapSetting(mode) == -1) {
|
||||
return apm_->kBadParameterError;
|
||||
}
|
||||
@ -250,7 +221,7 @@ GainControl::Mode GainControlImpl::mode() const {
|
||||
|
||||
int GainControlImpl::set_analog_level_limits(int minimum,
|
||||
int maximum) {
|
||||
CriticalSectionScoped crit_scoped(*apm_->crit());
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
if (minimum < 0) {
|
||||
return apm_->kBadParameterError;
|
||||
}
|
||||
@ -282,7 +253,7 @@ bool GainControlImpl::stream_is_saturated() const {
|
||||
}
|
||||
|
||||
int GainControlImpl::set_target_level_dbfs(int level) {
|
||||
CriticalSectionScoped crit_scoped(*apm_->crit());
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
if (level > 31 || level < 0) {
|
||||
return apm_->kBadParameterError;
|
||||
}
|
||||
@ -296,7 +267,7 @@ int GainControlImpl::target_level_dbfs() const {
|
||||
}
|
||||
|
||||
int GainControlImpl::set_compression_gain_db(int gain) {
|
||||
CriticalSectionScoped crit_scoped(*apm_->crit());
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
if (gain < 0 || gain > 90) {
|
||||
return apm_->kBadParameterError;
|
||||
}
|
||||
@ -310,7 +281,7 @@ int GainControlImpl::compression_gain_db() const {
|
||||
}
|
||||
|
||||
int GainControlImpl::enable_limiter(bool enable) {
|
||||
CriticalSectionScoped crit_scoped(*apm_->crit());
|
||||
CriticalSectionScoped crit_scoped(crit_);
|
||||
limiter_enabled_ = enable;
|
||||
return Configure();
|
||||
}
|
||||
@ -325,35 +296,16 @@ int GainControlImpl::Initialize() {
|
||||
return err;
|
||||
}
|
||||
|
||||
analog_capture_level_ =
|
||||
(maximum_capture_level_ - minimum_capture_level_) >> 1;
|
||||
capture_levels_.assign(num_handles(), analog_capture_level_);
|
||||
was_analog_level_set_ = false;
|
||||
|
||||
return apm_->kNoError;
|
||||
}
|
||||
|
||||
int GainControlImpl::get_version(char* version, int version_len_bytes) const {
|
||||
if (WebRtcAgc_Version(version, version_len_bytes) != 0) {
|
||||
return apm_->kBadParameterError;
|
||||
}
|
||||
|
||||
return apm_->kNoError;
|
||||
}
|
||||
|
||||
void* GainControlImpl::CreateHandle() const {
|
||||
Handle* handle = NULL;
|
||||
if (WebRtcAgc_Create(&handle) != apm_->kNoError) {
|
||||
handle = NULL;
|
||||
} else {
|
||||
assert(handle != NULL);
|
||||
}
|
||||
|
||||
return handle;
|
||||
return WebRtcAgc_Create();
|
||||
}
|
||||
|
||||
int GainControlImpl::DestroyHandle(void* handle) const {
|
||||
return WebRtcAgc_Free(static_cast<Handle*>(handle));
|
||||
void GainControlImpl::DestroyHandle(void* handle) const {
|
||||
WebRtcAgc_Free(static_cast<Handle*>(handle));
|
||||
}
|
||||
|
||||
int GainControlImpl::InitializeHandle(void* handle) const {
|
||||
@ -361,18 +313,18 @@ int GainControlImpl::InitializeHandle(void* handle) const {
|
||||
minimum_capture_level_,
|
||||
maximum_capture_level_,
|
||||
MapSetting(mode_),
|
||||
apm_->sample_rate_hz());
|
||||
apm_->proc_sample_rate_hz());
|
||||
}
|
||||
|
||||
int GainControlImpl::ConfigureHandle(void* handle) const {
|
||||
WebRtcAgc_config_t config;
|
||||
WebRtcAgcConfig config;
|
||||
// TODO(ajm): Flip the sign here (since AGC expects a positive value) if we
|
||||
// change the interface.
|
||||
//assert(target_level_dbfs_ <= 0);
|
||||
//config.targetLevelDbfs = static_cast<WebRtc_Word16>(-target_level_dbfs_);
|
||||
config.targetLevelDbfs = static_cast<WebRtc_Word16>(target_level_dbfs_);
|
||||
//config.targetLevelDbfs = static_cast<int16_t>(-target_level_dbfs_);
|
||||
config.targetLevelDbfs = static_cast<int16_t>(target_level_dbfs_);
|
||||
config.compressionGaindB =
|
||||
static_cast<WebRtc_Word16>(compression_gain_db_);
|
||||
static_cast<int16_t>(compression_gain_db_);
|
||||
config.limiterEnable = limiter_enabled_;
|
||||
|
||||
return WebRtcAgc_set_config(static_cast<Handle*>(handle), config);
|
||||
|
Reference in New Issue
Block a user