Adding all necessary MapSetting and MapError functions. This doesn't alter the existing functionality but just "formalizes" the mapping layer for the underlying components.

Review URL: http://webrtc-codereview.appspot.com/44002

git-svn-id: http://webrtc.googlecode.com/svn/trunk@111 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
ajm@google.com 2011-06-21 12:58:27 +00:00
parent 33bb406f22
commit 909118894b
17 changed files with 151 additions and 356 deletions

View File

@ -24,6 +24,19 @@ namespace webrtc {
typedef void Handle;
namespace {
WebRtc_Word16 MapSetting(EchoCancellation::SuppressionLevel level) {
switch (level) {
case EchoCancellation::kLowSuppression:
return kAecNlpConservative;
case EchoCancellation::kModerateSuppression:
return kAecNlpModerate;
case EchoCancellation::kHighSuppression:
return kAecNlpAggressive;
default:
return -1;
}
}
int MapError(int err) {
switch (err) {
case AEC_UNSUPPORTED_FUNCTION_ERROR:
@ -164,9 +177,7 @@ bool EchoCancellationImpl::is_enabled() const {
int EchoCancellationImpl::set_suppression_level(SuppressionLevel level) {
CriticalSectionScoped crit_scoped(*apm_->crit());
if (level != kLowSuppression &&
level != kModerateSuppression &&
level != kHighSuppression) {
if (MapSetting(level) == -1) {
return apm_->kBadParameterError;
}
@ -315,27 +326,11 @@ int EchoCancellationImpl::InitializeHandle(void* handle) const {
device_sample_rate_hz_);
}
/*int EchoCancellationImpl::InitializeHandles(
const vector<void*>& handles) const {
int err = apm_->kNoError;
for (size_t i = 0; i < num_handles(); i++) {
err = WebRtcAec_Init(static_cast<Handle*>(handles[i]),
apm_->SampleRateHz(),
device_sample_rate_hz_);
if (err != apm_->kNoError) {
return TranslateError(err);
}
}
return apm_->kNoError;
}*/
int EchoCancellationImpl::ConfigureHandle(void* handle) const {
assert(handle != NULL);
AecConfig config;
config.metricsMode = metrics_enabled_;
config.nlpMode = suppression_level_;
config.nlpMode = MapSetting(suppression_level_);
config.skewMode = drift_compensation_enabled_;
return WebRtcAec_set_config(static_cast<Handle*>(handle), config);
@ -351,43 +346,3 @@ int EchoCancellationImpl::GetHandleError(void* handle) const {
return MapError(WebRtcAec_get_error_code(static_cast<Handle*>(handle)));
}
} // namespace webrtc
/*int EchoCancellationImpl::GetConfiguration(void* handle) {
if (!initialized_) {
return apm_->kNoError;
}
AecConfig config;
int err = WebRtcAec_get_config(handle, &config);
if (err != apm_->kNoError) {
return TranslateError(err);
}
if (config.metricsMode == 0) {
metrics_enabled_ = false;
} else if (config.metricsMode == 1) {
metrics_enabled_ = true;
} else {
return apm_->kUnspecifiedError;
}
if (config.nlpMode == kAecNlpConservative) {
suppression_level_ = kLowSuppression;
} else if (config.nlpMode == kAecNlpModerate) {
suppression_level_ = kModerateSuppression;
} else if (config.nlpMode == kAecNlpAggressive) {
suppression_level_ = kHighSuppression;
} else {
return apm_->kUnspecifiedError;
}
if (config.skewMode == 0) {
drift_compensation_enabled_ = false;
} else if (config.skewMode == 1) {
drift_compensation_enabled_ = true;
} else {
return apm_->kUnspecifiedError;
}
return apm_->kNoError;
}*/

View File

@ -53,12 +53,9 @@ class EchoCancellationImpl : public EchoCancellation,
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
virtual int InitializeHandle(void* handle) const;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const;
virtual int ConfigureHandle(void* handle) const;
virtual int DestroyHandle(void* handle) const;
virtual int num_handles_required() const;
virtual int GetHandleError(void* handle) const;
const AudioProcessingImpl* apm_;

View File

@ -22,6 +22,41 @@ namespace webrtc {
typedef void Handle;
namespace {
WebRtc_Word16 MapSetting(EchoControlMobile::RoutingMode mode) {
switch (mode) {
case EchoControlMobile::kQuietEarpieceOrHeadset:
return 0;
case EchoControlMobile::kEarpiece:
return 1;
case EchoControlMobile::kLoudEarpiece:
return 2;
case EchoControlMobile::kSpeakerphone:
return 3;
case EchoControlMobile::kLoudSpeakerphone:
return 4;
default:
return -1;
}
}
int MapError(int err) {
switch (err) {
case AECM_UNSUPPORTED_FUNCTION_ERROR:
return AudioProcessing::kUnsupportedFunctionError;
case AECM_BAD_PARAMETER_ERROR:
return AudioProcessing::kBadParameterError;
case AECM_BAD_PARAMETER_WARNING:
return AudioProcessing::kBadStreamParameterWarning;
default:
// AECMOBFIX_UNSPECIFIED_ERROR
// AECMOBFIX_UNINITIALIZED_ERROR
// AECMOBFIX_NULL_POINTER_ERROR
return AudioProcessing::kUnspecifiedError;
}
}
} // namespace
EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessingImpl* apm)
: ProcessingComponent(apm),
apm_(apm),
@ -44,13 +79,14 @@ int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) {
size_t handle_index = 0;
for (int i = 0; i < apm_->num_output_channels(); i++) {
for (int j = 0; j < audio->num_channels(); j++) {
Handle* my_handle = static_cast<Handle*>(handle(handle_index));
err = WebRtcAecm_BufferFarend(
static_cast<Handle*>(handle(handle_index)),
my_handle,
audio->low_pass_split_data(j),
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()));
if (err != apm_->kNoError) {
return TranslateError(err); // TODO(ajm): warning possible?
return GetHandleError(my_handle); // TODO(ajm): warning possible?
}
handle_index++;
@ -86,8 +122,9 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) {
clean = NULL;
}
for (int j = 0; j < apm_->num_reverse_channels(); j++) {
Handle* my_handle = static_cast<Handle*>(handle(handle_index));
err = WebRtcAecm_Process(
static_cast<Handle*>(handle(handle_index)),
my_handle,
noisy,
clean,
audio->low_pass_split_data(i),
@ -95,7 +132,7 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) {
apm_->stream_delay_ms());
if (err != apm_->kNoError) {
return TranslateError(err); // TODO(ajm): warning possible?
return GetHandleError(my_handle); // TODO(ajm): warning possible?
}
handle_index++;
@ -121,11 +158,7 @@ bool EchoControlMobileImpl::is_enabled() const {
int EchoControlMobileImpl::set_routing_mode(RoutingMode mode) {
CriticalSectionScoped crit_scoped(*apm_->crit());
if (mode != kQuietEarpieceOrHeadset &&
mode != kEarpiece &&
mode != kLoudEarpiece &&
mode != kSpeakerphone &&
mode != kLoudSpeakerphone) {
if (MapSetting(mode) == -1) {
return apm_->kBadParameterError;
}
@ -192,26 +225,10 @@ int EchoControlMobileImpl::InitializeHandle(void* handle) const {
// required by AECM.
}
/*int EchoControlMobileImpl::InitializeHandles(
const vector<void*>& handles) const {
int err = apm_->kNoError;
for (size_t i = 0; i < num_handles(); i++) {
err = WebRtcAec_Init(static_cast<Handle*>(handles[i]),
apm_->SampleRateHz(),
device_sample_rate_hz_);
if (err != apm_->kNoError) {
return TranslateError(err);
}
}
return apm_->kNoError;
}*/
int EchoControlMobileImpl::ConfigureHandle(void* handle) const {
AecmConfig config;
config.cngMode = comfort_noise_enabled_;
config.echoMode = routing_mode_;
config.echoMode = MapSetting(routing_mode_);
return WebRtcAecm_set_config(static_cast<Handle*>(handle), config);
}
@ -221,58 +238,8 @@ int EchoControlMobileImpl::num_handles_required() const {
apm_->num_reverse_channels();
}
int EchoControlMobileImpl::TranslateError(int err) const {
if (err == AECM_UNSUPPORTED_FUNCTION_ERROR) {
return apm_->kUnsupportedFunctionError;
} else if (err == AECM_BAD_PARAMETER_ERROR) {
return apm_->kBadParameterError;
} else if (err == AECM_BAD_PARAMETER_WARNING) {
return apm_->kBadStreamParameterWarning;
} else {
// AECMOBFIX_UNSPECIFIED_ERROR
// AECMOBFIX_UNINITIALIZED_ERROR
// AECMOBFIX_NULL_POINTER_ERROR
return apm_->kUnspecifiedError;
}
int EchoControlMobileImpl::GetHandleError(void* handle) const {
assert(handle != NULL);
return MapError(WebRtcAecm_get_error_code(static_cast<Handle*>(handle)));
}
} // namespace webrtc
/*int EchoControlMobileImpl::GetConfiguration(void* handle) {
if (!initialized_) {
return apm_->kNoError;
}
AecConfig config;
int err = WebRtcAec_get_config(handle, &config);
if (err != apm_->kNoError) {
return TranslateError(err);
}
if (config.metricsMode == 0) {
metrics_enabled_ = false;
} else if (config.metricsMode == 1) {
metrics_enabled_ = true;
} else {
return apm_->kUnspecifiedError;
}
if (config.nlpMode == kAecNlpConservative) {
routing_mode_ = kLowSuppression;
} else if (config.nlpMode == kAecNlpModerate) {
routing_mode_ = kMediumSuppression;
} else if (config.nlpMode == kAecNlpAggressive) {
routing_mode_ = kHighSuppression;
} else {
return apm_->kUnspecifiedError;
}
if (config.skewMode == 0) {
drift_compensation_enabled_ = false;
} else if (config.skewMode == 1) {
drift_compensation_enabled_ = true;
} else {
return apm_->kUnspecifiedError;
}
return apm_->kNoError;
}*/

View File

@ -45,12 +45,10 @@ class EchoControlMobileImpl : public EchoControlMobile,
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
virtual int InitializeHandle(void* handle) const;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const;
virtual int ConfigureHandle(void* handle) const;
virtual int DestroyHandle(void* handle) const;
virtual int num_handles_required() const;
virtual int TranslateError(int err) const;
virtual int GetHandleError(void* handle) const;
const AudioProcessingImpl* apm_;
RoutingMode routing_mode_;

View File

@ -48,7 +48,6 @@ WebRtc_Word16 MapSetting(GainControl::Mode mode) {
return kAgcModeFixedDigital;
break;
default:
assert(false);
return -1;
}
}
@ -83,13 +82,14 @@ int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) {
}
for (int i = 0; i < num_handles(); i++) {
Handle* my_handle = static_cast<Handle*>(handle(i));
int err = WebRtcAgc_AddFarend(
static_cast<Handle*>(handle(i)),
my_handle,
mixed_data,
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()));
if (err != apm_->kNoError) {
return TranslateError(err);
return GetHandleError(my_handle);
}
}
@ -108,32 +108,36 @@ int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
if (mode_ == kAdaptiveAnalog) {
for (int i = 0; i < num_handles(); i++) {
Handle* my_handle = static_cast<Handle*>(handle(i));
err = WebRtcAgc_AddMic(
static_cast<Handle*>(handle(i)),
my_handle,
audio->low_pass_split_data(i),
audio->high_pass_split_data(i),
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()));
if (err != apm_->kNoError) {
return TranslateError(err);
return GetHandleError(my_handle);
}
}
} else if (mode_ == kAdaptiveDigital) {
for (int i = 0; i < num_handles(); i++) {
Handle* my_handle = static_cast<Handle*>(handle(i));
WebRtc_Word32 capture_level_out = 0;
err = WebRtcAgc_VirtualMic(
static_cast<Handle*>(handle(i)),
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],
analog_capture_level_,
&capture_level_out);
capture_levels_[i] = capture_level_out;
if (err != apm_->kNoError) {
return TranslateError(err);
return GetHandleError(my_handle);
}
}
@ -156,11 +160,12 @@ int GainControlImpl::ProcessCaptureAudio(AudioBuffer* audio) {
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;
int err = WebRtcAgc_Process(
static_cast<Handle*>(handle(i)),
my_handle,
audio->low_pass_split_data(i),
audio->high_pass_split_data(i),
static_cast<WebRtc_Word16>(audio->samples_per_split_channel()),
@ -172,7 +177,7 @@ int GainControlImpl::ProcessCaptureAudio(AudioBuffer* audio) {
&saturation_warning);
if (err != apm_->kNoError) {
return TranslateError(err);
return GetHandleError(my_handle);
}
capture_levels_[i] = capture_level_out;
@ -231,9 +236,7 @@ bool GainControlImpl::is_enabled() const {
int GainControlImpl::set_mode(Mode mode) {
CriticalSectionScoped crit_scoped(*apm_->crit());
if (mode != kAdaptiveAnalog &&
mode != kAdaptiveDigital &&
mode != kFixedDigital) {
if (MapSetting(mode) == -1) {
return apm_->kBadParameterError;
}
@ -361,33 +364,6 @@ int GainControlImpl::InitializeHandle(void* handle) const {
apm_->sample_rate_hz());
}
/*int GainControlImpl::InitializeHandles(const vector<void*>& handles)
const {
int err = apm_->kNoError;
err = WebRtcAgc_Init(static_cast<Handle*>(handles[0]),
minimum_capture_level_,
maximum_capture_level_,
mode_,
apm_->SampleRateHz());
if (err != apm_->kNoError) {
return TranslateError(err);
}
for (size_t i = 1; i < num_handles(); i++) {
WebRtcAgc_Init(static_cast<Handle*>(handles[i]),
minimum_capture_level_,
maximum_capture_level_,
kFixedDigital,
apm_->SampleRateHz());
if (err != apm_->kNoError) {
return TranslateError(err);
}
}
return apm_->kNoError;
}*/
int GainControlImpl::ConfigureHandle(void* handle) const {
WebRtcAgc_config_t config;
// TODO(ajm): Flip the sign here (since AGC expects a positive value) if we
@ -406,40 +382,10 @@ int GainControlImpl::num_handles_required() const {
return apm_->num_output_channels();
}
/*int GainControlImpl::GetConfiguration() {
if (!initialized_) {
return apm_->kNoError;
}
WebRtcAgc_config_t config;
int err = WebRtcAgc_get_config(handle_, &config);
if (err != apm_->kNoError) {
return TranslateError(err);
}
if (config.targetLevelDbfs < 0) {
return apm_->kUnspecifiedError;
}
target_level_dbfs_ = config.targetLevelDbfs;
if (config.compressionGaindB < 0) {
return apm_->kUnspecifiedError;
}
compression_gain_db_ = config.compressionGaindB;
if (config.limiterEnable == 0) {
limiter_enabled_ = false;
} else if (config.limiterEnable == 1) {
limiter_enabled_ = true;
} else {
return apm_->kUnspecifiedError;
}
return apm_->kNoError;
}*/
// TODO(ajm): implement
int GainControlImpl::TranslateError(int /*err*/) const {
return -1;
int GainControlImpl::GetHandleError(void* handle) const {
// The AGC has no get_error() function.
// (Despite listing errors in its interface...)
assert(handle != NULL);
return apm_->kUnspecifiedError;
}
} // namespace webrtc

View File

@ -58,12 +58,10 @@ class GainControlImpl : public GainControl,
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
virtual int InitializeHandle(void* handle) const;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const;
virtual int ConfigureHandle(void* handle) const;
virtual int DestroyHandle(void* handle) const;
virtual int num_handles_required() const;
virtual int TranslateError(int err) const;
virtual int GetHandleError(void* handle) const;
const AudioProcessingImpl* apm_;
Mode mode_;

View File

@ -21,7 +21,6 @@
namespace webrtc {
namespace {
const WebRtc_Word16 kFilterCoefficients8kHz[5] =
{3798, -7596, 3798, 7807, -3733};
@ -92,8 +91,8 @@ int Filter(FilterState* hpf, WebRtc_Word16* data, int length) {
// Saturate (to 2^27) so that the HP filtered signal does not overflow
tmp_int32 = WEBRTC_SPL_SAT(static_cast<WebRtc_Word32>(134217727),
tmp_int32,
static_cast<WebRtc_Word32>(-134217728));
tmp_int32,
static_cast<WebRtc_Word32>(-134217728));
// Convert back to Q0 and use rounding
data[i] = (WebRtc_Word16)WEBRTC_SPL_RSHIFT_W32(tmp_int32, 12);
@ -122,13 +121,13 @@ int HighPassFilterImpl::ProcessCaptureAudio(AudioBuffer* audio) {
assert(audio->samples_per_split_channel() <= 160);
for (int i = 0; i < num_handles(); i++) {
err = Filter(static_cast<Handle*>(handle(i)),
Handle* my_handle = static_cast<Handle*>(handle(i));
err = Filter(my_handle,
audio->low_pass_split_data(i),
audio->samples_per_split_channel());
if (err != apm_->kNoError) {
//return TranslateError(err);
return err;
return GetHandleError(my_handle);
}
}
@ -165,21 +164,6 @@ int HighPassFilterImpl::InitializeHandle(void* handle) const {
apm_->sample_rate_hz());
}
/*int HighPassFilterImpl::InitializeHandles(
const vector<void*>& handles) const {
int err = apm_->kNoError;
for (size_t i = 0; i < num_handles(); i++) {
err = InitializeFilter(static_cast<Handle*>(handles[i]),
apm_->SampleRateHz());
if (err != apm_->kNoError) {
return TranslateError(err);
}
}
return apm_->kNoError;
}*/
int HighPassFilterImpl::ConfigureHandle(void* /*handle*/) const {
return apm_->kNoError; // Not configurable.
}
@ -188,8 +172,9 @@ int HighPassFilterImpl::num_handles_required() const {
return apm_->num_output_channels();
}
// TODO(ajm): implement
int HighPassFilterImpl::TranslateError(int /*err*/) const {
return -1;
int HighPassFilterImpl::GetHandleError(void* handle) const {
// The component has no detailed errors.
assert(handle != NULL);
return apm_->kUnspecifiedError;
}
} // namespace webrtc

View File

@ -39,13 +39,10 @@ class HighPassFilterImpl : public HighPassFilter,
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
virtual int InitializeHandle(void* handle) const;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const;
virtual int ConfigureHandle(void* handle) const;
virtual int DestroyHandle(void* handle) const;
virtual int num_handles_required() const;
virtual int TranslateError(int err) const;
//virtual int GetConfiguration();
virtual int GetHandleError(void* handle) const;
const AudioProcessingImpl* apm_;
};

View File

@ -25,7 +25,6 @@ namespace webrtc {
typedef void Handle;
namespace {
/*int EstimateLevel(AudioBuffer* audio, Handle* my_handle) {
assert(audio->samples_per_split_channel() <= 160);
@ -39,7 +38,7 @@ namespace {
mixed_data,
audio->samples_per_split_channel());
if (err != AudioProcessing::kNoError) {
return TranslateError(err);
return GetHandleError(my_handle);
}
return AudioProcessing::kNoError;
@ -165,20 +164,6 @@ int LevelEstimatorImpl::InitializeHandle(void* /*handle*/) const {
kIntervalSeconds);*/
}
/*int LevelEstimatorImpl::InitializeHandles(
const vector<void*>& handles) const {
int err = apm_->kNoError;
for (size_t i = 0; i < num_handles(); i++) {
err = InitLvlEst(static_cast<Handle*>(handles[i]), apm_->SampleRateHz());
if (err != apm_->kNoError) {
return TranslateError(err);
}
}
return apm_->kNoError;
}*/
int LevelEstimatorImpl::ConfigureHandle(void* /*handle*/) const {
return apm_->kUnsupportedComponentError;
//return apm_->kNoError;
@ -189,9 +174,9 @@ int LevelEstimatorImpl::num_handles_required() const {
//return 2;
}
//int LevelEstimatorImpl::GetConfiguration() {
// // There are no configuration accessors.
// return apm_->kUnsupportedFunctionError;
//}
int LevelEstimatorImpl::GetHandleError(void* handle) const {
// The component has no detailed errors.
assert(handle != NULL);
return apm_->kUnspecifiedError;
}
} // namespace webrtc

View File

@ -41,12 +41,10 @@ class LevelEstimatorImpl : public LevelEstimator,
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
virtual int InitializeHandle(void* handle) const;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const;
virtual int ConfigureHandle(void* handle) const;
virtual int DestroyHandle(void* handle) const;
virtual int num_handles_required() const;
//virtual int TranslateError(int err) const;
virtual int GetHandleError(void* handle) const;
const AudioProcessingImpl* apm_;
};

View File

@ -30,6 +30,23 @@ typedef NsHandle Handle;
typedef NsxHandle Handle;
#endif
namespace {
int MapSetting(NoiseSuppression::Level level) {
switch (level) {
case NoiseSuppression::kLow:
return 0;
case NoiseSuppression::kModerate:
return 1;
case NoiseSuppression::kHigh:
return 2;
case NoiseSuppression::kVeryHigh:
return 3;
default:
return -1;
}
}
} // namespace
NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessingImpl* apm)
: ProcessingComponent(apm),
apm_(apm),
@ -47,6 +64,7 @@ int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
assert(audio->num_channels() == num_handles());
for (int i = 0; i < num_handles(); i++) {
Handle* my_handle = static_cast<Handle*>(handle(i));
#if defined(WEBRTC_NS_FLOAT)
err = WebRtcNs_Process(static_cast<Handle*>(handle(i)),
audio->low_pass_split_data(i),
@ -62,7 +80,7 @@ int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
#endif
if (err != apm_->kNoError) {
return TranslateError(err);
return GetHandleError(my_handle);
}
}
@ -80,10 +98,7 @@ bool NoiseSuppressionImpl::is_enabled() const {
int NoiseSuppressionImpl::set_level(Level level) {
CriticalSectionScoped crit_scoped(*apm_->crit());
if (level != kLow &&
level != kModerate &&
level != kHigh &&
level != kVeryHigh) {
if (MapSetting(level) == -1) {
return apm_->kBadParameterError;
}
@ -141,25 +156,13 @@ int NoiseSuppressionImpl::InitializeHandle(void* handle) const {
#endif
}
/*int NoiseSuppressionImpl::InitializeHandles(
const vector<void*>& handles) const {
int err = apm_->kNoError;
for (size_t i = 0; i < num_handles(); i++) {
err = WebRtcNs_Init(static_cast<Handle*>(handles[i]), apm_->SampleRateHz());
if (err != apm_->kNoError) {
return TranslateError(err);
}
}
return apm_->kNoError;
}*/
int NoiseSuppressionImpl::ConfigureHandle(void* handle) const {
#if defined(WEBRTC_NS_FLOAT)
return WebRtcNs_set_policy(static_cast<Handle*>(handle), level_);
return WebRtcNs_set_policy(static_cast<Handle*>(handle),
MapSetting(level_));
#elif defined(WEBRTC_NS_FIXED)
return WebRtcNsx_set_policy(static_cast<Handle*>(handle), level_);
return WebRtcNsx_set_policy(static_cast<Handle*>(handle),
MapSetting(level_));
#endif
}
@ -167,14 +170,10 @@ int NoiseSuppressionImpl::num_handles_required() const {
return apm_->num_output_channels();
}
//int NoiseSuppressionImpl::GetConfiguration() {
// // There are no configuration accessors.
// return apm_->kUnsupportedFunctionError;
//}
// TODO(ajm): implement
int NoiseSuppressionImpl::TranslateError(int /*err*/) const {
return -1;
int NoiseSuppressionImpl::GetHandleError(void* handle) const {
// The NS has no get_error() function.
assert(handle != NULL);
return apm_->kUnspecifiedError;
}
} // namespace webrtc

View File

@ -41,12 +41,10 @@ class NoiseSuppressionImpl : public NoiseSuppression,
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
virtual int InitializeHandle(void* handle) const;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const;
virtual int ConfigureHandle(void* handle) const;
virtual int DestroyHandle(void* handle) const;
virtual int num_handles_required() const;
virtual int TranslateError(int err) const;
virtual int GetHandleError(void* handle) const;
const AudioProcessingImpl* apm_;
Level level_;

View File

@ -86,13 +86,9 @@ int ProcessingComponent::Initialize() {
int err = InitializeHandle(handles_[i]);
if (err != apm_->kNoError) {
return err;
return GetHandleError(handles_[i]);
}
}
//int err = InitializeHandles(handles_);
//if (err != apm_->kNoError) {
// return TranslateError(err);
//}
initialized_ = true;
return Configure();
@ -107,9 +103,7 @@ int ProcessingComponent::Configure() {
for (int i = 0; i < num_handles_; i++) {
int err = ConfigureHandle(handles_[i]);
if (err != apm_->kNoError) {
// Try to get the current valid state.
//GetConfiguration();
return err;
return GetHandleError(handles_[i]);
}
}

View File

@ -44,18 +44,13 @@ class ProcessingComponent {
void* handle(int index) const;
int num_handles() const;
// TODO(ajm): do we want this?
//virtual int GetConfiguration() = 0;
private:
virtual void* CreateHandle() const = 0;
virtual int InitializeHandle(void* handle) const = 0;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const = 0;
virtual int ConfigureHandle(void* handle) const = 0;
virtual int DestroyHandle(void* handle) const = 0;
virtual int num_handles_required() const = 0;
//virtual int TranslateError(int err) const = 0;
virtual int GetHandleError(void* handle) const = 0;
const AudioProcessingImpl* apm_;
std::vector<void*> handles_;

View File

@ -38,7 +38,6 @@ WebRtc_Word16 MapSetting(VoiceDetection::Likelihood likelihood) {
return 0;
break;
default:
assert(false);
return -1;
}
}
@ -115,10 +114,7 @@ bool VoiceDetectionImpl::stream_has_voice() const {
int VoiceDetectionImpl::set_likelihood(VoiceDetection::Likelihood likelihood) {
CriticalSectionScoped crit_scoped(*apm_->crit());
if (likelihood != kVeryLowLikelihood &&
likelihood != kLowLikelihood &&
likelihood != kModerateLikelihood &&
likelihood != kHighLikelihood) {
if (MapSetting(likelihood) == -1) {
return apm_->kBadParameterError;
}
@ -189,37 +185,18 @@ int VoiceDetectionImpl::InitializeHandle(void* handle) const {
return WebRtcVad_Init(static_cast<Handle*>(handle));
}
/*int VoiceDetectionImpl::InitializeHandles(
const vector<void*>& handles) const {
int err = apm_->kNoError;
for (size_t i = 0; i < num_handles(); i++) {
err = WebRtcVad_Init(static_cast<Handle*>(handles[i]),
apm_->SampleRateHz());
if (err != apm_->kNoError) {
return TranslateError(err);
}
}
return apm_->kNoError;
}*/
int VoiceDetectionImpl::ConfigureHandle(void* handle) const {
return WebRtcVad_set_mode(static_cast<Handle*>(handle),
MapSetting(likelihood_));
MapSetting(likelihood_));
}
int VoiceDetectionImpl::num_handles_required() const {
return 1;
}
//int VoiceDetectionImpl::GetConfiguration() {
// // There are no configuration accessors.
// return apm_->kUnsupportedFunctionError;
//}
// TODO(ajm): implement
int VoiceDetectionImpl::TranslateError(int /*err*/) const {
return -1;
int VoiceDetectionImpl::GetHandleError(void* handle) const {
// The VAD has no get_error() function.
assert(handle != NULL);
return apm_->kUnspecifiedError;
}
} // namespace webrtc

View File

@ -46,12 +46,10 @@ class VoiceDetectionImpl : public VoiceDetection,
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
virtual int InitializeHandle(void* handle) const;
//virtual int InitializeHandles(
// const std::vector<void*>& handles) const;
virtual int ConfigureHandle(void* handle) const;
virtual int DestroyHandle(void* handle) const;
virtual int num_handles_required() const;
virtual int TranslateError(int err) const;
virtual int GetHandleError(void* handle) const;
const AudioProcessingImpl* apm_;
bool stream_has_voice_;

View File

@ -146,22 +146,22 @@ void ApmTest::TearDown() {
delete frame_;
}
frame_ = NULL;
if (reverse_frame_) {
delete reverse_frame_;
}
reverse_frame_ = NULL;
if (far_file_) {
ASSERT_EQ(0, fclose(far_file_));
}
far_file_ = NULL;
if (near_file_) {
ASSERT_EQ(0, fclose(near_file_));
}
near_file_ = NULL;
if (stat_file_) {
ASSERT_EQ(0, fclose(stat_file_));
}
@ -748,6 +748,14 @@ TEST_F(ApmTest, EchoControlMobile) {
// Turn AECM on (and AEC off)
EXPECT_EQ(apm_->kNoError, apm_->echo_control_mobile()->Enable(true));
EXPECT_TRUE(apm_->echo_control_mobile()->is_enabled());
EXPECT_EQ(apm_->kBadParameterError,
apm_->echo_control_mobile()->set_routing_mode(
static_cast<EchoControlMobile::RoutingMode>(-1)));
EXPECT_EQ(apm_->kBadParameterError,
apm_->echo_control_mobile()->set_routing_mode(
static_cast<EchoControlMobile::RoutingMode>(5)));
// Toggle routing modes
EchoControlMobile::RoutingMode mode[] = {
EchoControlMobile::kQuietEarpieceOrHeadset,