webrtc_m130/webrtc/modules/audio_processing/level_estimator_impl.cc

87 lines
2.5 KiB
C++
Raw Normal View History

/*
* 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
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_processing/level_estimator_impl.h"
#include "webrtc/modules/audio_processing/audio_buffer.h"
2014-05-05 18:22:21 +00:00
#include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/modules/audio_processing/rms_level.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
namespace webrtc {
LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm,
CriticalSectionWrapper* crit)
: ProcessingComponent(),
crit_(crit) {}
LevelEstimatorImpl::~LevelEstimatorImpl() {}
int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) {
if (!is_component_enabled()) {
2014-05-05 18:22:21 +00:00
return AudioProcessing::kNoError;
}
2014-05-05 18:22:21 +00:00
RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0));
for (int i = 0; i < audio->num_channels(); ++i) {
rms_level->Process(audio->channels_const()[i],
audio->num_frames());
}
2014-05-05 18:22:21 +00:00
return AudioProcessing::kNoError;
}
int LevelEstimatorImpl::Enable(bool enable) {
CriticalSectionScoped crit_scoped(crit_);
return EnableComponent(enable);
}
bool LevelEstimatorImpl::is_enabled() const {
return is_component_enabled();
}
int LevelEstimatorImpl::RMS() {
if (!is_component_enabled()) {
2014-05-05 18:22:21 +00:00
return AudioProcessing::kNotEnabledError;
}
2014-05-05 18:22:21 +00:00
RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0));
return rms_level->RMS();
}
2014-05-05 18:22:21 +00:00
// The ProcessingComponent implementation is pretty weird in this class since
// we have only a single instance of the trivial underlying component.
void* LevelEstimatorImpl::CreateHandle() const {
2014-05-05 18:22:21 +00:00
return new RMSLevel;
}
void LevelEstimatorImpl::DestroyHandle(void* handle) const {
2014-05-05 18:22:21 +00:00
delete static_cast<RMSLevel*>(handle);
}
int LevelEstimatorImpl::InitializeHandle(void* handle) const {
2014-05-05 18:22:21 +00:00
static_cast<RMSLevel*>(handle)->Reset();
return AudioProcessing::kNoError;
}
int LevelEstimatorImpl::ConfigureHandle(void* /*handle*/) const {
2014-05-05 18:22:21 +00:00
return AudioProcessing::kNoError;
}
int LevelEstimatorImpl::num_handles_required() const {
return 1;
}
2014-05-05 18:22:21 +00:00
int LevelEstimatorImpl::GetHandleError(void* /*handle*/) const {
return AudioProcessing::kUnspecifiedError;
}
2014-05-05 18:22:21 +00:00
} // namespace webrtc